Пример #1
0
        private byte[,] GetRobertsEdgeMatrix()
        {
            byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);

            int width  = f.GetLength(0);
            int height = f.GetLength(1);

            byte[,] g = new byte[width - 1, height - 1];
            for (int x = 0; x < width - 1; x++)
            {
                for (int y = 0; y < height - 1; y++)
                {
                    g[x, y] = (byte)(Math.Abs(f[x + 1, y + 1] - f[x, y]) + Math.Abs(f[x, y + 1] - f[x + 1, y]));
                    if (g[x, y] > 255)
                    {
                        g[x, y] = 255;
                    }
                    if (g[x, y] < 0)
                    {
                        g[x, y] = 0;
                    }
                }
            }
            return(g);
        }
Пример #2
0
        private void добавитьШумToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NoiseForm noiseForm = new NoiseForm();

            noiseForm.Owner = this;
            noiseForm.ShowDialog();
        }
Пример #3
0
        private void лапласианToolStripMenuItem_Click(object sender, EventArgs e)
        {
            byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);

            int width  = f.GetLength(0);
            int height = f.GetLength(1);

            byte[,] g = new byte[width - 2, height - 2];
            int Vf = 0;

            for (int x = 1; x < width - 1; x++)
            {
                for (int y = 1; y < height - 1; y++)
                {
                    Vf = f[x + 1, y] + f[x, y + 1] + f[x - 1, y] + f[x, y - 1] - 4 * f[x, y];
                    g[x - 1, y - 1] = (byte)Vf;
                    if (g[x - 1, y - 1] > 255)
                    {
                        g[x - 1, y - 1] = 255;
                    }
                    if (g[x - 1, y - 1] < 0)
                    {
                        g[x - 1, y - 1] = 0;
                    }
                }
            }
            alteredImageBox.Image = GetImageFromMatrix(g);
        }
Пример #4
0
 private void построениеОстоваToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.Enabled          = false;
     byte[,] f             = MakeBinaryImage(NoiseForm.GetBrightnessMatrix(originalImageBox.Image));
     alteredImageBox.Image = GetImageFromMatrix(Skeletonization(f));
     Enabled = true;
 }
Пример #5
0
        private void методКближайшихСоседейToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetNForm setN = new SetNForm();

            setN.Owner = this;
            setN.ShowDialog();

            byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);
            KNearestNeighbors(f);
        }
        private void UseFirstMask()
        {
            byte[,] imageBrightness = NoiseForm.GetBrightnessMatrix(image);

            int width  = imageBrightness.GetLength(0);
            int height = imageBrightness.GetLength(1);

            for (int i = 0; i < width; i++)
            {
                for (int j = 1; j < height - 1; j++)
                {
                    byte[] array = new byte[3] {
                        imageBrightness[i, j - 1], imageBrightness[i, j], imageBrightness[i, j + 1]
                    };
                    imageBrightness[i, j] = array.OrderBy(q => q).ToArray()[1];
                }
            }
            mainForm.alteredImageBox.Image = MainForm.GetImageFromMatrix(imageBrightness);
        }
        private void UseSecondMask()
        {
            byte[,] imageBrightness = NoiseForm.GetBrightnessMatrix(image);

            int width  = imageBrightness.GetLength(0);
            int height = imageBrightness.GetLength(1);

            byte[,] t = new byte[width - 2, height - 2];
            for (int i = 1; i < width - 1; i++)
            {
                for (int j = 1; j < height - 1; j++)
                {
                    byte[] array = new byte[] { imageBrightness[i - 1, j + 1], imageBrightness[i, j + 1], imageBrightness[i + 1, j + 1],
                                                imageBrightness[i - 1, j], imageBrightness[i, j], imageBrightness[i + 1, j],
                                                imageBrightness[i - 1, j - 1], imageBrightness[i, j - 1], imageBrightness[i + 1, j - 1] };
                    t[i - 1, j - 1] = array.OrderBy(q => q).ToArray()[5];
                }
            }
            mainForm.alteredImageBox.Image = MainForm.GetImageFromMatrix(t);
        }
