Example #1
0
        //obtain L component as CIE1976 experiment, somewhere find coefficient, but less a bit ~ 2.4 :3
        public static double[,] FakeCIE1976L(Bitmap img)
        {
            List <ArraysListDouble> lab = RGBandLab.RGB2Lab(img);

            double[,] L = lab[0].Color;
            L           = L.ArrayMultByConst(2.57);

            return(L);
        }
Example #2
0
        ////Equalize histogram for image brocess
        private static Bitmap EqualizeHelper(Bitmap img, HisteqColorSpace cSpace)
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            List <ArraysListInt> Result = new List <ArraysListInt>();
            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            if (!Checks.BinaryInput(img))
            {
                List <ArraysListInt> ColorList = Helpers.GetPixels(img);

                //obtain histogram in choosen color space
                switch (cSpace)
                {
                case HisteqColorSpace.RGB:
                    if (Depth == 8)
                    {
                        var bw = HisteqHelper(ColorList[0].Color);
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        }); Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                    }
                    else
                    {
                        Result.Add(new ArraysListInt()
                        {
                            Color = HisteqHelper(ColorList[0].Color)
                        });
                        Result.Add(new ArraysListInt()
                        {
                            Color = HisteqHelper(ColorList[1].Color)
                        });
                        Result.Add(new ArraysListInt()
                        {
                            Color = HisteqHelper(ColorList[2].Color)
                        });
                    }
                    break;

                case HisteqColorSpace.HSV:
                    var hsv      = RGBandHSV.RGB2HSV(img);
                    var hsv_temp = HisteqHelper((hsv[2].Color).ImageDoubleToUint8());

                    //Filter by V - Value (Brightness/яркость)
                    //artificially if V > 1; make him 1
                    Result = RGBandHSV.HSV2RGB(hsv[0].Color, hsv[1].Color, hsv_temp.ImageUint8ToDouble().ToBorderGreaterZero(1));
                    break;

                case HisteqColorSpace.Lab:
                    var lab      = RGBandLab.RGB2Lab(img);
                    var lab_temp = HisteqHelper((lab[0].Color).ArrayToUint8());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab2RGB(lab_temp.ArrayToDouble().ToBorderGreaterZero(255), lab[1].Color, lab[2].Color);
                    break;

                case HisteqColorSpace.fakeCIE1976L:
                    var fakeCIE1976L      = RGBandLab.RGB2Lab1976(img);
                    var fakeCIE1976L_temp = HisteqHelper(fakeCIE1976L[0].Color.ArrayToUint8());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab1976toRGB(fakeCIE1976L_temp.ArrayToDouble(), fakeCIE1976L[1].Color, fakeCIE1976L[2].Color);
                    break;
                }

                image = Helpers.SetPixels(image, Result[0].Color, Result[1].Color, Result[2].Color);

                if (Depth == 8)
                {
                    image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
                }
            }
            else
            {
                Console.WriteLine("What did you expected to HistogramEqualization binaty image? Return black square.");
            }

            return(image);
        }
