Borrar filtros
Borrar filtros

How to count number of hues in an image?

2 visualizaciones (últimos 30 días)
Matija
Matija el 15 de Mzo. de 2013
Hello all,
I would like to do a hue count in an image; what I want to do is to differentiate between images with a large number of hues and images with just a few hues.
Do you have any advice on that?
I did this (M is mask, I dont want to include pixels with low/high hue values and low saturation):
M = Ihsv(:,:,2)>0.2 .* (Ihsv(:,:,3)>0.15 .* Ihsv(:,:,3)<0.95);
Tmasktrue = I(find(M));
Tmasktrue=double(Tmasktrue);
[nr,xout] = hist(Tmasktrue, 20);
hue_count= std2(nr);
If in histogram with 20 bins I have all bins equally filed with pixels, std2 will be 0; if I have all pixels in only one bin, I will have std2 very large.
Please check and comment my code, regards, M.

Respuestas (2)

Walter Roberson
Walter Roberson el 15 de Mzo. de 2013
To count the number of hues, you should use
hue_count = length(unique(I(M)));
  1 comentario
Matija
Matija el 15 de Mzo. de 2013
OK, I didnt make correct formulation of my question...
"when taking a shoot, It is a good idea to limit the number of hues to just a few or at least work them into a grouping of related colors."
How to find out if hues in my image are grouped or not? I.e. that your avatar has three distinct group of hues...
I guess my code will give me a clue about it...bigger the number of pixels in one (and only one) bin, std dev gets bigger.
hue_count = length(unique(I(M))) will return exact number of hues...
Your help is appreciated.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 15 de Mzo. de 2013
The total number of hues is as Walter said. If you want to take a histogram into a different number of hues, and get the count for each range, you can do that
[hueCount, hueValues] = hist(M(:), numberOfBins);
  2 comentarios
Matija
Matija el 15 de Mzo. de 2013
OK, I did this:
[nr,xout] = hist(Tmasktrue, 20);
If I want to sort images based on number of bins, is std2 a good measure?
hue_count= std2(nr);
If pixels are equally spread over all of the bins: std2=0;
if they are spread over only 3 bins: std2 is much higher.
Image Analyst
Image Analyst el 15 de Mzo. de 2013
You could do that, if you want to identify images that span the gamut fairly evenly. Of course you could also do that directly on the Tmasktrue image directly and not bother with a histogram, you'd just look for high std dev instead of low std dev.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by