Matrix Dimension does not agree when using ==

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)

 採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 12 月 5 日
編集済み: KALYAN ACHARJYA 2019 年 12 月 5 日

1 投票

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 件のコメント

coolcoolcoolcoolcool
coolcoolcoolcoolcool 2019 年 12 月 5 日
Thank you so much Sir ! It works :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeComputer Vision Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by