Example #3
0
        //
        private static Bitmap FSpecialHelper(Bitmap img, double[,] filter, FSpecialColorSpace cSpace, FSpecialFilterType filterType)
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            List <ArraysListInt> Result = new List <ArraysListInt>();
            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            double[,] Resultemp;

            if (!Checks.BinaryInput(img))
            {
                List <ArraysListInt> ColorList = Helpers.GetPixels(img);

                //sharp in choosen color space
                switch (cSpace)
                {
                case FSpecialColorSpace.RGB:
                    if (Depth == 8)
                    {
                        var bw = FSpecialFilterHelper(ColorList[0].Color.ArrayToDouble(), filter, filterType).ArrayToUint8();
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        }); Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                    }
                    else
                    {
                        Result.Add(new ArraysListInt()
                        {
                            Color = FSpecialFilterHelper(ColorList[0].Color.ArrayToDouble(), filter, filterType).ArrayToUint8()
                        });                                                                                                           //R
                        Result.Add(new ArraysListInt()
                        {
                            Color = FSpecialFilterHelper(ColorList[1].Color.ArrayToDouble(), filter, filterType).ArrayToUint8()
                        });                                                                                                           //G
                        Result.Add(new ArraysListInt()
                        {
                            Color = FSpecialFilterHelper(ColorList[2].Color.ArrayToDouble(), filter, filterType).ArrayToUint8()
                        });                                                                                                           //B
                    }
                    break;

                case FSpecialColorSpace.HSV:
                    var hsvd      = RGBandHSV.RGB2HSV(img);
                    var hsvd_temp = FSpecialFilterHelper((hsvd[2].Color).ArrayMultByConst(100), filter, filterType);

                    //Filter by V - Value (Brightness/яркость)
                    //artificially if V > 1, make him 1
                    Resultemp = hsvd_temp.ArrayDivByConst(100).ToBorderGreaterZero(1);
                    Result    = RGBandHSV.HSV2RGB(hsvd[0].Color, hsvd[1].Color, Resultemp);
                    break;

                case FSpecialColorSpace.Lab:
                    var labd      = RGBandLab.RGB2Lab(img);
                    var labd_temp = FSpecialFilterHelper(labd[0].Color, filter, filterType);

                    //Filter by L - lightness
                    Result = RGBandLab.Lab2RGB(labd_temp.ToBorderGreaterZero(255), labd[1].Color, labd[2].Color);
                    break;
                }

                image = Helpers.SetPixels(image, Result[0].Color, Result[1].Color, Result[2].Color);

                if (Depth == 8)
                {
                    image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
                }
            }
            else
            {
                Console.WriteLine("I don`t wont process binary image. Return black rectangle.");
            }

            return(image);
        }
Example #4
0
        //image smoothing by entered size for average filter process
        private static Bitmap SmoothHelper(Bitmap img, int m, int n, SmoothInColorSpace cSpace)
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);
            List <ArraysListInt> Result = new List <ArraysListInt>();

            double[,] filter;

            if (!Checks.BinaryInput(img))
            {
                List <ArraysListInt> ColorList = Helpers.GetPixels(img);

                if (m >= 1 && n >= 1)
                {
                    //create average filter by entered size
                    filter = ImageFilter.FspecialSize(m, n, "average");

                    //smooth in choosen color space
                    switch (cSpace)
                    {
                    case SmoothInColorSpace.RGB:
                        if (Depth == 8)
                        {
                            var bw = ImageFilter.Filter_double(ColorList[0].Color, filter).ArrayToUint8();
                            Result.Add(new ArraysListInt()
                            {
                                Color = bw
                            }); Result.Add(new ArraysListInt()
                            {
                                Color = bw
                            });
                            Result.Add(new ArraysListInt()
                            {
                                Color = bw
                            });
                        }
                        else
                        {
                            Result.Add(new ArraysListInt()
                            {
                                Color = ImageFilter.Filter_double(ColorList[0].Color, filter).ArrayToUint8()
                            });
                            Result.Add(new ArraysListInt()
                            {
                                Color = ImageFilter.Filter_double(ColorList[1].Color, filter).ArrayToUint8()
                            });
                            Result.Add(new ArraysListInt()
                            {
                                Color = ImageFilter.Filter_double(ColorList[2].Color, filter).ArrayToUint8()
                            });
                        }
                        break;

                    case SmoothInColorSpace.HSV:
                        var hsv      = RGBandHSV.RGB2HSV(img);
                        var hsv_temp = ImageFilter.Filter_double(hsv[2].Color, filter, PadType.replicate);

                        //Filter by V - Value (Brightness/яркость)
                        //artificially if V > 1; make him 1
                        Result = RGBandHSV.HSV2RGB(hsv[0].Color, hsv[1].Color, hsv_temp.ToBorderGreaterZero(1));
                        break;

                    case SmoothInColorSpace.Lab:
                        var lab      = RGBandLab.RGB2Lab(img);
                        var lab_temp = ImageFilter.Filter_double(lab[0].Color, filter, PadType.replicate);

                        //Filter by L - lightness
                        Result = RGBandLab.Lab2RGB(lab_temp.ToBorderGreaterZero(255), lab[1].Color, lab[2].Color);
                        break;

                    case SmoothInColorSpace.fakeCIE1976L:
                        var fakeCIE1976L      = RGBandLab.RGB2Lab1976(img);
                        var fakeCIE1976L_temp = ImageFilter.Filter_double(fakeCIE1976L[0].Color, filter, PadType.replicate);

                        //Filter by L - lightness
                        Result = RGBandLab.Lab1976toRGB(fakeCIE1976L_temp, fakeCIE1976L[1].Color, fakeCIE1976L[2].Color);
                        break;
                    }

                    image = Helpers.SetPixels(image, Result[0].Color, Result[1].Color, Result[2].Color);

                    if (Depth == 8)
                    {
                        image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
                    }
                }
                else
                {
                    Console.WriteLine("m and n parameters must be positive and greater or equal 1. Recommended 2 & 2 and higher. Method >Smooth<. Return black square.");
                }
            }
            else
            {
                Console.WriteLine("What did you expected to smooth binaty image? Return black square.");
            }

            return(image);
        }
