Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top