public ImageMatHSV ToImageHSV() { var hsvs = new PixelHSV[data.Length]; for (int i = 0; i < data.Length; i++) { data[i].ToPixelHSV(out hsvs[i]); } ImageMatHSV result = new ImageMatHSV(hsvs, Width, Height, false); return(result); }
public void ToPixelHSV(out PixelHSV result) { int H, V; double S; var max = Math.Max(Math.Max(R, G), B); var min = Math.Min(Math.Min(R, G), B); H = 0; if (max == min) { H = 0; } else if (max == R && G > B) { H = 60 * (G - B) / (max - min) + 0; } else if (max == R && G < B) { H = 60 * (G - B) / (max - min) + 360; } else if (max == G) { H = H = 60 * (B - R) / (max - min) + 120; } else if (max == B) { H = H = 60 * (R - G) / (max - min) + 240; } // S if (max == 0) { S = 0; } else { S = (max - min) * 1.0f / max; } // V V = max; result.H = H; result.S = S; result.V = (byte)V; }