Example #5
0
        //Sharpen process in selected color space
        private static Bitmap SharpHelper(Bitmap img, UnSharpInColorSpace cSpace, SharpFilterType filterType)
        {
            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);
            List <ArraysListInt> Result = new List <ArraysListInt>();
            double Depth = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            double[,] Resultemp;

            if (!Checks.BinaryInput(img))
            {
                List <ArraysListInt> ColorList = Helpers.GetPixels(img);

                //sharp in choosen color space
                switch (cSpace)
                {
                case UnSharpInColorSpace.RGB:
                    if (Depth == 8)
                    {
                        var bw = UnSharpHelperInt(ColorList[0].Color, filterType.ToString());
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        }); Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                        Result.Add(new ArraysListInt()
                        {
                            Color = bw
                        });
                    }
                    else
                    {
                        Result.Add(new ArraysListInt()
                        {
                            Color = UnSharpHelperInt(ColorList[0].Color, filterType.ToString())
                        });                                                                                                          //R
                        Result.Add(new ArraysListInt()
                        {
                            Color = UnSharpHelperInt(ColorList[1].Color, filterType.ToString())
                        });                                                                                                          //G
                        Result.Add(new ArraysListInt()
                        {
                            Color = UnSharpHelperInt(ColorList[2].Color, filterType.ToString())
                        });                                                                                                          //B
                    }
                    break;

                case UnSharpInColorSpace.HSVi:
                    var hsvi      = RGBandHSV.RGB2HSV(img);
                    var hsvi_temp = UnSharpHelperInt(((hsvi[2].Color).ArrayMultByConst(100).ArrayToUint8()), filterType.ToString());

                    //Filter by V - Value (Brightness/яркость)
                    Resultemp = hsvi_temp.ArrayToDouble().ArrayDivByConst(100).ToBorderGreaterZero(1);
                    Result    = RGBandHSV.HSV2RGB(hsvi[0].Color, hsvi[1].Color, Resultemp);
                    break;

                case UnSharpInColorSpace.HSVd:
                    var hsvd      = RGBandHSV.RGB2HSV(img);
                    var hsvd_temp = UnSharpHelperDouble((hsvd[2].Color).ArrayMultByConst(100), filterType.ToString());

                    //Filter by V - Value (Brightness/яркость)
                    //artificially if V > 1, make him 1
                    Resultemp = hsvd_temp.ArrayDivByConst(100).ToBorderGreaterZero(1);
                    Result    = RGBandHSV.HSV2RGB(hsvd[0].Color, hsvd[1].Color, Resultemp);
                    break;

                case UnSharpInColorSpace.Labi:
                    var labi      = RGBandLab.RGB2Lab(img);
                    var labi_temp = UnSharpHelperInt((labi[0].Color).ArrayToUint8(), filterType.ToString());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab2RGB(labi_temp.ArrayToDouble(), labi[1].Color, labi[2].Color);
                    break;

                case UnSharpInColorSpace.Labd:
                    var labd      = RGBandLab.RGB2Lab(img);
                    var labd_temp = UnSharpHelperDouble(labd[0].Color, filterType.ToString());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab2RGB(labd_temp.ToBorderGreaterZero(255), labd[1].Color, labd[2].Color);
                    break;

                case UnSharpInColorSpace.fakeCIE1976Labi:
                    var fakeCIE1976abLi      = RGBandLab.RGB2Lab1976(img);
                    var fakeCIE1976Labi_temp = UnSharpHelperInt((fakeCIE1976abLi[0].Color).ArrayToUint8(), filterType.ToString());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab1976toRGB(fakeCIE1976Labi_temp.ArrayToDouble(), fakeCIE1976abLi[1].Color, fakeCIE1976abLi[2].Color);
                    break;

                case UnSharpInColorSpace.fakeCIE1976Labd:
                    var fakeCIE1976Labd      = RGBandLab.RGB2Lab1976(img);
                    var fakeCIE1976Labd_temp = UnSharpHelperDouble((fakeCIE1976Labd[0].Color), filterType.ToString());

                    //Filter by L - lightness
                    Result = RGBandLab.Lab1976toRGB(fakeCIE1976Labd_temp.ToBorderGreaterZero(255), fakeCIE1976Labd[1].Color, fakeCIE1976Labd[2].Color);
                    break;
                }

                image = Helpers.SetPixels(image, Result[0].Color, Result[1].Color, Result[2].Color);

                if (Depth == 8)
                {
                    image = PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
                }
            }
            else
            {
                Console.WriteLine("What did you expected to sharp binary image? Return black rectangle.");
            }

            return(image);
        }
