在 MATLAB 上过滤 DetectSURFfeatures 并将数组转换回它自己的类型

Filtering the DetectSURFfeatures and converting the array back to its own type on MATLAB

我应该从视频帧中收集一堆 SURF 点,在过滤这些坐标点之后,我想将它转换回它自己的形式。 下面你可以看到我写的代码:

surfpoints_raw_single_column_matrix = detectSURFFeatures(img);
raw_points_double_column_matrix = SURFPoints(Location);
s=1;
for a=1:size(raw_points_double_column_matrix,1)
    i=raw_points_double_column_matrix(a,1);
    j=raw_points_double_column_matrix(a,2);
if ( (i>156-9-70 && i<156+9+70) && (j>406-9-70 && j<406+9+70) )
matrix_filtered(s,1)=i;
matrix_filtered(s,2)=j;
s=s+1; %filtered matrix index counter
end
end
???? = matrix_filtered; 
% Conversion back to the type of surfpoints_raw_single_column_matrix 

我需要的是将(例如)24x2 矩阵转换为 24x1 矩阵,该矩阵仍将选定的 x 和 y 坐标保持为一对(24 次 [x,y] )。 提前致谢...

该方法的问题在于您会丢失每个点的 SURF 描述符附带的所有信息。您会丢失比例、每个点的拉普拉斯符号、方向等信息。您只查看空间位置。

相反,使用 logical 索引并删除 SURFPoints 结构数组中不需要的任何点。您也没有正确获取原始坐标。请记住,SURFPoints 在名为 Location 的字段中包含检测到的要素的空间位置,这是您在第二行代码中尝试执行的操作,但并不完全正确。

因此,您需要做的是:

% Your code
surfpoints_raw_single_column_matrix = detectSURFFeatures(img);

% Corrected
raw_points_double_column_matrix = surfpoints_raw_single_column_matrix.Location;

% New - Get X and Y coordinates
X = raw_points_double_column_matrix(:,1);
Y = raw_points_double_column_matrix(:,2);

% New - Determine a mask to grab the points we want
ind = (X>156-9-70 & X<156+9+70) & (Y>406-9-70 & Y<406+9+70);

% New - Create new SURFPoints structure that contains all information
% from the points we need
matrix_filtered = surfpoints_raw_single_column_matrix(ind);