calculate Euclidean distance of two image in hsv color space in matlab -


i use code below calculate euclidean distance 2 rgb images:

im1 = imread(filename1); im1 = rgb2gray(im1); hn1 = imhist(im1)./numel(im1); im2 = imread(filename2); im2 = rgb2gray(im2); hn2 = imhist(im2)./numel(im2);  f = norm(hn1-hn2); 

and gives me correct answer
want use code 2 images in hsv color mode wont work on it
cause of above code in 2d space while hsv 1d
there specific code calculating euclidean distance of 2 image in hsv color space? images format jpeg

you need create histogram each channel seperatetly

function hst = im2hsvhist( img ) %  % computes 3 channels histogram in hsv color space % n = 256; % number of bins per hist (per channel) hsvimg = rgb2hsv( img ); hst = zeros(n,3); ci = 1:3      hst(:,ci) = imhist( hsvimg(:,:,ci ) , n ); end hst = hst(:) ./ n; % 3*n vector, normalize n , not 3n 

using function can compute image image distance in hsv space

im1 = imread(filename1); hst1 = im2hsvhist(im1); im2 = imread(filename2); hst2 = im2hsvdist(im2); f = norm( hst1 - hst2 ); 

sneak peek vectorized version of im2hsvhist:

n = 256;
hsvimg = rgb2hsv( img );
hst = hist( reshape(hsvimg, [], 3), 255 ); % instead of loop!
hst = hst(:) / n;


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -