MATLAB Answers

Matrix Dimension does not agree when using ==

2 views (last 30 days)
Hello, i tried this code I found which programmed to match two images. When I try to use two pictures that are slightly different, it become error and says 'Matrix dimension does not agree'. Do any of you know why? Thank you so much.
% --- Executes on button press in upload1.
function upload1_Callback(~, ~, handles)
%Image Upload number 1
global img1
[filename, pathname] = uigetfile('*.*','D:\Users\Pictures');
img1 = imread([pathname, filename]);
imshow(img1,'Parent',handles.axes5);
set(handles.clear, 'Enable', 'on')
set(handles.upload2, 'Enable', 'on')
% hObject handle to upload1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in upload2.
function upload2_Callback(~, ~, handles)
%Image Upload number 2
global img2
[filename, pathname] = uigetfile('*.*','D:\Users\Pictures');
img2 = imread([pathname, filename]);
imshow(img2,'Parent',handles.axes6);
set(handles.clear, 'Enable', 'on')
set(handles.matchbutton5, 'Enable', 'on')
% hObject handle to upload2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user
% --- Executes on button press in match.
function matchbutton5_Callback(~, ~, handles)
global img1;
global img2;
scale_factor = 1;
img1 = imresize(img1, scale_factor, 'bilinear');
img2 = imresize(img2, scale_factor, 'bilinear');
I = img1;
I1 = rgb2gray(I);
I2 = imresize(imrotate(I1, -20), 1.2);
points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);
[f1,vpts1] = extractFeatures(I1,points1);
[f2,vpts2] = extractFeatures(I2,points2);
indexPairs1 = matchFeatures(f1,f2);
matchedPoints1 = vpts1(indexPairs1(:,1));
matchedPoints2 = vpts2(indexPairs1(:,2));
figure; showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);
handles.axes1 = showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2);
II = img2;
I11 = rgb2gray(II);
I22 = imresize(imrotate(I11, -20), 1.2);
points11 = detectSURFFeatures(I11);
points22 = detectSURFFeatures(I22);
[f11,vpts11] = extractFeatures(I11,points11);
[f22,vpts22] = extractFeatures(I22,points22);
indexPairs = matchFeatures(f11,f22);
matchedPoints11 = vpts11(indexPairs(:,1));
matchedPoints22 = vpts22(indexPairs(:,2));
figure; showMatchedFeatures(I11, I22, matchedPoints11, matchedPoints22);
handles.axes1 = showMatchedFeatures(I11, I22, matchedPoints11, matchedPoints22);
if I1 == I11
msgbox('Images are matched!');
else
msgbox('Images are NOT matched!');
end
set(handles.upload2, 'Enable', 'off')
set(handles.upload1, 'Enable', 'off')
% hObject handle to match (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

  0 Comments

Sign in to comment.

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 5 Dec 2019
Edited: KALYAN ACHARJYA on 5 Dec 2019
May be both Image having different size. Please make them same size and type and do compare.
Use this way
isequal(I1,I11)
When you use I1 == I11,note that when you compare two image you get the logical matrices, not single logical value
see the example
>> a=magic(5);
>> b=randi(10,[5,5]);
>> a==b
ans =
5×5 logical array
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
1 0 0 0 0
0 0 0 0 0
#Here isequal
>> isequal(a,b)
ans =
logical
0
>>
Hope it helps!

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.