Пример #8
0
        private void originalImageBox_MouseClick(object sender, MouseEventArgs e)
        {
            if (alteredImageBox.Image != null)
            {
                paintedOver = NoiseForm.GetBrightnessMatrix(alteredImageBox.Image);
            }
            else
            {
                paintedOver = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);
            }
            paintedOver[e.X, e.Y] = 0;

            PaintOver(e.X, e.Y + 1);
            PaintOver(e.X + 1, e.Y);
            PaintOver(e.X - 1, e.Y);
            PaintOver(e.X, e.Y - 1);

            int width = paintedOver.GetLength(0), height = paintedOver.GetLength(1), pixel;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    pixel = paintedOver[i, j];
                    try
                    {
                        alteredImage.SetPixel(i, j, Color.FromArgb(pixel, pixel, pixel));
                    }
                    catch
                    {
                        alteredImage = new Bitmap(originalImageBox.Image);
                        alteredImage.SetPixel(i, j, Color.FromArgb(pixel, pixel, pixel));
                    }
                }
            }
            alteredImageBox.Image = alteredImage;
        }
        private void UseThirdMask()
        {
            byte[,] br = NoiseForm.GetBrightnessMatrix(image);

            int width  = br.GetLength(0);
            int height = br.GetLength(1);

            byte[,] t = new byte[width - 4, height - 4];
            for (int i = 2; i < width - 2; i++)
            {
                for (int j = 2; j < height - 2; j++)
                {
                    byte[] array = new byte[] {
                        br[i, j + 2],
                        br[i - 1, j + 1], br[i, j + 1], br[i + 1, j + 1],
                        br[i - 2, j], br[i - 1, j], br[i, j], br[i + 1, j], br[i + 2, j],
                        br[i - 1, j - 1], br[i, j - 1], br[i + 1, j - 1],
                        br[i, j - 2]
                    };
                    t[i - 2, j - 2] = array.OrderBy(q => q).ToArray()[7];
                }
            }
            mainForm.alteredImageBox.Image = MainForm.GetImageFromMatrix(t);
        }
Пример #10
0
        private Bitmap MakeErosion()
        {
            int k = 2;

            if (mask3x3.Checked)
            {
                k = 1;
            }
            else if (mask5x5.Checked)
            {
                k = 2;
            }
            else if (mask7x7.Checked)
            {
                k = 3;
            }
            else if (mask9x9.Checked)
            {
                k = 4;
            }
            byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);
            int    width = f.GetLength(0), height = f.GetLength(1);
            bool   flag  = false;
            Bitmap image = new Bitmap(width - 2 * k, height - 2 * k);

            for (int x = k; x < width - k; x++)
            {
                for (int y = k; y < height - k; y++)
                {
                    for (int i = -k; i < k; i++)
                    {
                        for (int j = -k; j < k; j++)
                        {
                            if (f[x + i, y + j] >= 128)
                            {
                                flag = true;
                            }
                            else
                            {
                                flag = false;
                            }
                        }

                        if (!flag)
                        {
                            break;
                        }
                    }

                    if (flag)
                    {
                        image.SetPixel(x - k, y - k, Color.FromArgb(255, 255, 255));
                    }
                    else
                    {
                        image.SetPixel(x - k, y - k, Color.FromArgb(0, 0, 0));
                    }
                }
            }

            return(image);
        }
Пример #11
0
 private void сглаживаниеПоОднороднойОкрестностиToolStripMenuItem_Click(object sender, EventArgs e)
 {
     byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);
     SmoothingOver(f);
 }
Пример #12
0
 private void локальноеУсреднениеToolStripMenuItem_Click(object sender, EventArgs e)
 {
     byte[,] f = NoiseForm.GetBrightnessMatrix(originalImageBox.Image);
     LocalAveraging(f);
 }
Пример #13
0
 private void эрозияToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     byte[,] g             = MakeBinaryImage(NoiseForm.GetBrightnessMatrix(originalImage));
     byte[,] f             = Erosion(g);
     alteredImageBox.Image = GetImageFromMatrix(f);
 }