to show 5 images having smallest eucledian distance with respect to query image.

Suppose i have one query image and a database in matlab having 10 images..i have read out and showed one image which has smallest eucledian distance with respect to query image.but now i want to read and to show atleast 5 images from that database which has nearest eucledian distance with respect to query image,that means i want to read and show 5 images in 5 different windows all together.
my program for reading and showing one image with respect to query image which has smallest eucledian distance is as follows:
G=imread('spine.tif');
H = adapthisteq(G,'clipLimit',0.01,'Distribution','rayleigh');
[rows cols]=size(H);
[c1,s1]=wavedec2(H,1,'db1');
X=c1;
figure,imshow(G);
figure,imshow(H);
fileFolder=fullfile(matlabroot,'toolbox','images','imdata');
dirOutput=dir(fullfile(fileFolder,'*.tif'));
fileNames={dirOutput.name}
n=numel(fileNames)
g=zeros(1,n)
for k = 1 : n
fileNames1=strcat('fullfile(fileFolder)',fileNames(k))
I = imread(fileNames{k});
J = adapthisteq(I,'clipLimit',0.01,'Distribution','rayleigh');
J = imresize(J, [rows cols]);
[c2,s2]=wavedec2(J,1,'db1');
Y=c2;
E_distance = sqrt(sum((X-Y).^2));
g(1,k)=E_distance;
if g(1,k)==0
w=k;
end
end
disp(g);
II=imread(fileNames{w});
figure, imshow(II);
How will i read and show atleast 5 images from that database which has nearest eucledian distance with respect to query image,that means i want to read and show 5 images in 5 different windows all together.

3 Comments

i want to compute euclidean distance of a given image with the every 5 images one by one i want to see which image out of 5 which has the least euclidean distance and to show them one by one...please help me..thank you
Editing away your question is very very much despised and will lead to people not answering your questions in the future.
I have restored the original text of this question.
diva dave anthony: this question has a clear subject and an accepted answer, so it may be valuable to someone else in the future. If you have a good reason why it should be removed from MATLAB Answers, please flag the question, explain why it should be deleted, and an administrator or high-reputation contributor will consider deleting the question. Please do not simply edit your question away.

Sign in to comment.

 Accepted Answer

Run your above code, except removing the disp(g) on downward, and adding in the missing "end" for the "for n" loop.
Afterwards, find the 5 smallest values in g. The indices of those 5 values tell you which fileNames(k) to read and display.

7 Comments

SORRY I AM NOT GETTING YOU..PLEASE WRITE THE CODE FOR ME.THANKS
G=imread('spine.tif');
H = adapthisteq(G,'clipLimit',0.01,'Distribution','rayleigh');
[rows cols]=size(H);
[c1,s1]=wavedec2(H,1,'db1');
X=c1;
figure,imshow(G);
figure,imshow(H);
fileFolder=fullfile(matlabroot,'toolbox','images','imdata');
dirOutput=dir(fullfile(fileFolder,'*.tif'));
fileNames={dirOutput.name}
n=numel(fileNames)
g=zeros(1,n)
for k = 1 : n
fileNames1=strcat('fullfile(fileFolder)',fileNames(k))
I = imread(fileNames{k});
J = adapthisteq(I,'clipLimit',0.01,'Distribution','rayleigh');
J = imresize(J, [rows cols]);
[c2,s2]=wavedec2(J,1,'db1');
Y=c2;
E_distance = sqrt(sum((X-Y).^2));
g(1,k)=E_distance;
if g(1,k)==0
w=k;
end
end
Then, find the 5 smallest values in g. If the indices of those 5 smallest values in g are k1, k2, k3, k3, k5, then
for k = [k1 k2 k3 k4 k5]
figure;
imshow( imread(fileNames{k}) );
title( sprintf('distance %g to file %s', g(k), fileNames{k}) );
end
ki k2 k3 k4 k5-error coming,it tells indefinite variable.if i give for k =1:5 will it be wrong?
I wrote " If the indices of those 5 smallest values in g are k1, k2, k3, k3, k5,". So when you find the 5 smallest values in g, assign the indices to k1, k2, k3, k4, k5 and proceed.
Using k = 1:5 will not be right: that would just take the first 5 images, not the 5 that are the best match.
Undefined function or variable "k1".
Error in ==> MONA at 26
for k =[k1,k2,k3,k4,k5]
this is the error coming..
Assign the index of the smallest value in "g" to k1. Assign the index of the next smallest value in "g" to k2. Assign the index of the third smallest value in "g" to k3. Assign the index of the fourth smallest value in "g" to k4. Assign the index of the fifth smallest value in "g" to k5. Then proceed with the code I showed.

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!