コード例 #1
0
        public void Initialiser(OpenFileDialog openFileDialog)
        {
            HSLconvertor         = new HSLconvertor();
            this.img             = new Bitmap(openFileDialog.FileName);
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox1.Image    = img;

            this.width  = img.Width;
            this.height = img.Height;

            RGBcolor   = new RGBcolor();
            RGBcolor.A = new int[width, height];
            RGBcolor.R = new int[width, height];
            RGBcolor.G = new int[width, height];
            RGBcolor.B = new int[width, height];
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e) // соляризація
        {
            imgSolar = new Bitmap(img);
            HSLconvertor.toHSL(RGBcolor, height, width);
            RGBcolor rgbNew = new RGBcolor();

            rgbNew = HSLconvertor.toRGB_solorized(RGBcolor.A); // new rgb color

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    imgSolar.SetPixel(x, y, Color.FromArgb(rgbNew.A[x, y], rgbNew.R[x, y], rgbNew.G[x, y], rgbNew.B[x, y]));
                }
            }
            pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox2.Image    = imgSolar;
        }
コード例 #3
0
        private void button4_Click(object sender, EventArgs e) // лінеаризація
        {
            double min   = double.Parse(textBox1.Text);
            double max   = double.Parse(textBox2.Text);
            float  L_new = float.Parse(textBox3.Text);

            imgLinerized = new Bitmap(img);
            HSLconvertor hsl = new HSLconvertor();

            hsl.toHSL(RGBcolor, img.Height, img.Width);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    if (hsl.L[i, j] > min && hsl.L[i, j] < max)
                    {
                        hsl.L[i, j] = L_new;
                    }
                }
            }

            RGBcolor rgb = new RGBcolor();

            rgb = hsl.toRGB(RGBcolor.A);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    imgLinerized.SetPixel(x, y, Color.FromArgb(rgb.A[x, y], rgb.R[x, y], rgb.G[x, y], rgb.B[x, y]));
                }
            }
            pictureBox4.SizeMode = PictureBoxSizeMode.Zoom;
            pictureBox4.Image    = imgLinerized;
        }
コード例 #4
0
        public HSLconvertor toHSL(RGBcolor color, int height, int width)
        {
            this.height = height;
            this.width  = width;
            float[,] R  = new float[width, height];
            float[,] G  = new float[width, height];
            float[,] B  = new float[width, height];
            this.Cmax   = new float[width, height];
            this.Cmin   = new float[width, height];
            this.delta  = new float[width, height];
            this.H      = new float[width, height];
            this.S      = new float[width, height];
            this.L      = new float[width, height];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    R[x, y]          = (float)color.R[x, y] / 255; // R'
                    G[x, y]          = (float)color.G[x, y] / 255; // G'
                    B[x, y]          = (float)color.B[x, y] / 255; // B'
                    this.Cmax[x, y]  = (float)Math.Max(R[x, y], Math.Max(G[x, y], B[x, y]));
                    this.Cmin[x, y]  = (float)Math.Min(R[x, y], Math.Min(G[x, y], B[x, y]));
                    this.delta[x, y] = (float)this.Cmax[x, y] - this.Cmin[x, y];

                    // hue calculation
                    if (this.delta[x, y] == 0)
                    {
                        this.H[x, y] = 0;
                    }
                    else
                    {
                        if (this.Cmax[x, y] == R[x, y])
                        {
                            this.H[x, y] = (G[x, y] - B[x, y] / this.delta[x, y]) % 6;
                        }
                        else if (this.Cmax[x, y] == G[x, y])
                        {
                            this.H[x, y] = ((B[x, y] - R[x, y]) / this.delta[x, y]) + 2f;
                        }
                        else if (this.Cmax[x, y] == B[x, y])
                        {
                            this.H[x, y] = ((R[x, y] - G[x, y]) / this.delta[x, y]) + 4f;
                        }

                        // convert to degrees
                        this.H[x, y] *= 60f;
                        if (this.H[x, y] < 0)
                        {
                            this.H[x, y] += 360;
                        }
                    }

                    // lightness calculation
                    this.L[x, y] = ((this.Cmax[x, y] + this.Cmin[x, y]) / 2);

                    //saturation calculation
                    if (this.delta[x, y] == 0)
                    {
                        this.S[x, y] = 0;
                    }
                    else
                    {
                        this.S[x, y] = this.delta[x, y] / (1 - Math.Abs(2 * this.L[x, y] - 1));
                    }
                }
            }



            return(new HSLconvertor(this.H, this.S, this.L));
        }
