Search code examples
imagematlabimage-processingmatlab-cvstsurf

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


I'm supposed to gather a bunch of SURF points from a video frame and after filtering these coordinate points bunch I'd like to convert it back to it's own form. Below you can see the code I wrote:

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 

What I need is to convert (for example) 24x2 matrix into a 24x1 matrix which still keeps the selected x and y coordinates as a pair ( 24 times [x,y] ). Thanks in advance...


Solution

  • The trouble with that approach is that you would be losing all of the information that accompanied the SURF descriptor per point. You would lose information such as the scale, the sign of the Laplacian at each point, the orientation, etc. You are only looking at the spatial locations.

    Instead, use logical indexing and remove out any of the points in the SURFPoints structure array you don't want. You are also not getting the raw coordinates properly. Remember that SURFPoints contains the spatial locations of your detected features in a field called Location which is what you tried to do in your second line of code but it isn't quite correct.

    Therefore, what you need to do is the following:

    % 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);