private static void TestConvertColors(string inputImage, string outputImage) { // Get colors of the input image var img = new Emgu.CV.Image <Bgr, byte>(inputImage); Bgr[] colors = new Bgr[img.Width * img.Height]; for (int x = 0; x < img.Width; x++) { for (int y = 0; y < img.Height; y++) { colors[y * img.Width + x] = img[y, x]; } } // Convert Lab[] newColors = ColorConversion.ConvertColors <Bgr, Lab>(colors); Bgr[] newColors2 = ColorConversion.ConvertColors <Lab, Bgr>(newColors); // Set colors of output image var img2 = new Emgu.CV.Image <Bgr, byte>(img.Width, img.Height); for (int x = 0; x < img2.Width; x++) { for (int y = 0; y < img2.Height; y++) { img2[y, x] = newColors2[y * img2.Width + x]; } } img2.Save(outputImage); }
public static Lab[] ToLabPalette <TColor>(TColor[] palette) where TColor : struct, IColor { Lab[] labPalette = null; try { // Try direct conversion CvToolbox.GetColorCvtCode(typeof(TColor), typeof(Lab)); labPalette = ColorConversion.ConvertColors <TColor, Lab>(palette); } catch { // Indirect conversion (converting first to Rgb) Rgb[] tempPalette = ColorConversion.ConvertColors <TColor, Rgb>(palette); labPalette = ColorConversion.ConvertColors <Rgb, Lab>(tempPalette); } return(labPalette); }