Skip to content

Instantly share code, notes, and snippets.

@maheshmc2
Created February 20, 2011 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshmc2/835910 to your computer and use it in GitHub Desktop.
Save maheshmc2/835910 to your computer and use it in GitHub Desktop.
function [Hist] = getHSVHistogram(imageName)
% read RGB data:
RGB = imread(imageName);
RGB = rgb2hsv(RGB);
% get image size:
[M,N,~] = size(RGB);
range = 0.0:0.1:1.0;
Hist = zeros(length(range),length(range),length(range));
for i=1:M
for j=1:N
nn1 = round(RGB(i,j,1) * 10)+1;
nn2 = round(RGB(i,j,2) * 10)+1;
nn3 = round(RGB(i,j,3) * 10)+1;
Hist(nn1, nn2, nn3) = Hist(nn1, nn2, nn3) + 1;
end
end
Hist = Hist / (M*N);
function [Similarity] = HSVcomp(Hist1, Hist2)
range = 0.0:0.1:1.0;
rangeNew = 0.0:0.05:1.0;
[x,y,z] = meshgrid(range);
[x2,y2,z2] = meshgrid(rangeNew);
% decision thresholds:
t = 0.010;
t2 = 0.8;
Hist1 = interp3(x,y,z,Hist1,x2,y2,z2);
Hist2 = interp3(x,y,z,Hist2,x2,y2,z2);
DIFF = abs(Hist1-Hist2) ./ Hist2;
DIFF(isnan(DIFF)) = 0;
DIFF(isinf(DIFF)) = 1;
DIFF2 = DIFF(Hist1 > t & Hist1 < t2);
% keep distance values for which the corresponding query image's values
% are larger than the predefined threshold:
DIFF = DIFF(Hist1>t);
% keep error values which are smaller than 1:
%DIFF2 = DIFF(DIFF<t2);
L2 = length(DIFF2);
Similarity = length(DIFF) * mean(DIFF2)/ (L2^2);
@sathysumathi
Copy link

why they have multiply by 10 and add by 1 in round off function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment