Kal
Kal

Reputation: 73

Using SURF algorithm to match objects on MATLAB

The objective is to see if two images, which have one object captured in each image, matches.

The object or image I have stored. This will be used as a baseline:

The object/image that needs to matched with-this is stored:

My method:

  1. Covert images to gray-scale.
  2. Extract SURF interest points.
  3. Obtain features.
  4. Match features.
  5. Get 50 strongest features.
  6. Match the number of strongest features with each image.
  7. Take the ratio of- number of features matched/ number of strongest features (which is 50).

If I have two images of the same object (two images taken separately on a camera), ideally the ratio should be near 1 or near 100%. However this is not the case, the best ratio I am getting is near 0.5 or even worse, 0.3.

I am aware the SURF detectors and features can be used in neural networks, or using a statistics based approach. I believe I have approached the statistics based approach to some extent by using 50 of the strongest features.

Is there something I am missing? What do I add onto this or how do I improve it? Please provide me a point to start from.

%Clearing the workspace and all variables
clc;
clear;

%ITEM 1
item1 = imread('Loreal.jpg');%Retrieve order 1 and digitize it.
item1Grey  = rgb2gray(item1);%convert to grayscale, 2 dimensional matrix
item1KP = detectSURFFeatures(item1Grey,'MetricThreshold',600);%get SURF dectectors or interest points
strong1 = item1KP.selectStrongest(50);
[item1Features, item1Points] = extractFeatures(item1Grey, strong1,'SURFSize',128); % using SURFSize of 128

%INPUT : Aquire Image
input= imread('MakeUp1.jpg');%Retrieve input and digitize it.
inputGrey  = rgb2gray(input);%convert to grayscale, 2 dimensional matrix
inputKP = detectSURFFeatures(inputGrey,'MetricThreshold',600);%get SURF dectectors or interest
strongInput = inputKP.selectStrongest(50);
[inputFeatures, inputPoints] = extractFeatures(inputGrey, strongInput,'SURFSize',128); % using SURFSize of 128

pairs = matchFeatures(item1Features, inputFeatures, 'MaxRatio',1); %matching SURF Features
totalFeatures = length(item1Features); %baseline number of features
numPairs = length(pairs); %the number of pairs
percentage  = numPairs/50;

if percentage >= 0.49
    disp('We have this');
else
    disp('We do not have this');
    disp(percentage);
end

The baseline image

The input image

Upvotes: 1

Views: 7934

Answers (1)

Dima
Dima

Reputation: 39389

I would try not doing selectStrongest and not setting MaxRatio. Just call matchFeatures with the default options and compare the number of resulting matches.

The default behavior of matchFeatures is to use the ratio test to exclude ambiguous matches. So the number of matches it returns may be a good indicator of the presence or absence of the object in the scene.

If you want to try something more sophisticated, take a look at this example.

Upvotes: 1

Related Questions