Exemple #1
0
        //h
        private void button4_Click(object sender, EventArgs e)
        {
            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < OwnerForm.localImage.Width; i++)
            {
                for (int j = 0; j < OwnerForm.localImage.Height; j++)
                {
                    Color  color = OwnerForm.originalImage.GetPixel(i, j);
                    double h, s, v;
                    ModelSettingsChooser.ColorToHSV(color, out h, out s, out v);

                    h = h + trackBar4.Value;

                    // корректировки
                    if (h > 360)
                    {
                        h = h - 360;
                    }
                    if (h < 0)
                    {
                        h = h + 360;
                    }

                    color = ModelSettingsChooser.HSVToColor(h, s, v);
                    OwnerForm.localImage.SetPixel(i, j, color);
                }
            }
            OwnerForm.updatePicturebox();

            stopwatch.Stop();
            timeLabel.Text = "Time taken " + stopwatch.ElapsedMilliseconds;
        }
Exemple #2
0
        //v
        private void button7_Click(object sender, EventArgs e)
        {
            stopwatch.Reset();
            stopwatch.Start();

            for (int i = 0; i < OwnerForm.localImage.Width; i++)
            {
                for (int j = 0; j < OwnerForm.localImage.Height; j++)
                {
                    Color  color = OwnerForm.originalImage.GetPixel(i, j);
                    double h, s, v;
                    ModelSettingsChooser.ColorToHSV(color, out h, out s, out v);

                    v = v + (v / 10 * trackBar7.Value);

                    if (v > 1)
                    {
                        v = 1;
                    }
                    else if (v < 0)
                    {
                        v = 0;
                    }

                    color = ModelSettingsChooser.HSVToColor(h, s, v);
                    OwnerForm.localImage.SetPixel(i, j, color);
                }
            }
            OwnerForm.updatePicturebox();

            stopwatch.Stop();
            timeLabel.Text = "Time taken " + stopwatch.ElapsedMilliseconds;
        }
Exemple #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (originalImage != null)
     {
         ModelSettingsChooser form = new ModelSettingsChooser(originalImage);
         form.ShowDialog();
     }
     else
     {
         MessageBox.Show("Изображение не существует");
     }
 }
Exemple #4
0
        private void Lab2Form_Load(object sender, EventArgs e)
        {
            RGBImage = new Bitmap(source);
            YUVImage = new Bitmap(source.Width, source.Height);
            for (int i = 0; i < source.Width; i++)
            {
                for (int j = 0; j < source.Height; j++)
                {
                    Color  color = source.GetPixel(i, j);
                    double Y, U, V;
                    ModelSettingsChooser.ColorToYUV(color, out Y, out U, out V);
                    YUVImage.SetPixel(i, j, Color.FromArgb((int)Y, (int)U, (int)V));
                }
            }

            PictureBox.Image        = RGBImage;
            originalImage           = new Bitmap(RGBImage);
            comboBox1.SelectedIndex = 0;
        }
