Beispiel #1
0
        public static void RGBtoAnothercolorSpacetoFile(Bitmap img, RGBtoAnotherColorSpace colorSpace)
        {
            string imgName = GetImageInfo.Imginfo(Imageinfo.FileName);
            List <ArraysListInt> ColorList = Helpers.GetPixels(img);

            RGBtoAnothercolorSpacetoFile(ColorList, colorSpace, imgName);
        }
Beispiel #2
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");
        }