Esempio n. 1
0
        void Gist_RGB_and_GREY()
        {
            List <byte> ColorR    = new List <byte>();
            List <byte> ColorG    = new List <byte>();
            List <byte> ColorB    = new List <byte>();
            List <byte> ColorGREY = new List <byte>();

            byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]);
            int width  = Im[comboBox1.SelectedIndex].Width,
                height = Im[comboBox1.SelectedIndex].Height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ColorR.Add(rgb[0, y, x]);
                    ColorG.Add(rgb[1, y, x]);
                    ColorB.Add(rgb[2, y, x]);
                    ColorGREY.Add(RGB.Limit(0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x]));
                }
            }
            int Porig1R    = otsuThreshold(ColorR, 1);
            int Porig1G    = otsuThreshold(ColorG, 2);
            int Porig1B    = otsuThreshold(ColorB, 3);
            int Porig1GREY = otsuThreshold(ColorGREY, 4);
        }
Esempio n. 2
0
        private void ерозіяToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]);
            int width  = Im[comboBox1.SelectedIndex].Width,
                height = Im[comboBox1.SelectedIndex].Height;

            byte[,,] rgbN = new byte[3, height, width];

            int Rozmir_maski_S = 1;

            int[,] S = StructElement(toolStripComboBox1.SelectedIndex);

            bool nullPoint = false;

            for (int y = Rozmir_maski_S; y < height - Rozmir_maski_S; y++)
            {
                for (int x = Rozmir_maski_S; x < width - Rozmir_maski_S; x++)
                {
                    if (rgb[0, y, x] == 255)
                    {
                        nullPoint = false;

                        for (int i = -Rozmir_maski_S; i <= Rozmir_maski_S; i++)
                        {
                            for (int j = -Rozmir_maski_S; j <= Rozmir_maski_S; j++)
                            {
                                if (S[1 + i, 1 + j] == 1)
                                {
                                    if (rgb[0, y + i, x + j] == 0)
                                    {
                                        nullPoint = true;
                                    }
                                }
                            }
                        }

                        if (nullPoint == true)
                        {
                            rgbN[0, y, x] = RGB.Limit(0);
                            rgbN[1, y, x] = RGB.Limit(0);
                            rgbN[2, y, x] = RGB.Limit(0);
                        }
                        else
                        {
                            rgbN[0, y, x] = RGB.Limit(255);
                            rgbN[1, y, x] = RGB.Limit(255);
                            rgbN[2, y, x] = RGB.Limit(255);
                        }
                    }
                }
            }

            Im.Add(RGB.RgbToBitmapNaive(rgbN));

            comboBox1.Items.Add(comboBox1.Text + "+E" + toolStripComboBox1.SelectedIndex);
            comboBox1.Text = comboBox1.Text + "+E" + toolStripComboBox1.SelectedIndex;

            label2.Text = "E" + toolStripComboBox1.SelectedIndex;
        }
Esempio n. 3
0
        private void градаціяСірогоToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]);

            int width  = Im[comboBox1.SelectedIndex].Width,
                height = Im[comboBox1.SelectedIndex].Height;

            byte[,,] rgbN = new byte[3, height, width];

            double buf = 0;

            dataGridView1.ColumnCount = width;
            dataGridView1.RowCount    = height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    buf = 0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x];

                    rgbN[0, y, x] = RGB.Limit(buf);
                    rgbN[1, y, x] = RGB.Limit(buf);
                    rgbN[2, y, x] = RGB.Limit(buf);

                    if (rgbN[0, y, x] != 255)
                    {
                        dataGridView1.Rows[y].Cells[x].Value = Convert.ToString(rgbN[0, y, x]);
                    }
                }
            }

            Etalon = RGB.RgbToBitmapNaive(rgbN);

            Im.Add(RGB.RgbToBitmapNaive(rgbN));

            comboBox1.Items.Add(comboBox1.Text + "+GS");
            comboBox1.Text = comboBox1.Text + "+GS";

            label2.Text = "GS";
        }
Esempio n. 4
0
        private void однаГраницяToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <byte> ColorGREY = new List <byte>();

            byte[,,] rgb = RGB.BitmapToByteRgbNaive(Im[comboBox1.SelectedIndex]);
            int width  = Im[comboBox1.SelectedIndex].Width,
                height = Im[comboBox1.SelectedIndex].Height;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    ColorGREY.Add(RGB.Limit(0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x]));
                }
            }
            int Porig1GREY = otsuThreshold(ColorGREY, 4);

            byte[,,] rgbN = new byte[3, height, width];

            double buf = 0;

            PersentBin = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    buf = 0.2125 * rgb[0, y, x] + 0.7154 * rgb[1, y, x] + 0.0721 * rgb[2, y, x];

                    if (buf <= Porig1GREY)
                    {
                        PersentBin++;
                        rgbN[0, y, x] = RGB.Limit(255);
                        rgbN[1, y, x] = RGB.Limit(255);
                        rgbN[2, y, x] = RGB.Limit(255);
                    }
                    else
                    {
                        rgbN[0, y, x] = RGB.Limit(0);
                        rgbN[1, y, x] = RGB.Limit(0);
                        rgbN[2, y, x] = RGB.Limit(0);
                    }

                    //if (buf <= Porig1GREY)
                    //{
                    //    PersentBin++;
                    //    rgbN[0, y, x] = RGB.Limit(0);
                    //    rgbN[1, y, x] = RGB.Limit(0);
                    //    rgbN[2, y, x] = RGB.Limit(0);
                    //}
                    //else
                    //{
                    //    rgbN[0, y, x] = RGB.Limit(255);
                    //    rgbN[1, y, x] = RGB.Limit(255);
                    //    rgbN[2, y, x] = RGB.Limit(255);
                    //}
                }
            }

            PersentBin /= (width * height);

            Im.Add(RGB.RgbToBitmapNaive(rgbN));

            comboBox1.Items.Add(comboBox1.Text + "+Bin");
            comboBox1.Text = comboBox1.Text + "+Bin";

            label2.Text = "Bin";
            label3.Text = Math.Round(PersentBin, 4).ToString();
        }