Comparing two binary images

62 views (last 30 days)
Elie
Elie on 5 Feb 2014
Commented: Elie on 6 Feb 2014
Hello i'm trying to build a matlab function which is capable of locating the location of an image inside another one : as in the picture
the picture to the right doesn't have the same size as that in the one to the left i tried various method like subtracting the two image , the objective of this is to extract a number which is located beside this tree for that i want to locate the treee then extract the number using ocr , im not experienced in image processing i hope you guide me to the right track. Regards

Accepted Answer

Elvin
Elvin on 5 Feb 2014
  3 Comments
Elie
Elie on 6 Feb 2014
Edited: Elie on 6 Feb 2014
I'm facing some difficulties in the code, i followed the link you supplied me with and its exactly what i want; But when i try to compile the code im getting an error at a certain part of the code. Everything goes well until the function reaches a certain point and i get this error " Error in Compare (line 46) showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints,matchedScenePoints,'montage') ; " Compare is the name of the function.
Here's the full code
if true
if true
function [ Image] = Compare( Img )
% Reading the reference Image
I= imread('C:\Users\user\Desktop\Matlab-Comparsion\tree11.jpg');
C=rgb2gray(I);
boxImage = C;
figure; imshow(boxImage);
title('Image of a Box');
%Reading the target image
II= imread('C:\Users\user\Desktop\Matlab-Comparsion\4.jpg');
CC=rgb2gray(II);
sceneImage = CC;
figure;
imshow(sceneImage);
title('Image of a Cluttered Scene');
%Detect feature images
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);
%Visualize the strongest feature points found in the reference image.
figure;
imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(boxPoints.selectStrongest(100));
%Visualize the strongest feature points found in the target image.
figure;
imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(scenePoints.selectStrongest(300));
%Extract feature descriptors at the interest points in both images.
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);
%Match the features using their descriptors.
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
%Display putatively matched features.
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
%This is line 46 of the code where the compiler is indicating the error
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints,matchedScenePoints,'montage');
title('Putatively Matched Points (Including Outliers)');
%estimateGeometricTransform calculates the transformation relating the matched points,
%while eliminating outliers. This transformation allows us to localize the object in the scene.
[tform, inlierBoxPoints, inlierScenePoints] = estimateGeometricTransform(matchedBoxPoints, ...
matchedScenePoints, 'affine');
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints,...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');
%Get the bounding polygon of the reference image.
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
% Transform the polygon into the coordinate system of the target image. The transformed polygon indicates the location of the object in the scene.
newBoxPolygon = transformPointsForward(tform, boxPolygon);
%Display the detected object.
figure();
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');
end
end
%Display the matching point pairs with the outliers removed
figure;
% code
end
Please help me , i really appreciate your help.
Elie
Elie on 6 Feb 2014
is there any possibility that this error has to do with my matlab version i have R2012A.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 6 Feb 2014
There is SIFT - Scale Invariant Feature Transform, but that's been patented so you can use an similar alternate: SURF. The authors also patented SURF or something related to it, but the good news is that it's built into the Computer Vision System Toolbox. The bad news is that it's pretty challenging to use for novices like you. Good luck.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!