Exemple #5
0
        public Bitmap applyMultiplicativeNoize(string colorMode, Bitmap originalImage, int noizeLevel, int kmin, int kmax, int colorChannel = 0)
        {
            Bitmap result = new Bitmap(originalImage);
            int    noisepixel = (int)(originalImage.Width * originalImage.Height * noizeLevel / 100);
            int    x, y, randomValue;
            Color  color;
            double value1, value2, value3;

            //повторить для каждого пикселя на изображении в процентном отношении (т.е. noizeLevel процентов)
            for (int i = 0; i < noisepixel; i++)
            {
                //получаем случайный пиксель на изображении и случайное значение
                x           = rand.Next(0, originalImage.Width);
                y           = rand.Next(0, originalImage.Height);
                color       = originalImage.GetPixel(x, y);
                randomValue = rand.Next(0, 100);

                if (colorMode == "RGB" || colorMode == "YUV")
                {
                    if (colorChannel == 0)
                    {
                        value1 = getMultiplicativeAdditionalValue(color.R, kmin, kmax, "RGB");
                        value2 = getMultiplicativeAdditionalValue(color.G, kmin, kmax, "RGB");
                        value3 = getMultiplicativeAdditionalValue(color.B, kmin, kmax, "RGB");
                        result.SetPixel(x, y, Color.FromArgb((int)value1, (int)value2, (int)value3));
                    }
                    else
                    {
                        //массив с цветами, нужен для RGB и YUV
                        int[] colors = new int[3];
                        colors[0] = color.R;
                        colors[1] = color.G;
                        colors[2] = color.B;

                        colors[colorChannel - 1] = getMultiplicativeAdditionalValue(colors[colorChannel - 1], kmin, kmax, "RGB");

                        result.SetPixel(x, y, Color.FromArgb(colors[0], colors[1], colors[2]));
                    }
                }
                else if (colorMode == "HSL")
                {
                    double H, S, L;
                    ModelSettingsChooser.ColorToHSL(color, out H, out S, out L);
                    if (colorChannel == 0)
                    {
                        value1 = getMultiplicativeAdditionalValue((int)H, kmin, kmax, "H");
                        value2 = getMultiplicativeAdditionalValue((int)(S * 100), kmin, kmax, "S");
                        value3 = getMultiplicativeAdditionalValue((int)(L * 100), kmin, kmax, "L");
                        result.SetPixel(x, y, ModelSettingsChooser.HSLToColor(value1, value2, value3));
                    }
                    else if (colorChannel == 1)
                    {
                        value1 = getMultiplicativeAdditionalValue((int)H, kmin, kmax, "H");
                        result.SetPixel(x, y, ModelSettingsChooser.HSLToColor(value1, S, L));
                    }
                    else if (colorChannel == 2)
                    {
                        value2 = getMultiplicativeAdditionalValue((int)(S * 100), kmin, kmax, "S");
                        result.SetPixel(x, y, ModelSettingsChooser.HSLToColor(H, value2, L));
                    }
                    else if (colorChannel == 3)
                    {
                        value3 = getMultiplicativeAdditionalValue((int)(L * 100), kmin, kmax, "L");
                        result.SetPixel(x, y, ModelSettingsChooser.HSLToColor(H, S, value3));
                    }
                }
                else if (colorMode == "HSV")
                {
                    double H, S, V;
                    ModelSettingsChooser.ColorToHSV(color, out H, out S, out V);
                    if (colorChannel == 0)
                    {
                        value1 = getMultiplicativeAdditionalValue((int)H, kmin, kmax, "H");
                        value2 = getMultiplicativeAdditionalValue((int)(S * 100), kmin, kmax, "S");
                        value3 = getMultiplicativeAdditionalValue((int)(V * 100), kmin, kmax, "V");
                        result.SetPixel(x, y, ModelSettingsChooser.HSVToColor(value1, value2, value3));
                    }
                    else if (colorChannel == 1)
                    {
                        value1 = getMultiplicativeAdditionalValue((int)H, kmin, kmax, "H");
                        result.SetPixel(x, y, ModelSettingsChooser.HSVToColor(value1, S, V));
                    }
                    else if (colorChannel == 2)
                    {
                        value2 = getMultiplicativeAdditionalValue((int)(S * 100), kmin, kmax, "S");
                        result.SetPixel(x, y, ModelSettingsChooser.HSVToColor(H, value2, V));
                    }
                    else if (colorChannel == 3)
                    {
                        value3 = getMultiplicativeAdditionalValue((int)(V * 100), kmin, kmax, "V");
                        result.SetPixel(x, y, ModelSettingsChooser.HSVToColor(H, S, value3));
                    }
                }
                else
                {
                    MessageBox.Show("Цветовой режим не известен или не определен :(");
                }
            }

            return(result);
        }
