DSPRelated.com
Forums

How to compute the HSV histograms of a color image?

Started by vash...@yahoo.com December 16, 2008
Hi all,

Can anybody tell me how to generate a HSV histogram for an image. The HUE should use 16 Levels, SATURATION and VALUE should use 4 levels each.

Therefore the number of histogram bins to be used should be 16x4x4 = 256 bins.

I know how to get the HSV histograms for the H,S and V channels separately(ie, 16+4+4 bins) though using the following code :

RGB = imread(imagename);
HSV = rgb2hsv(RGB);
H = HSV(:,:,1);
S = HSV(:,:,2);
V = HSV(:,:,3);

hHist = hist(H(:),16);
sHist = hist(S(:),4);
vHist = hist(V(:),4);

My idea is basically to get the histogram for 16x4x4 = 256 bins as follows :

HUE channel has 16 levels so that each level is assigned a code in the range 0 - 15
SATURATION channel has 4 levels so that each level is assigned a code in the range 0 - 3
VALUE channel has 4 levels so that each level is assigned a code in the range 0 - 3.

So a combination of the 3 codes for H, S and V would be regarded as a separate bin(which represents a separate color). For example :

H : 0, S : 0, V : 0 would denote one bin(one color)
H : 0, S : 0, V : 1 would denote onother bin(onother color)
H : 1, S : 0, V : 2 would denote onother bin(onother color)
H : 0, S : 0, V : 1 would denote onother bin(onother color)
H : 14, S : 3, V : 3 would denote onother bin(onother color)

Therefore considering all such combinations, there would be 16x4x4 = 256 different bins/colors. It is for these 256 bins that we should get the histogram count.

I hope the logic is right.

What I don't understand is how to first reduce each of the 3 HSV color channels to 16, 4, 4 levels respectively and then from there onwards obtain the 256 different bins/colors in the way described above.The code I prepared for getting the H,S,V channels separately is:

RGB = imread(imagename);
HSV = rgb2hsv(RGB);
H = HSV(:,:,1);
S = HSV(:,:,2);
V = HSV(:,:,3);

But how do I proceed thereafter. Please can anyone tell me of any functions or the methods I can use to achieve this as I am new to both MATLAB and image processing.

Thanks.

Regards,
Vashini