1. ## Hue index Histogram

Hai, I'm student in some college in indonesia

I have some problem to make hue index histogram from RGB Image .Because i'm newbie in C#.

I have problem to make code to convert from RGB to HSV color.

Anyone can help me to make hue index histogram from RGB image ???

2. I couldn't find any C# functions which convert RGB to HSV, however there are lots of javascript examples on google. Here's one which I've converted to C# for you. I've not tested much but it should work.

Code:
```using System;
using System.Collections.Generic;
using System.Text;

namespace whatever
{
class Program
{
static void Main()
{
// test it

HSVObject test = RGB2HSV(240, 123, 212);
Console.WriteLine("{0} {1} {2}", test.H, test.S, test.V);
}

static HSVObject RGB2HSV(int red, int green, int blue)
{
decimal H, S, V;

decimal r = (decimal)(red / 255.0);
decimal g = (decimal)(green / 255.0);
decimal b = (decimal)(blue / 255.0);
decimal min = Math.Min(Math.Min(r, g), b);
decimal max = Math.Max(Math.Max(r, g), b);
decimal delta = max - min;

V = max;

if (delta == 0)
{
H = 0;
S = 0;
}
else
{
S = delta / max;

decimal dR = ((((max - r) / 6) + (delta / 2)) / delta);
decimal dG = ((((max - g) / 6) + (delta / 2)) / delta);
decimal dB = ((((max - b) / 6) + (delta / 2)) / delta);

if (r == max)
H = dB - dG;
else if (g == max)
H = (1 / 3) + dR - dB;
else
H = (2 / 3) + dG - dR;

if (H < 0)
H += 1;

if (H > 1)
H -= 1;
}

return new HSVObject(H, S, V);
}
}

class HSVObject
{
public int H;
public int S;
public int V;

public HSVObject(decimal H, decimal S, decimal V)
{
this.H = (int)Math.Round(H * 360);
this.S = (int)Math.Round(S * 100);
this.V = (int)Math.Round(V * 100);
}
}
}```