コード例 #5
0
        public RGBcolor toRGB(int[,] A)
        {
            double R = 0;
            double G = 0;
            double B = 0;

            double C;
            double X;
            double m;

            RGBcolor color = new RGBcolor();

            color.R = new int[width, height];
            color.G = new int[width, height];
            color.B = new int[width, height];
            color.A = new int[width, height];



            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    C = (1 - Math.Abs(2 * this.L[x, y] - 1)) * this.S[x, y];
                    X = C * (1 - Math.Abs((this.H[x, y] / 60) % 2 - 1));
                    m = this.L[x, y] - C / 2;

                    if (this.H[x, y] >= 0 && this.H[x, y] < 60)
                    {
                        R = C;
                        G = X;
                        B = 0;
                    }
                    else if (this.H[x, y] >= 60 && this.H[x, y] < 120)
                    {
                        R = X;
                        G = C;
                        B = 0;
                    }
                    else if (this.H[x, y] >= 120 && this.H[x, y] < 180)
                    {
                        R = 0;
                        G = C;
                        B = X;
                    }
                    else if (this.H[x, y] >= 180 && this.H[x, y] < 240)
                    {
                        R = 0;
                        G = X;
                        B = C;
                    }
                    else if (this.H[x, y] >= 240 && this.H[x, y] < 300)
                    {
                        R = X;
                        G = 0;
                        B = C;
                    }
                    else if (this.H[x, y] >= 300 && this.H[x, y] < 360)
                    {
                        R = C;
                        G = 0;
                        B = X;
                    }
                    color.A[x, y] = A[x, y];
                    color.R[x, y] = (int)((R + m) * 255);
                    color.G[x, y] = (int)((G + m) * 255);
                    color.B[x, y] = (int)((B + m) * 255);
                }
            }
            return(color);
        }
コード例 #6
0
        public RGBcolor toRGB_solorized(int[,] A)
        {
            double R = 0;
            double G = 0;
            double B = 0;

            double C;
            double X;
            double m;
            double lnew;

            RGBcolor color = new RGBcolor();

            color.R = new int[width, height];
            color.G = new int[width, height];
            color.B = new int[width, height];
            color.A = new int[width, height];

            double Lmax = this.L.Cast <float>().Max();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    lnew = 4 / Lmax * this.L[x, y] * (Lmax - this.L[x, y]);
                    C    = (1 - Math.Abs(2 * lnew - 1)) * this.S[x, y];
                    X    = C * (1 - Math.Abs((this.H[x, y] / 60) % 2 - 1));
                    m    = lnew - C / 2;

                    if (this.H[x, y] >= 0 && this.H[x, y] < 60)
                    {
                        R = C;
                        G = X;
                        B = 0;
                    }
                    else if (this.H[x, y] >= 60 && this.H[x, y] < 120)
                    {
                        R = X;
                        G = C;
                        B = 0;
                    }
                    else if (this.H[x, y] >= 120 && this.H[x, y] < 180)
                    {
                        R = 0;
                        G = C;
                        B = X;
                    }
                    else if (this.H[x, y] >= 180 && this.H[x, y] < 240)
                    {
                        R = 0;
                        G = X;
                        B = C;
                    }
                    else if (this.H[x, y] >= 240 && this.H[x, y] < 300)
                    {
                        R = X;
                        G = 0;
                        B = C;
                    }
                    else if (this.H[x, y] >= 300 && this.H[x, y] < 360)
                    {
                        R = C;
                        G = 0;
                        B = X;
                    }
                    color.A[x, y] = A[x, y];
                    color.R[x, y] = (int)((R + m) * 255);
                    color.G[x, y] = (int)((G + m) * 255);
                    color.B[x, y] = (int)((B + m) * 255);
                }
            }
            return(color);
        }