I have to compute an HSV histogram of a colored image. Is it same as an H-S histogram?

I have found H-S histogram computation code everywhere. What is the method to change an H-S histogram to an HSV?

  • 1
    $\begingroup$ Is you end-goal a marginal histogram, that is, one histogram for each variable dimension (H, S and V respectively), or a joint histogram of all three variables at once? $\endgroup$
    – rwong
    Jul 19 '14 at 10:03

Since you want an histogram, I believe you want to plot it. In GNU Octave you may use hist3 and make three histograms (one for each pair: HxS, HxV and SxV). The code follows bellow:

pkg load statistics
I = imread ('lena.png');
sI = size (I);
Ihsv = rgb2hsv (I);
figure ("position",get(0,"screensize")./[1 1 2 3]);
subplot (1,3,1);
hist3 ( reshape (permute (Ihsv(:,:,[1,2]), [3, 1, 2]), 2, prod(sI(1:2)))' );
title ('H vs S'); xlabel ('H'); ylabel ('S');
subplot (1,3,2);
hist3 ( reshape (permute (Ihsv(:,:,[1,3]), [3, 1, 2]), 2, prod(sI(1:2)))' );
title ('H vs V'); xlabel ('H'); ylabel ('V');
subplot (1,3,3);
hist3 ( reshape (permute (Ihsv(:,:,[2,3]), [3, 1, 2]), 2, prod(sI(1:2)))' );
title ('S vs V'); xlabel ('S'); ylabel ('V');

enter image description here


They are not the same. HSV histogram would involve computing the frequencies in a 3D cube where the volume is (depending on the implementation) 360x255x255. Due to the memory requirements, this is often not preferred (~90MB) (This might seem pretty small nowadays, but traversing this histogram is very inefficient because one cannot benefit from random accesses over CPU cache. In other words, accessing elements of the histogram - even to fill the entire volume causes tons of cache misses). In brief, I don't recommend computing this at all.

On the other hand, HS histogram is a simple 2D joint histogram with only 255x255 values. It can be cached and used even in real-time applications safely.

  • $\begingroup$ Also think that the histogram will be essentially void, with less than 0.05 pixel per bin for a 1 Mpixel image. $\endgroup$
    – user7657
    Mar 16 '15 at 8:14
  • $\begingroup$ In that case you could use sparse storage, to save certain cache misses and to avoid unnecessary memory allocation. $\endgroup$ Sep 12 '15 at 7:55
  • $\begingroup$ ok for parse storage, but my point is more about the usefulness of such a histogram where most nonzero frequencies are just ones. $\endgroup$
    – user7657
    Sep 12 '15 at 8:48
  • $\begingroup$ It totally depends on your data and representation. If you have a quantized / cartoon-like image, they won't all be 1s. Nevertheless, the question is related to the implementation, not the philosophical usefulness. $\endgroup$ Sep 12 '15 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.