how to find euclidean distance for an image?

S
Savannah · Nov 3, 2020 · 1.9K views
Question
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,
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 10, 2026

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));
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!