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

Suppose that 5 hue samples were taken using a simple HSV model for a color having values โ€‹โ€‹of 355, 5, 5, 5, 5, all shades of red and โ€œfollowingโ€ one another in relation to perception. But the simple average is 75, which is far from 0 or 360, next to yellow-green.

What is the best way to calculate this average and the associated std?

+6
source share
1 answer

A simple solution is to convert these angles into a set of vectors, from polar coordinates to Cartesian coordinates.

Since you work with colors, think of it as converting to a plane (a *, b *). Then take the average of these coordinates, and then return to the 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 average of x and y, calculate 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 average angle. As you can see, it gives a consistent result with the average angles directly, where I understand that 355 degrees really wrap up to -5 degrees.

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

To calculate the standard deviation, the easiest way to do this is to

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

Yes, this requires me to do the transfer explicitly.

+10
source

Source: https://habr.com/ru/post/901723/


All Articles