Exemple #6
0
        public Bitmap applyImpulseNoize(string colorMode, Bitmap originalImage, int noizeLevel, double impulseK, int colorChannel = 0)
        {
            Bitmap result = new Bitmap(originalImage);
            int    noisepixel = (int)(originalImage.Width * originalImage.Height * noizeLevel / 100);
            int    x, y, randomValue;
            Color  color, tempColor;

            //повторить для каждого пикселя на изображении в процентном отношении (т.е. noizeLevel процентов)
            for (int i = 0; i < noisepixel; i++)
            {
                //получаем случайный пиксель на изображении и случайное значение
                x           = rand.Next(0, originalImage.Width);
                y           = rand.Next(0, originalImage.Height);
                color       = originalImage.GetPixel(x, y);
                randomValue = rand.Next(0, 100);

                //обработка RGB и YUV
                #region RGB and YUV processing
                if (colorMode == "RGB" || colorMode == "YUV")
                {
                    //массив с цветами, нужен для RGB и YUV
                    int[] colors = new int[3];
                    colors[0] = color.R;
                    colors[1] = color.G;
                    colors[2] = color.B;

                    //если канал - базовый (например полный RGB)
                    if (colorChannel == 0)
                    {
                        if (randomValue < impulseK)
                        {
                            result.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                        }
                        else
                        {
                            result.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                        }
                    }
                    else
                    {
                        if (randomValue < impulseK)
                        {
                            //зануляем соответстствующий канал
                            colors[colorChannel - 1] = 0;
                            result.SetPixel(x, y, Color.FromArgb(colors[0], colors[1], colors[2]));
                        }
                        else
                        {
                            colors[colorChannel - 1] = 255;
                            result.SetPixel(x, y, Color.FromArgb(colors[0], colors[1], colors[2]));
                        }
                    }
                }
                #endregion rgb

                #region HSL and HSV
                else if (colorMode == "HSL")
                {
                    double H, S, L;
                    ModelSettingsChooser.ColorToHSL(color, out H, out S, out L);

                    //All
                    if (colorChannel == 0)
                    {
                        if (randomValue < impulseK)
                        {
                            H -= 180;
                            S  = L = 0;
                        }
                        else
                        {
                            H += 180;
                            S  = L = 1;
                        }
                    }
                    //Hue
                    else if (colorChannel == 1)
                    {
                        if (randomValue < impulseK)
                        {
                            H -= 180;
                        }
                        else
                        {
                            H += 180;
                        }
                    }
                    //S
                    else if (colorChannel == 2)
                    {
                        if (randomValue < impulseK)
                        {
                            S = 0;
                        }
                        else
                        {
                            S = 1;
                        }
                    }
                    //L
                    else if (colorChannel == 3)
                    {
                        if (randomValue < impulseK)
                        {
                            L = 0;
                        }
                        else
                        {
                            L = 1;
                        }
                    }

                    H         = CorrectHue(H);
                    tempColor = ModelSettingsChooser.HSLToColor(H, S, L);
                    result.SetPixel(x, y, tempColor);
                }
                else if (colorMode == "HSV")
                {
                    double H, S, V;
                    ModelSettingsChooser.ColorToHSV(color, out H, out S, out V);

                    //All
                    if (colorChannel == 0)
                    {
                        if (randomValue < impulseK)
                        {
                            H -= 180;
                            S  = V = 0;
                        }
                        else
                        {
                            H += 180;
                            S  = V = 1;
                        }
                    }
                    //Hue
                    else if (colorChannel == 1)
                    {
                        if (randomValue < impulseK)
                        {
                            H -= 180;
                        }
                        else
                        {
                            H += 180;
                        }
                    }
                    //S
                    else if (colorChannel == 2)
                    {
                        if (randomValue < impulseK)
                        {
                            S = 0;
                        }
                        else
                        {
                            S = 1;
                        }
                    }
                    //L
                    else if (colorChannel == 3)
                    {
                        if (randomValue < impulseK)
                        {
                            V = 0;
                        }
                        else
                        {
                            V = 1;
                        }
                    }

                    H         = CorrectHue(H);
                    tempColor = ModelSettingsChooser.HSVToColor(H, S, V);
                    result.SetPixel(x, y, tempColor);
                }
                #endregion
                else
                {
                    MessageBox.Show("Цветовой режим не известен или не определен :(");
                }
            }

            return(result);
        }
Exemple #7
0
        public void CountHystograms(string mode, out double[] R, out double[] G, out double[] B, out string rName, out string gName, out string bName)
        {
            //int[] points = new int[100];
            R     = new double[256];
            G     = new double[256];
            B     = new double[256];
            rName = "Red";
            gName = "Green";
            bName = "Blue";
            Color color;

            for (int i = 0; i < localImage.Width; i++)
            {
                for (int j = 0; j < localImage.Height; j++)
                {
                    color = localImage.GetPixel(i, j);
                    if (mode == "RGB")
                    {
                        rName = "Red";
                        gName = "Green";
                        bName = "Blue";
                        ++R[color.R];
                        ++G[color.G];
                        ++B[color.B];
                    }
                    else if (mode == "YUV")
                    {
                        double Y, U, V;
                        ModelSettingsChooser.ColorToYUV(color, out Y, out U, out V);
                        rName = "Y";
                        gName = "U";
                        bName = "V";
                        ++R[(int)Y];
                        ++G[(int)U];
                        ++B[(int)V];
                    }
                    else if (mode == "HSL")
                    {
                        double H, S, L;
                        ModelSettingsChooser.ColorToHSL(color, out H, out S, out L);
                        rName = "Hue";
                        gName = "Saturation";
                        bName = "Brightness";
                        ++R[(int)(H * 255)];
                        ++G[(int)(S * 255)];
                        ++B[(int)(L * 255)];
                    }
                    else if (mode == "HSV")
                    {
                        double H, S, V;
                        ModelSettingsChooser.ColorToHSV(color, out H, out S, out V);
                        rName = "Hue";
                        gName = "Saturation";
                        bName = "Value";
                        ++R[(int)(H / 360 * 255)];
                        ++G[(int)(S * 255)];
                        ++B[(int)(V * 255)];
                    }
                }
            }
            //double maxValue = 0;
            //for (int i = 0; i < 256; ++i)
            //{
            //    if (R[i] > maxValue)
            //        maxValue = R[i];
            //    if (G[i] > maxValue)
            //        maxValue = G[i];
            //    if (B[i] > maxValue)
            //        maxValue = B[i];
            //}
        }