Example #6
0
        //all 2rgb looks good, if obtained not from file, but from rgb and made some filtering or another process, and saved as rgb back
        //list at input - coz bitmap object contain uint values (byte), and we can lost some color difference in other color space represent is
        public static void AnothercolorSpacetoRGBXYZLabtoFile(List <ArraysListDouble> colorPlanes, AnotherColorSpacetoRGBaXYZLab colorSpace, string nameForImage)
        {
            string defPath = GetImageInfo.MyPath("ColorSpace") + nameForImage;

            int    width  = colorPlanes[0].Color.GetLength(1);
            int    height = colorPlanes[0].Color.GetLength(0);
            Bitmap image  = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            //back result [0 .. 255]
            int[,] colorPlaneOne   = new int[height, width];
            int[,] colorPlaneTwo   = new int[height, width];
            int[,] colorPlaneThree = new int[height, width];

            List <ArraysListInt> rgbResult = new List <ArraysListInt>();
            string outName = String.Empty;

            if (colorPlanes[0].Color.Length != colorPlanes[1].Color.Length || colorPlanes[0].Color.Length != colorPlanes[2].Color.Length)
            {
                Console.WriteLine("Image plane arrays size dismatch in operation -> " +
                                  "AnothercolorSpacetoRGBXYZLabtoFile(List<ArraysListDouble> Colors, AnotherColorSpacetoRGBaXYZLab colorSpace) <-");
            }
            else
            {
                switch (colorSpace.ToString())
                {
                case "hsv2rgb":
                    rgbResult = RGBandHSV.HSV2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + "_hsv2rgb.jpeg";
                    break;

                case "ntsc2rgb":
                    rgbResult = RGBandNTSC.NTSC2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //when ntsc2rgb from file
                    //approximate result in file, coz we lost negative values in I and Q, when saving ntsc result in file [0..255]
                    outName = defPath + "_ntsc2rgb.jpeg";
                    break;

                case "cmy2rgb":
                    rgbResult = RGBandCMY.CMY2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + "_cmy2rgb.jpeg";
                    break;

                case "YCbCr2rgb":
                    rgbResult = RGBandYCbCr.YCbCr2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + "_YCbCr2rgb.jpeg";
                    break;

                case "xyz2rgb":
                    rgbResult = RGBandXYZ.XYZ2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //bad when from file, coz using heavy rounded X Y Z values, when writing them to file
                    outName = defPath + "_xyz2rgb.jpeg";
                    break;

                case "xyz2lab":
                    var xyzlabResult = XYZandLab.XYZ2Lab(colorPlanes);

                    colorPlaneOne   = (xyzlabResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (xyzlabResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (xyzlabResult[2].Color).ArrayToUint8();

                    //bad when from file, coz xyz values rounded; and lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + "_xyz2lab.jpeg";
                    break;

                case "lab2xyz":
                    var labxyzResult = XYZandLab.Lab2XYZ(colorPlanes);

                    colorPlaneOne   = (labxyzResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (labxyzResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (labxyzResult[2].Color).ArrayToUint8();

                    //bad when from file, coz lost a and b negative value when save to file. And lost X Y Z values when round before save in [0..255] range into file
                    outName = defPath + "_lab2xyz.jpeg";
                    break;

                case "lab2rgb":
                    rgbResult = RGBandLab.Lab2RGB(colorPlanes);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //if from file
                    //very bad, coz lost a lot in converting and round everywhere...
                    outName = defPath + "_lab2rgb.jpeg";
                    break;

                default:

                    colorPlaneOne   = Helpers.RandArray(height, width, 0, 255);
                    colorPlaneTwo   = Helpers.RandArray(height, width, 0, 255);
                    colorPlaneThree = Helpers.RandArray(height, width, 0, 255);

                    outName = defPath + "_defaultNonColorSpace.jpeg";
                    break;
                }
            }

            image = Helpers.SetPixels(image, colorPlaneOne, colorPlaneTwo, colorPlaneThree);

            Helpers.SaveOptions(image, outName, ".jpeg");
        }
Example #7
0
        //if direct from file. Alert: don`t recommended to use
        public static void ColorSpaceToFileDirectFromImage(Bitmap img, ColorSpaceType colorSpace)
        {
            string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension);
            string imgName      = GetImageInfo.Imginfo(Imageinfo.FileName);
            string defPath      = GetImageInfo.MyPath("ColorSpace");

            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);

            //back result [0 .. 255]
            int[,] colorPlaneOne   = new int[img.Height, img.Width];
            int[,] colorPlaneTwo   = new int[img.Height, img.Width];
            int[,] colorPlaneThree = new int[img.Height, img.Width];

            List <ArraysListInt> rgbResult = new List <ArraysListInt>();
            string outName = String.Empty;

            if (Checks.RGBinput(img))
            {
                switch (colorSpace.ToString())
                {
                case "rgb2hsv":
                    var hsvResult = RGBandHSV.RGB2HSV(img);

                    colorPlaneOne   = (hsvResult[0].Color).ArrayDivByConst(360).ImageDoubleToUint8();
                    colorPlaneTwo   = (hsvResult[1].Color).ImageDoubleToUint8();
                    colorPlaneThree = (hsvResult[2].Color).ImageDoubleToUint8();

                    outName = defPath + imgName + "_rgb2hsv" + imgExtension;
                    break;

                case "hsv2rgb":
                    rgbResult = RGBandHSV.HSV2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + imgName + "_hsv2rgb" + imgExtension;
                    break;

                case "rgb2ntsc":
                    var ntscResult = RGBandNTSC.RGB2NTSC(img);

                    colorPlaneOne   = (ntscResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (ntscResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (ntscResult[2].Color).ArrayToUint8();

                    //if we want to save rgb2ntsc result in file
                    //approximate result in file, coz we lost negative values in I and Q
                    outName = defPath + imgName + "_rgb2ntsc" + imgExtension;
                    break;

                case "ntsc2rgb":
                    rgbResult = RGBandNTSC.NTSC2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //when ntsc2rgb from file
                    //approximate result in file, coz we lost negative values in I and Q when saving ntsc result in file [0..255]
                    outName = defPath + imgName + "_ntsc2rgb" + imgExtension;
                    break;

                case "rgb2cmy":
                    var cmyResult = RGBandCMY.RGB2CMY(img);

                    colorPlaneOne   = (cmyResult[0].Color).ImageDoubleToUint8();
                    colorPlaneTwo   = (cmyResult[1].Color).ImageDoubleToUint8();
                    colorPlaneThree = (cmyResult[2].Color).ImageDoubleToUint8();

                    outName = defPath + imgName + "_rgb2cmy" + imgExtension;
                    break;

                case "cmy2rgb":
                    rgbResult = RGBandCMY.CMY2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + imgName + "_cmy2rgb" + imgExtension;
                    break;

                case "rgb2YCbCr":
                    var YCbCrResult = RGBandYCbCr.RGB2YCbCr(img);

                    colorPlaneOne   = (YCbCrResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (YCbCrResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (YCbCrResult[2].Color).ArrayToUint8();

                    outName = defPath + imgName + "_rgb2YCbCr" + imgExtension;
                    break;

                case "YCbCr2rgb":
                    rgbResult = RGBandYCbCr.YCbCr2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    outName = defPath + imgName + "_YCbCr2rgb" + imgExtension;
                    break;

                case "rgb2xyz":
                    var xyzrgbResult = RGBandXYZ.RGB2XYZ(img);

                    colorPlaneOne   = (xyzrgbResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (xyzrgbResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (xyzrgbResult[2].Color).ArrayToUint8();

                    //approximate result in file, coz we lost values after comma in saving ntsc result in file [0..255] and heavy round them
                    outName = defPath + imgName + "_rgb2xyz" + imgExtension;
                    break;

                case "xyz2rgb":
                    rgbResult = RGBandXYZ.XYZ2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //bad when from file, coz using heavy rounded X Y Z values; when writing them to file
                    outName = defPath + imgName + "_xyz2rgb" + imgExtension;
                    break;

                case "xyz2lab":
                    var xyzlabResult = XYZandLab.XYZ2Lab(img);

                    colorPlaneOne   = (xyzlabResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (xyzlabResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (xyzlabResult[2].Color).ArrayToUint8();

                    //bad when from file, coz xyz values rounded; and lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + imgName + "_xyz2lab" + imgExtension;
                    break;

                case "lab2xyz":
                    var labxyzResult = XYZandLab.Lab2XYZ(img);

                    colorPlaneOne   = (labxyzResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (labxyzResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (labxyzResult[2].Color).ArrayToUint8();

                    //bad when from file, coz lost a and b negative value when save to file. And lost X Y Z values when round before save in [0..255] range into file
                    outName = defPath + imgName + "_lab2xyz" + imgExtension;
                    break;

                case "rgb2lab":
                    var rgblabResult = RGBandLab.RGB2Lab(img);

                    colorPlaneOne   = (rgblabResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (rgblabResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (rgblabResult[2].Color).ArrayToUint8();

                    //bad, coz lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + imgName + "_rgb2lab" + imgExtension;
                    break;

                case "rgb2lab1976":
                    var rgblab1976Result = RGBandLab.RGB2Lab1976(img);

                    colorPlaneOne   = (rgblab1976Result[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (rgblab1976Result[1].Color).ArrayToUint8();
                    colorPlaneThree = (rgblab1976Result[2].Color).ArrayToUint8();

                    //bad, coz lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + imgName + "_rgb2lab1976" + imgExtension;
                    break;

                case "lab2rgb":
                    rgbResult = RGBandLab.Lab2RGB(img);

                    colorPlaneOne   = rgbResult[0].Color;
                    colorPlaneTwo   = rgbResult[1].Color;
                    colorPlaneThree = rgbResult[2].Color;

                    //very bad, coz lost a lot in converting and round everywhere...
                    outName = defPath + imgName + "_lab2rgb" + imgExtension;
                    break;

                default:
                    colorPlaneOne   = Helpers.GetPixels(img)[0].Color;
                    colorPlaneTwo   = Helpers.GetPixels(img)[1].Color;
                    colorPlaneThree = Helpers.GetPixels(img)[2].Color;

                    outName = defPath + imgName + "_defaultNonColorSpace" + imgExtension;
                    break;
                }

                image = Helpers.SetPixels(image, colorPlaneOne, colorPlaneTwo, colorPlaneThree);

                Helpers.SaveOptions(image, outName, imgExtension);
            }
        }
Example #8
0
        //some rgb2 looks good, some lost negative values, when ranged to uint8 [0..255] for saving
        public static void RGBtoAnothercolorSpacetoFile(List <ArraysListInt> colorPlanes, RGBtoAnotherColorSpace colorSpace, string nameForImage)
        {
            string defPath = GetImageInfo.MyPath("ColorSpace") + nameForImage;

            int    width  = colorPlanes[0].Color.GetLength(1);
            int    height = colorPlanes[0].Color.GetLength(0);
            Bitmap image  = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            //back result [0 .. 255]
            int[,] colorPlaneOne   = new int[height, width];
            int[,] colorPlaneTwo   = new int[height, width];
            int[,] colorPlaneThree = new int[height, width];

            string outName = String.Empty;

            if (colorPlanes[0].Color.Length != colorPlanes[1].Color.Length || colorPlanes[0].Color.Length != colorPlanes[2].Color.Length)
            {
                Console.WriteLine("Image plane arrays size dismatch in operation -> " +
                                  "RGBtoAnothercolorSpacetoFile(List<arraysListInt> colorPlanes, RGBtoAnotherColorSpace colorSpace) <-");
            }
            else
            {
                switch (colorSpace.ToString())
                {
                case "rgb2hsv":
                    var hsvResult = RGBandHSV.RGB2HSV(colorPlanes);

                    colorPlaneOne   = (hsvResult[0].Color).ArrayDivByConst(360).ImageDoubleToUint8();
                    colorPlaneTwo   = (hsvResult[1].Color).ImageDoubleToUint8();
                    colorPlaneThree = (hsvResult[2].Color).ImageDoubleToUint8();

                    outName = defPath + "_rgb2hsv.jpeg";
                    break;

                case "rgb2ntsc":
                    var ntscResult = RGBandNTSC.RGB2NTSC(colorPlanes);

                    colorPlaneOne   = (ntscResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (ntscResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (ntscResult[2].Color).ArrayToUint8();

                    //if we want to save rgb2ntsc result in file
                    //approximate result in file, coz we lost negative values in I and Q
                    outName = defPath + "_rgb2ntsc.jpeg";
                    break;

                case "rgb2cmy":
                    var cmyResult = RGBandCMY.RGB2CMY(colorPlanes);

                    colorPlaneOne   = (cmyResult[0].Color).ImageDoubleToUint8();
                    colorPlaneTwo   = (cmyResult[1].Color).ImageDoubleToUint8();
                    colorPlaneThree = (cmyResult[2].Color).ImageDoubleToUint8();

                    outName = defPath + "_rgb2cmy.jpeg";
                    break;

                case "rgb2YCbCr":
                    var YCbCrResult = RGBandYCbCr.RGB2YCbCr(colorPlanes);

                    colorPlaneOne   = (YCbCrResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (YCbCrResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (YCbCrResult[2].Color).ArrayToUint8();

                    outName = defPath + "_rgb2YCbCr.jpeg";
                    break;

                case "rgb2xyz":
                    var xyzrgbResult = RGBandXYZ.RGB2XYZ(colorPlanes);

                    colorPlaneOne   = (xyzrgbResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (xyzrgbResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (xyzrgbResult[2].Color).ArrayToUint8();

                    //approximate result in file, coz we lost values after comma in saving ntsc result in file [0..255] and heavy round them
                    outName = defPath + "_rgb2xyz.jpeg";
                    break;

                case "rgb2lab":
                    var rgblabResult = RGBandLab.RGB2Lab(colorPlanes);

                    colorPlaneOne   = (rgblabResult[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (rgblabResult[1].Color).ArrayToUint8();
                    colorPlaneThree = (rgblabResult[2].Color).ArrayToUint8();

                    //bad, coz lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + "_rgb2lab.jpeg";
                    break;

                case "rgb2lab1976":
                    var rgblab1976Result = RGBandLab.RGB2Lab1976(colorPlanes);

                    colorPlaneOne   = (rgblab1976Result[0].Color).ArrayToUint8();
                    colorPlaneTwo   = (rgblab1976Result[1].Color).ArrayToUint8();
                    colorPlaneThree = (rgblab1976Result[2].Color).ArrayToUint8();

                    //bad, coz lost negative value in a & b when saving in [0..255] range into file
                    outName = defPath + "_rgb2lab1976.jpeg";
                    break;

                default:
                    colorPlaneOne   = colorPlanes[0].Color;
                    colorPlaneTwo   = colorPlanes[1].Color;
                    colorPlaneThree = colorPlanes[2].Color;

                    outName = defPath + "_defaultNonColorSpace.jpeg";
                    break;
                }
            }

            image = Helpers.SetPixels(image, colorPlaneOne, colorPlaneTwo, colorPlaneThree);

            Helpers.SaveOptions(image, outName, ".jpeg");
        }