MATLAB: How to find euclidean distance for an image

image processingImage Processing Toolbox

I have 100 images and i have to find the euclidean distance for it,and i have to take a query image and find the euclidean distance and retrieve the image ,i have extracted an feature of an image and have stored it in .mat file,please help

Best Answer

Dear FIR, Sorry FIR I can't overview your code you sent to me. To compute the Euclidean distance between images or image features, your vector length or matrix should have same dimensions. Let say your first image has 1 x 460 vector then your query should be of same length. If that is the case then you can easily find Euclidean distance by the code I have written below. You just have to ensure that the dimensions are the same. I give you example of Histogram feature of two images.
I = imread('myimage.jpg');
I = rgb2gray(I);
h = imhist(I); % this will have default bins 256
% now second image
J = imread('myimage1.jpg');
J = rgb2gray(J);
h1 = imhist(J); % this will have default bins 256
E_distance = sqrt(sum((h-h1).^2));
You can do it for 1000 images as well. Let say now your 1000 images histogram are concatenated into h1. where each column is one histogram. Then your query image histogram is h. Then distance can be computed as follow.
h_new = repmat(h,1,size(h1,2));
E_distance = sqrt(sum((h_new-h1).^2));
Related Question