15,741,818 members
4.00/5 (1 vote)
See more: , +
Hello
I need a filter or a method in Aforge.Net to convert from RGB system to HSV, I made a search but found nothing useful
If there isn't I need the equation to make conversion
any help will be appreciated
Thanks
Posted

## Solution 1

To store the values you can use a struct like this:
C#
public struct HSVColor
{
public double Hue;
public double Saturation;
public double Value;
}

Then this method will populate and return one of these objects with the correct values.
C#
public static HSVColor GetHSV (Color color)
{
HSVColor toReturn = new HSVColor();

int max = Math.Max(color.R, Math.Max(color.G, color.B));
int min = Math.Min(color.R, Math.Min(color.G, color.B));

toReturn.Hue = Math.Round(color.GetHue(), 2);
toReturn.Saturation = ( ( max == 0 ) ? 0 : 1d - ( 1d * min / max ) ) * 100;
toReturn.Saturation = Math.Round(toReturn.Saturation, 2);
toReturn.Value = Math.Round(( ( max / 255d ) * 100 ), 2);

}

If you need all decimal places just remove the Math.Round method call.