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 concern
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.
I think the method proposed by user85109 is a good way to compute the mean, but not the standard deviation: imagine to have three angles: 180, 180, 181
the mean would be correctly computed, as a number aproximately equal to 180
but from [180,180,-179] you would compute a high variance when in fact it is near zero
At first glance, I would compute separately the means and variances for the half positive angles , [0 to 180] and fot the negative ones [0,-180] and later I would compute the combined variance https://www.emathzone.com/tutorials/basic-statistics/combined-variance.html
taking into account that the global mean and the difference between it and the local means has to be computed in both directions: clockwise and counterclockwise, and the the correct one has to be chosen.