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

余生颓废 提交于 2019-12-04 13:46:55

You need to create a histogram for each channel seperatetly

function hst = im2hsvHist( img )
% 
% computes three channels histogram in HSV color space
%
n = 256; % number of bins per hist (per channel)
hsvImg = rgb2hsv( img );
hst = zeros(n,3);
for ci = 1:3 
    hst(:,ci) = imhist( hsvImg(:,:,ci ) , n );
end
hst = hst(:) ./ n; % to 3*n vector, normalize by n and not 3n

Using this function you can compute the image to image distance in hsv space

Im1 = imread(filename1);
hst1 = im2hsvHist(Im1);
Im2 = imread(filename2);
hst2 = im2hsvDist(Im2);
f = norm( hst1 - hst2 );

Sneak a peek for a vectorized version of im2hsvHist:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!