Exemple #1
0
        public override (Bitmap, Bitmap, Bitmap) Transform()
        {
            for (int i = 0; i < InitBitmap.Width; i++)
            {
                for (int j = 0; j < InitBitmap.Height; j++)
                {
                    Color  p = InitBitmap.GetPixel(i, j);
                    double R = ((double)p.R / 255.0);
                    double G = ((double)p.G / 255.0);
                    double B = ((double)p.B / 255.0);

                    var XYZ = RGB2XYZ(R, G, B);
                    var lab = XYZ2LAB(XYZ);
                    var L   = lab[0];
                    var a   = lab[1];
                    var b   = lab[2];

                    var r1 = a + 127;
                    var g1 = 127 - a;

                    var r2 = b + 127;
                    var b1 = 127 - b;

                    rbmap.SetPixel(i, j, Color.FromArgb(255, (int)L, (int)L, (int)L));
                    gbmap.SetPixel(i, j, Color.FromArgb(255, (int)r1, (int)g1, 127));
                    bbmap.SetPixel(i, j, Color.FromArgb(255, (int)r2, 127, (int)b1));
                }
            }


            return(rbmap.Bitmap, gbmap.Bitmap, bbmap.Bitmap);
        }
Exemple #2
0
        public override (Bitmap, Bitmap, Bitmap) Transform()
        {
            for (int i = 0; i < InitBitmap.Width; i++)
            {
                for (int j = 0; j < InitBitmap.Height; j++)
                {
                    Color  p  = InitBitmap.GetPixel(i, j);
                    double Y  = 0.299 * p.R + 0.587 * p.G + 0.114 * p.B;
                    double Cb = -0.1687 * p.R - 0.3313 * p.G + 0.5 * p.B + 128;

                    double Cr = 0.5 * p.R - 0.4187 * p.G - 0.0813 * p.B + 128;


                    rbmap.SetPixel(i, j, Color.FromArgb(255, (int)Y, (int)Y, (int)Y));

                    //Color interpolation
                    var G1 = 255 - Cb;
                    var B1 = Cb;

                    var R1 = Cr;
                    var G2 = 255 - Cr;

                    gbmap.SetPixel(i, j, Color.FromArgb(255, 127, (int)G1, (int)B1));
                    bbmap.SetPixel(i, j, Color.FromArgb(255, (int)R1, (int)G2, 127));

                    //Gray shades

                    //gbmap.SetPixel(i, j, Color.FromArgb(255, (int)Cb, (int)Cb, (int)Cb));
                    //bbmap.SetPixel(i, j, Color.FromArgb(255, (int)Cr, (int)Cr, (int)Cr));
                }
            }

            return(rbmap.Bitmap, gbmap.Bitmap, bbmap.Bitmap);
        }
Exemple #3
0
        public override (Bitmap, Bitmap, Bitmap) Transform()
        {
            for (int i = 0; i < InitBitmap.Width; i++)
            {
                for (int j = 0; j < InitBitmap.Height; j++)
                {
                    double H = 0;
                    double S = 0;
                    double V = 0;
                    Color  p = InitBitmap.GetPixel(i, j);

                    double r     = (double)p.R / 255;
                    double g     = (double)p.G / 255;
                    double b     = (double)p.B / 255;
                    double Cmax  = Math.Max(r, Math.Max(g, b));
                    double Cmin  = Math.Min(Math.Min(r, g), b);
                    double delta = Cmax - Cmin;

                    if (delta == 0)
                    {
                        H = 0;
                    }
                    else if (Cmax == r)
                    {
                        H = ((g - b) / delta % 6) * 60;
                    }
                    else if (Cmax == g)
                    {
                        H = ((b - r) / delta + 2) * 60;
                    }
                    else if (Cmax == b)
                    {
                        H = ((r - g) / delta + 4) * 60;
                    }

                    if (H < 0)
                    {
                        H += 360;
                    }


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

                    V  = Cmax;
                    S *= 100;
                    V *= 100;

                    if (H > 255)
                    {
                        H = H / 255;
                    }

                    rbmap.SetPixel(i, j, Color.FromArgb(255, (int)H, (int)H, (int)H));
                    gbmap.SetPixel(i, j, Color.FromArgb(255, (int)S, (int)S, (int)S));
                    bbmap.SetPixel(i, j, Color.FromArgb(255, (int)V, (int)V, (int)V));
                }
            }
            return(rbmap.Bitmap, gbmap.Bitmap, bbmap.Bitmap);
        }