im trying to compare array of images with the no of blobs in an image what is wrong this code how i can fix error " corr2>ParseInputs at 36 iptcheckinput(A, {'logical' 'numeric'}, {'real'}, mfilename, 'A', 1); Error in ==> corr2 at 22 [arr{i},b);

2 views (last 30 days)
figure(1);
I = imread('coins.png');
bw = im2bw(I, graythresh(I));
bw2 = imfill(bw,'holes');
imshow(bw2);
% figure(2);
L = bwlabel(bw2);
blobMeasurements = regionprops(L, bw2, 'all');
nofcoins= size(blobMeasurements, 1);
%figure(3);
imshow(I);
arr={'f1.png','f2.png','f3.png'};
for k= 1 : nofcoins
s = regionprops(L, 'BoundingBox');
rectangle('Position', s(k).BoundingBox);
subimage = I(round(s(k).BoundingBox(2):s(k).BoundingBox(2)+s(k).BoundingBox(4)),round(s(k).BoundingBox(1):s(k).BoundingBox(1)+s(k).BoundingBox(3)));
figure,imshow(subimage);
%%save sub images into subimages folder
% baseFileName =sprintf('Frame %4.4d.png', k);
% folder = 'C:\Users\Moniba Ghafoor\Documents\subimages';
% fullFileName = fullfile(folder, baseFileName);
% imwrite(subimage,fullFileName);
%%comparison with array
for i=1 : 3
[row col]=size(arr{i});
b=imresize(subimage,[row,col]);
c=corr2(arr{i},b);
if c==1
h=msgbox('image match with one of subimage');
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 14 Jun 2013
corr2() is checking to enforce that the first input argument is a logical array or else a numeric array. But what you are passing is arr{i} where arr is a cell array of strings, so arr{i} is a string rather than an array of data. corr2() does not support passing in the name of a file storing images whose image contents are to have correlation run on them.
  2 Comments
Image Analyst
Image Analyst on 14 Jun 2013
Try
referenceImage = imread(arr{i});
c=corr2(referenceImage, b);
Also change this:
h=msgbox('image match with one of the subimages');
to this:
uiwait(msgbox('image match with one of subimage'));
Otherwise msgbox won't wait for you to respond before it goes on ahead executing more code.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!