How can i average Hue value in image?
9 ビュー (過去 30 日間)
古いコメントを表示
hello,I'm beginner and I try to do this.
First i separate HSV in image and try to find V value having almost the same.
Second average Hue value in that area.
Can you please tell let me know the code to display the Hue.
thanks a lot.
0 件のコメント
回答 (2 件)
Richard Hartley
2016 年 12 月 4 日
編集済み: Image Analyst
2016 年 12 月 4 日
I cannot give Matlab code (someone else may), and I am not sure that I quite understand you pictures. However, for sure, one cannot average Hue just by adding up the numbers and averaging, because the hue represents an angle.
To do it properly, you have to do this (non-Matlab code)
sumsin = 0.0
sumcos = 0.0
for (i=1:n)
sumsin = sumsin + Sin[Hue[i]];
sumcos = sumcos + Cos[Hue[i]];
endfor
averageH = Atan2[sumsin, sumcos];
This is assuming that Hue is given in radians. If it is in degrees (as I believe in MSDN) then you have to make the appropriate corrections.
2 件のコメント
Image Analyst
2016 年 12 月 4 日
Good point Richard. When the hues do not cross the 0/360 red/purple axis, the straight mean and your trig method are the same.
However when the hues cross the axis, your result is still accurate while the straight mean is not.
The magenta * is the straight mean, and the red circle is your method.
By the way, the MATLAB code for your code is this:
sumsin = sum(sind(hue(:))) % Use (:) if you want to be able to handle 2-D hue images.
sumcos = sum(cosd(hue(:)))
averageH = atan2d(sumsin, sumcos) % Compute mean hue angle
Attached below is the m-file I used to create the demo images, in case anyone is interested.
Richard Hartley
2016 年 12 月 5 日
Well, if the hue values do not cross the axis, the result of my method and straight averaging may be close, but they will not be identical. Thanks for providing Matlab code.
Image Analyst
2014 年 1 月 4 日
Create a binary image of the v part, then call mean:
hsv=rgb2hsv(rgbImage);
h = hsv(:,:,1);
s = hsv(:,:,2);
v = hsv(:,:,3);
binaryImage = v > 0.82 & v < 0.90;
meanHue = mean(h(binaryImage));
4 件のコメント
Image Analyst
2014 年 1 月 5 日
You can either try to detect the uniform central region automatically based on it's variation, or you can use a circle of known, fixed coordinates. Or you can have the user draw an ellipse using imellipse (like in the attached example). Or you can plot profiles to let the user inspect the values (like you already did) and ask the user for the values via inputdlg(). Which way do you want to do it?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!