How to calculate mean and standard deviation for hue values from 0 to 360?

吃可爱长大的小学妹 提交于 2020-01-01 05:23:07

问题


Suppose 5 samples of hue are taken using a simple HSV model for color, having values 355, 5, 5, 5, 5, all a hue of red and "next" to each other as far as perception is concerned. But the simple average is 75 which is far away from 0 or 360, close to a yellow-green.

What is a better way to calculate this mean and associated std?


回答1:


The simple solution is to convert those angles to a set of vectors, from polar coordinates into cartesian coordinates.

Since you are working with colors, think of this as a conversion into the (a*,b*) plane. Then take the mean of those coordinates, and then revert back into polar form again. Done in matlab,

theta = [355,5,5,5,5];
x = cosd(theta); % cosine in terms of degrees
y = sind(theta); % sine with a degree argument

Now, take the mean of x and y, compute the angle, then convert back from radians to degrees.

meanangle = atan2(mean(y),mean(x))*180/pi
meanangle =
       3.0049

Of course, this solution is valid only for the mean angle. As you can see, it yields a consistent result with the mean of the angles directly, where I recognize that 355 degrees really wraps to -5 degrees.

mean([-5 5 5 5 5])
ans =
     3

To compute the standard deviation, it is simplest to do it as

std([-5 5 5 5 5])
ans =
       4.4721

Yes, that requires me to do the wrap explicitly.



来源:https://stackoverflow.com/questions/8169654/how-to-calculate-mean-and-standard-deviation-for-hue-values-from-0-to-360

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!