0

Suppose I have one query image, and a database in matlab that has 10 images. I can read out and show one image which has smallest Euclidean distance with respect to query image. But now, I want to read and show at least 5 images from that database, which means I want to read and show five images in five different windows.

My program for reading and showing a single image with the has smallest Euclidean 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);

My question is, how can I read and show at least five images from that database, in five different windows.

Hannele
  • 9,301
  • 6
  • 48
  • 68
ranadhir
  • 21
  • 1
  • 1
  • 6
  • 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 – ranadhir Mar 28 '13 at 15:29

1 Answers1

0

If i understand your code correctly you currently show only the image for which the distance is equal to zero (if g(1,k)==0, w=k; end), not the one with the smallest distance.

If you have the distances in g you can simply sort the array and take the first five.

[sorted,IX] = sort(g);
firstFiveIndexes = IX(1:5);

for I = 1:length(firstFiveIndexes)
  figure;imshow(imread(fileNames{firstFiveIndexes(I)}));
end

If you have many images, going through the array and maintaining the five smallest distances would be faster than sorting, but imo its not worth the trouble.

Josef Borkovec
  • 1,069
  • 8
  • 13
  • thank you but its not showing 5 images..its showing more than 5 images..how to show 5 images which has smallest eucledian distance – ranadhir Mar 28 '13 at 16:28
  • The code is working fine for me. It should show only five images. Your code shows also the query image and the image with adjusted contrast. Didn't you mean these? [Here](http://pastebin.com/iVY92789) is my exact source. I had to change the path to matlab images and exclude non-grayscale images for it to work with my matlab version. If it is still not working for you, then please give us more information on what exactly is wrong and what is the output. – Josef Borkovec Mar 28 '13 at 17:31
  • it shows altogether 18images along with the query image and image with adjust contrast – ranadhir Mar 28 '13 at 17:58
  • sorry i have done something wrong....thanx a lot..its working..thank you very much sir – ranadhir Mar 28 '13 at 18:08