Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

2D cross correlation unable to match

1 Ansicht (letzte 30 Tage)
Eliza Tham
Eliza Tham am 29 Mär. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
HI,
i am trying to compare 2 images using corr2 . When i compare with the first image in the folder, an error message is prompt which is what i wanted. But when the 2nd image in the folder is used to compare, it states that there is no match. I am not sure where went wrong, the 2nd image is already in the folder and its exactly the same but there is no match.
% --- Executes on button press in btnSelectFolder.
function btnSelectFolder_Callback(hObject, eventdata, handles)
% hObject handle to btnSelectFolder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.png;', 'All Image Files (*.png)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick an image file');
if filename ~= 0
FileName = fullfile(pathname,filename);
end
if pathname==0,
return;
end
axes (handles.axes1);
queryFace= imread (FileName);
queryFaceresize=imresize(queryFace,[240,240]);
imshow(queryFaceresize, 'Parent', handles.axes1);
faceDetector=vision.CascadeObjectDetector('FrontalFaceCART');
bbox = step(faceDetector,queryFace);
axes (handles.axes1);
if size(bbox,1) == 0
errordlg('No face detected.Please upload another one.');
return;
elseif size(bbox,1)>1
errordlg('Too many face detected. Please upload another one')
return;
else
path='C:\Users\ET\Desktop\matlab\project\Database\';
list=dir([path, '*.png']);
img=imread(FileName);
newimg=imresize(img,[240 240]);
X1=rgb2ind(newimg,16);
for x=1:length(list)
images{x}=imread([path, list(x).name]);
X2=rgb2ind(images{x},16);
newX2=imresize(X2,size(X1));
c=corr2(X1,newX2);
if c==1
errordlg('Image Error. Please upload another one');
return;
else
msgbox('Please click the save button to save your image into our system.');
set(handles.saveImage,'Visible','on');
return;
end
end
end
please help!
thank you!
  1 Kommentar
Geoff Hayes
Geoff Hayes am 29 Mär. 2015
Eliza - put a breakpoint at the line
for x=1:length(list)
and then run your code. When the debugger pauses at this line, start stepping through the code and look at each variable to ensure that it makes sense. What are X1 and newX2? Display each image using imshow to see each one. After the correlation, what is c?

Antworten (1)

Image Analyst
Image Analyst am 29 Mär. 2015
Perhaps you really meant to use normxcorr2(). See attached demo.

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by