hello i have problem displaying the lowest value from comparation process.
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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
Accepted Answer
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
thank you so much sir, it works!! by the way can we also displaying the value of the lowest hamming distance in a textfield and also display the filename of the choosen template(in axes2)in other textfield too? its just for additional information or as the comparation result details. sorry for my terrible english. thanks again sir, your help means alot to me! really. God bless you!
Sure: (almost) nothing to it! :)
fmt='Min Hamming distance file: %s: %.1f';
text(handles.axes2,xpos,ypos, ...
sprintf(fmt,templatefiles(idx).name,minhammingdist));
You'll have to experiment to find where is a good position for them, this writes text to the axes.
If you have other text boxes, use their handles and just set the 'String' property to the desired field, either value or filename.
Glenn
on 18 Jun 2017
ah my bad. :D not in axes sir, i mean i want to display them in text boxes. thank you sir. :D
dpb
on 18 Jun 2017
Then, just use the sprintf command to build the text you wish to write following the above as a template to modify (and "doc fprintf" as the bible ;) ) and set the target controls' handles' 'String' property--at least I think that's the property name isn't it; "I don't do windows!" so I really don't know much at all about the controls property names and you can look them up as easy as I! VBG
Glenn
on 18 Jun 2017
hahahah yes, i did it sir. thank you again. :))
dpb
on 18 Jun 2017
No problem, glad to help (up to a point; I figure everybody's got to learn at some point! :) ). I do try to put tutorial stuff in; I've been told I'm "preachy"...I tend to take it as a compliment. :)
Glenn
on 18 Jun 2017
hahahah, i and maybe also other beginners need the preachy stuff more. so its not bad at all. well im bad at making compliment. but im so grateful that u answered my question. whatever, you are my hero. have a nice day, sir! :D
Stella Gareth
on 20 Oct 2017
Hi, how to display the 10 lowest values of it?
dpb
on 20 Oct 2017
Hint:
doc sort % as first step...
Stella Gareth
on 20 Oct 2017
Edited: Stella Gareth
on 20 Oct 2017
ok=sort(hammingdistances)? how to make it just lowest 10? ok=sort(hammingdistances(:10))?
Stella Gareth
on 20 Oct 2017
Edited: Stella Gareth
on 20 Oct 2017
how about the filename? how to get it along with the sorted value?
Stella Gareth
on 21 Oct 2017
ok my sorting code doesn't work. lol any other hint?
dpb
on 21 Oct 2017
Think!!! :)
Where are the lowest N values in the result of the sort????
For the other question, look at alternate return from sort -- what could you do if you knew which of the original locations was which in the smallest N?
Read
doc sort % for details of inputs/return values
Stella Gareth
on 21 Oct 2017
ah man, idk. :)
dpb
on 21 Oct 2017
Try
>> x=randperm(10) % some random data
x =
6 3 7 8 5 1 2 4 9 10
>> [xs,idx]=sort(x); % sort, keep indexing vector
>> N=3; % set some magic N
>> [xs(1:N);idx(1:N)].' % what do we have???
ans =
1 6
2 7
3 2
>> str=['a':'z'].'; % also have some other data (a str arrray)
What if use idx with it, mayhaps????
Glenn
on 21 Oct 2017
[minhammingdistances,idx]=sort(hammingdistances);
N=10;
[hamingdistances(1:N); idx(1:N)]
Like that then?
Did you try??? Do you not see what that is doing from the previous example???
Glenn
on 21 Oct 2017
lol, sorry i will try it first.
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)