hello i have problem displaying the lowest value from comparation process.
1 view (last 30 days)
Show older comments
i want to do comparation one by one between an iris image template on axes1 and a folder filled with iris image templates. a hammingdist.m used to count the value. the output should be a template from the folder that has lowest value amongs other templates in that folder while compared to the template on axes1 and will be displayed on axes2. but instead of displaying the template with the lowest value, it displays the last file in the folder. how to fix it? here is the code:
function buttonpencocokan_Callback(hObject, eventdata, handles)
TestImage=getappdata(handles.axes1, 'templateVVV');
gettraining=get(handles.txtlokasilatih, 'String');
datapath = (gettraining);
templatefiles = dir(fullfile(datapath, '*.bmp'));
hammingdistances = zeros(size(templatefiles));
for fileidx = 1:numel(templatefiles)
templateimage = imread(fullfile(datapath, templatefiles(fileidx).name));
hammingdistances(fileidx) = hammingdist(TestImage, templateimage);
axes(handles.axes2);imshow(templateimage);
end
0 Comments
Accepted Answer
dpb
on 18 Jun 2017
Edited: dpb
on 18 Jun 2017
Because you never found the minimum...if you want the global minimum in the end, then
for fileidx = 1:numel(templatefiles)
templateimage = imread(fullfile(datapath, templatefiles(fileidx).name));
hammingdistances(fileidx) = hammingdist(TestImage, templateimage);
end
[minhammingdist,idx]=min(hammingdistances); % find the min, location in array
axes(handles.axes2);
imshow(imread(fullfile(datapath, templatefiles(idx).name))); % reload/display the one
If you wanted to keep a running display of which was the current closest as processed, then
templateimage = imread(fullfile(datapath, templatefiles(1).name));
minhammingdistance = hammingdist(TestImage, templateimage);
minIndex=1;
imshow(templateimage,'parent',handles.axes2);
for fileidx = 2:numel(templatefiles)
templateimage = imread(fullfile(datapath, templatefiles(fileidx).name));
hammingdistance = hammingdist(TestImage, templateimage);
if hammingdistance < minhammingdistance
minhammingdistance = minhammingdistance;
minIndex=fileidx;
imshow(templateimage,'parent',handles.axes2);
end
end
18 Comments
More Answers (0)
See Also
Categories
Find more on Annotations 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!