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
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));
Similar question was asked by one fellow. The solution you can see from following URL. I hope it might help you.
You have Query image Q, you want to compute euclidean distance of Q with all images in database. Is that you want ? If yes then Let say query Image Q is grayscale image so you can present it as feature vector
Q = Q(:); % this is one [size(Q,1) x size(Q,2) by 1]
all the images in database should have same dimensions. Let say every image and query image should have same number of pixels.
Now you load your database
D = load('Database.mat');
we assume that each column is one image and your number of columns should be size of Database. or if you want to present each row as image then simply take the transpose.
Q= repmat(Q,1,size(D,2)); E_distance = sqrt(sum((Q-D).^2));
Now E_distance have euclidean distance of Q with all images in database D.
Do let me know if It solved your problem.
Play games and win prizes!Learn more