필터 지우기
필터 지우기

How to count number of hues in an image?

조회 수: 2 (최근 30일)
Matija
Matija 2013년 3월 15일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2013년 3월 15일
To count the number of hues, you should use
hue_count = length(unique(I(M)));
  댓글 수: 1
Matija
Matija 2013년 3월 15일
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.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2013년 3월 15일
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
Matija
Matija 2013년 3월 15일
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 2013년 3월 15일
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.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by