Esempio n. 1
0
        private void grayscaleReduction()
        {
            Bitmap bm = new Bitmap(imageWindow.getImage());

            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    Color c      = bm.GetPixel(x, y);
                    var   points = chartDrawing.Series["Series1"].Points;
                    for (int i = 0; i < points.Count - 1; ++i)
                    {
                        if (c.R >= points[i].XValue && c.R <= points[i + 1].XValue)
                        {
                            int   q     = Convert.ToInt32(points[i].YValues[0]);
                            Color color = Color.FromArgb(255, q, q, q);
                            bm.SetPixel(x, y, color);
                        }
                    }
                }
            }

            pictureBox.Image = bm;
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox.Image, maxBmpLevel);
        }
Esempio n. 2
0
 public void setNewImage(Image image)
 {
     pictureBox1.Image = image;
     maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     HistogramOperations.clearHistogram(chart1);
     histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
 }
        private void tresholding()
        {
            Bitmap bitmap = new Bitmap(imageWindow.getImage());

            histoTab = new int[2];

            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color c = bitmap.GetPixel(x, y);
                    if (c.R <= bottomValueTrackBar.Value)
                    {
                        bitmap.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                        histoTab[0]++;
                    }
                    else
                    {
                        bitmap.SetPixel(x, y, Color.FromArgb(255, 255, 255));
                        histoTab[1]++;
                    }
                }
            }

            pictureBox1.Image = bitmap;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            chart1.Series["Series1"].Points.AddXY(0, histoTab[0]);
            chart1.Series["Series1"].Points.AddXY(1, histoTab[1]);
        }
Esempio n. 4
0
 private void ButtonReset_Click(object sender, EventArgs e)
 {
     pictureBox1.Image = bitmapCopy;
     acttualImage      = new Image <Gray, byte>(bitmapCopy);
     maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     HistogramOperations.clearHistogram(chart1);
     HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);
 }
Esempio n. 5
0
 private void cancelButton_Click(object sender, EventArgs e)
 {
     initializeReductionChart((int)domainUpDown1.SelectedItem);
     HistogramOperations.clearHistogram(chart1);
     pictureBox.Image = (Image)imageWindow.getImage().Clone();
     histoTab         = HistogramOperations.drawHistogram(chart1, pictureBox.Image, maxBmpLevel);
     grayscaleReduction();
 }
 private void previewButton_Click(object sender, EventArgs e)
 {
     operatioCalc();
     pictureBox1.Image = currentImage;
     HistogramOperations.clearHistogram(chart1);
     HistogramOperations.drawHistogram(chart1, pictureBox1.Image, HistogramOperations.MaxBmpLevel(pictureBox1.Image));
     acceptButton.Enabled = true;
 }
Esempio n. 7
0
        public void losMethodHisto()
        {
            int hAvg = 0;
            int R    = 0;
            int Hint = 0;

            int[] left     = new int[maxBmpLevel + 1];
            int[] right    = new int[maxBmpLevel + 1];
            int[] newValue = new int[maxBmpLevel + 1];

            for (int i = 0; i < histoTab.Length; i++)
            {
                hAvg += histoTab[i];
            }

            Bitmap bm = new Bitmap(pictureBox1.Image);

            hAvg = hAvg / 256;

            for (int Z = 0; Z < histoTab.Length; Z++)
            {
                left[Z] = R;
                Hint    = Hint + histoTab[Z];
                while (Hint > hAvg)
                {
                    Hint = Hint - hAvg;
                    R++;
                }
                right[Z]    = R;
                newValue[Z] = right[Z] - left[Z];
            }

            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    Color c = bm.GetPixel(x, y);
                    if (left[c.R] == right[c.R])
                    {
                        Color color = Color.FromArgb(255, left[c.R], left[c.R], left[c.R]);
                        bm.SetPixel(x, y, color);
                    }
                    else
                    {
                        Random rnd   = new Random();
                        int    los   = rnd.Next(0, newValue[c.R]);
                        Color  color = Color.FromArgb(255, left[c.R] + los, left[c.R] + los, left[c.R] + los);
                        bm.SetPixel(x, y, color);
                    }
                }
            }

            pictureBox1.Image = bm;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
Esempio n. 8
0
 public void setNewImage(Image image, int[] histTab)
 {
     pictureBox1.Image = image;
     maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     HistogramOperations.clearHistogram(chart1);
     histoTab = histTab;
     chart1.Series["Series1"].Points.AddXY(0, histoTab[0]);
     chart1.Series["Series1"].Points.AddXY(1, histoTab[1]);
 }
Esempio n. 9
0
        public void Thining()
        {
            Image <Gray, Byte> sourceImage = new Image <Gray, byte>((Bitmap)pictureBox1.Image);
            Image <Gray, Byte> dstImage    = new Image <Gray, Byte>(sourceImage.Width, sourceImage.Height);

            XImgprocInvoke.Thinning(sourceImage, dstImage, ThinningTypes.ZhangSuen);

            pictureBox1.Image = dstImage.ToBitmap();
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
        private void binaryOperation(Image image1, Image image2, OperationType operationType)
        {
            Bitmap bitmapImage1   = new Bitmap(image1);
            Bitmap bitmapImage2   = new Bitmap(image2);
            Bitmap bitmapNewImage = new Bitmap(bitmapImage1.Width, bitmapImage1.Height);

            if (bitmapImage1.Width == bitmapImage2.Width && bitmapImage1.Height == bitmapImage2.Height)
            {
                for (int x = 0; x < bitmapImage1.Width; x++)
                {
                    for (int y = 0; y < bitmapImage1.Height; y++)
                    {
                        Color c1 = bitmapImage1.GetPixel(x, y);
                        Color c2 = bitmapImage2.GetPixel(x, y);
                        int   q  = 0;

                        switch (operationType)
                        {
                        case OperationType.Add:
                            q = (c1.R + c2.R) / 2;
                            break;

                        case OperationType.Sub:
                            q = Math.Abs(c1.R - c2.R);
                            break;

                        case OperationType.Or:
                            q = c1.R | c2.R;
                            break;

                        case OperationType.And:
                            q = c1.R & c2.R;
                            break;

                        case OperationType.Xor:
                            q = c1.R ^ c2.R;
                            break;
                        }

                        bitmapNewImage.SetPixel(x, y, Color.FromArgb(255, q, q, q));
                    }
                }

                pictureBox1.Image = bitmapNewImage;
                HistogramOperations.clearHistogram(chart1);
                maxBmpLevel = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
                histoTab    = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
            }
            else
            {
                MessageBox.Show("Dla operacji dwuargumentowych, należy wybrać obrazy o takich samych wymiarach.", "Nie poprawne wymiary obrazów");
            }
        }
        private void cancelButton_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = (Image)imageWindow.getImage().Clone();
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);

            bottomValueTrackBar.Value = 0;
            upperValueTrackBar.Value  = maxBmpLevel;

            bottomValueLabel.Text = "0";
            upperValueLabel.Text  = maxBmpLevel.ToString();
        }
Esempio n. 12
0
        public void RegionGrowing()
        {
            Image <Bgr, Byte>  img     = new Image <Bgr, byte>((Bitmap)pictureBox1.Image);
            Image <Gray, byte> grayImg = img.Convert <Gray, byte>();
            Image <Gray, byte> binImg  = new Image <Gray, byte>(grayImg.Size);

            CvInvoke.Threshold(grayImg, binImg, 100, 255, ThresholdType.Otsu | ThresholdType.Binary);

            pictureBox1.Image = binImg.ToBitmap();
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
        private void previewButton_Click(object sender, EventArgs e)
        {
            Bitmap bm            = new Bitmap(imageWindow.getImage());
            Bitmap resultbBitmap = new Bitmap(imageWindow.getImage().Width, imageWindow.getImage().Height);

            for (int x = 1; x < bm.Width - 1; x++)
            {
                for (int y = 1; y < bm.Height - 1; y++)
                {
                    if (uprightRadioButton.Checked)
                    {
                        if (bm.GetPixel(x, y - 1).R == bm.GetPixel(x, y + 1).R)
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x, y + 1));
                        }
                        else
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x, y));
                        }
                    }
                    else if (horizontallyRadioButton.Checked)
                    {
                        if (bm.GetPixel(x - 1, y).R == bm.GetPixel(x + 1, y).R)
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x + 1, y));
                        }
                        else
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x, y));
                        }
                    }
                    else if (bothRadioButton.Checked)
                    {
                        if (bm.GetPixel(x, y - 1) == bm.GetPixel(x, y + 1) && bm.GetPixel(x - 1, y) == bm.GetPixel(x + 1, y) && bm.GetPixel(x - 1, y) == bm.GetPixel(x, y - 1))
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x, y - 1));
                        }
                        else
                        {
                            resultbBitmap.SetPixel(x, y, bm.GetPixel(x, y));
                        }
                    }
                }
            }

            pictureBox1.Image = resultbBitmap;
            HistogramOperations.clearHistogram(chart1);
            maxBMPLevel = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);
            acceptButton.Enabled = true;
        }
Esempio n. 14
0
        public void negacja()
        {
            Bitmap bitmap = new Bitmap(pictureBox1.Image);

            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color currentPixelColor = bitmap.GetPixel(x, y);
                    Color newColor          = Color.FromArgb(maxBmpLevel - currentPixelColor.R, maxBmpLevel - currentPixelColor.G, maxBmpLevel - currentPixelColor.B);
                    bitmap.SetPixel(x, y, newColor);
                }
            }

            pictureBox1.Image = bitmap;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
Esempio n. 15
0
        private void ButtonPreview_Click(object sender, EventArgs e)
        {
            Image <Gray, Byte> sourceImage = acttualImage;
            Image <Gray, Byte> dstImage    = new Image <Gray, Byte>(sourceImage.Width, sourceImage.Height);
            Mat structuringElement;

            if (radioButtonFourNeighbors.Checked)
            {
                structuringElement = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Cross, new Size(3, 3), new Point(-1, -1));
            }
            else
            {
                structuringElement = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            }

            if (radioButtonErode.Checked)
            {
                CvInvoke.Erode(sourceImage, dstImage, structuringElement, new Point(-1, -1), (int)numericUpDownIterations.Value, Emgu.CV.CvEnum.BorderType.Replicate, new MCvScalar(1));
            }
            else if (radioButtonDilatation.Checked)
            {
                CvInvoke.Dilate(sourceImage, dstImage, structuringElement, new Point(-1, -1), (int)numericUpDownIterations.Value, Emgu.CV.CvEnum.BorderType.Reflect, new MCvScalar(1));
            }
            else if (radioButtonOpen.Checked)
            {
                CvInvoke.MorphologyEx(sourceImage, dstImage, Emgu.CV.CvEnum.MorphOp.Open, structuringElement, new Point(-1, -1), (int)numericUpDownIterations.Value, Emgu.CV.CvEnum.BorderType.Reflect, new MCvScalar(1));
            }
            else if (radioButtonClose.Checked)
            {
                CvInvoke.MorphologyEx(sourceImage, dstImage, Emgu.CV.CvEnum.MorphOp.Close, structuringElement, new Point(-1, -1), (int)numericUpDownIterations.Value, Emgu.CV.CvEnum.BorderType.Reflect, new MCvScalar(1));
            }

            acttualImage      = dstImage;
            pictureBox1.Image = dstImage.ToBitmap();
            maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);

            buttonSave.Enabled = true;
        }
        private void maintainingTresholding()
        {
            Bitmap bitmap = new Bitmap(imageWindow.getImage());

            for (int x = 0; x < bitmap.Width; x++)
            {
                for (int y = 0; y < bitmap.Height; y++)
                {
                    Color c = bitmap.GetPixel(x, y);
                    if (c.R <= bottomValueTrackBar.Value || c.R >= upperValueTrackBar.Value)
                    {
                        bitmap.SetPixel(x, y, Color.FromArgb(0, 0, 0));
                        histoTab[0]++;
                    }
                }
            }

            pictureBox1.Image = bitmap;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
Esempio n. 17
0
        private void stretchHisto()
        {
            Bitmap bm = new Bitmap(imageWindow.getImage());

            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    Color c = bm.GetPixel(x, y);
                    if (c.R >= bottomTrackBar.Value && c.R < upperTrackBar.Value)
                    {
                        int   q     = (c.R - bottomTrackBar.Value) * (255 / (upperTrackBar.Value - bottomTrackBar.Value));
                        Color color = Color.FromArgb(255, q, q, q);
                        bm.SetPixel(x, y, color);
                    }
                }
            }

            pictureBox1.Image = bm;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
Esempio n. 18
0
        public void Watershed()
        {
            //Source : http://yy-programer.blogspot.com/2012/11/emgucv-image-process-transforming_29.html

            //Read input image
            Image <Bgr, Byte> image = new Image <Bgr, Byte>((Bitmap)pictureBox1.Image);

            //Get the binary image
            Image <Gray, Byte> binary =
                image.Convert <Gray, Byte>().ThresholdBinaryInv(new Gray(140), new Gray(255));
            Mat closeElement = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Ellipse, new Size(5, 5), new Point(2, 2));

            binary = binary.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Close, closeElement, new Point(-1, -1), 1, Emgu.CV.CvEnum.BorderType.Default, new MCvScalar());


            //Eliminate noise and smaller objects
            Image <Gray, Byte> foreground = binary.Erode(6);

            //Identify image pixels without objects
            Image <Gray, Byte> background = binary.Dilate(6);

            background._ThresholdBinaryInv(new Gray(1), new Gray(128));

            //Create markers image
            Image <Gray, Byte> markers = background + foreground;
            //Create watershed segmentation object
            WatershedSegmenter watershedSegmenter = new WatershedSegmenter();

            //Set markers and process
            watershedSegmenter.SetMakers(markers);
            Image <Gray, Int32> boundaryImage = watershedSegmenter.Process(image);

            pictureBox1.Image = watershedSegmenter.GetWatersheds().ToBitmap();
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
Esempio n. 19
0
        //Source: SokolowLineProfile13
        public void Turtle()
        {
            Bitmap bmp = new Bitmap(pictureBox1.Image);

            int[,] rtab = new int[bmp.Width, bmp.Height];
            int[,] gtab = new int[bmp.Width, bmp.Height];
            int[,] btab = new int[bmp.Width, bmp.Height];

            int i, j;

            for (i = 1; i < bmp.Width - 1; i++)
            {
                for (j = 1; j < bmp.Height - 1; j++)
                {
                    rtab[i, j] = bmp.GetPixel(i, j).R;
                    gtab[i, j] = bmp.GetPixel(i, j).G;
                    btab[i, j] = bmp.GetPixel(i, j).B;
                }
            }
            int d = 0;
            int pami = 0, pamj = 0, ja = 0, ia = 0;
            int x, y;

            int[] wynik = new int[bmp.Width * bmp.Height];
            int[] droga = new int[bmp.Width * bmp.Height];
            for (i = 1; i < bmp.Height - 1; i++)
            {
                for (j = 1; j < bmp.Width - 1; j++)
                {
                    if (rtab[j, i] != 0 || gtab[j, i] != 0 || btab[j, i] != 0)
                    {
                        ja   = j;
                        ia   = i;
                        pamj = j;
                        pami = i;
                        wynik[bmp.Width * i + j] = maxBmpLevel - 1;
                        goto cont;
                    }
                }
            }
cont:
            j = pamj;
            i = pami - 1;
            wynik[bmp.Width * i + j] = maxBmpLevel - 1;
            droga[d] = 1;
            do
            {
                x    = j - pamj;
                y    = i - pami;
                pamj = j;
                pami = i;
                d++;
                if (rtab[j, i] != 0 || gtab[j, i] != 0 || btab[j, i] != 0)
                {
                    if (x == 0 && y == (-1))
                    {
                        j--;
                        droga[d] = 2;
                    }
                    if (x == 1 && y == 0)
                    {
                        i--;
                        droga[d] = 1;
                    }
                    if (x == 0 && y == 1)
                    {
                        j++;
                        droga[d] = 0;
                    }
                    if (x == (-1) && y == 0)
                    {
                        i++;
                        droga[d] = 3;
                    }
                }
                else
                {
                    if (x == 0 && y == (-1))
                    {
                        j++;
                        droga[d] = 0;
                    }
                    if (x == 1 && y == 0)
                    {
                        i++;
                        droga[d] = 3;
                    }
                    if (x == 0 && y == 1)
                    {
                        j--;
                        droga[d] = 2;
                    }
                    if (x == (-1) && y == 0)
                    {
                        i--;
                        droga[d] = 1;
                    }
                }
                wynik[bmp.Width * i + j] = maxBmpLevel - 1;
            }while (j != ja || i != ia);
            for (i = 0; i < bmp.Height; i++)
            {
                for (j = 0; j < bmp.Width; j++)
                {
                    if (wynik[bmp.Width * i + j] == maxBmpLevel - 1)
                    {
                        rtab[j, i] = maxBmpLevel / 2;
                        gtab[j, i] = 0;
                        btab[j, i] = 0;
                    }
                }
            }

            for (i = 0; i < bmp.Width; i++)
            {
                for (j = 0; j < bmp.Height; j++)
                {
                    bmp.SetPixel(i, j, Color.FromArgb(rtab[i, j], gtab[i, j], btab[i, j]));
                }
            }

            pictureBox1.Image = bmp;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }
        private void previewButton_Click(object sender, EventArgs e)
        {
            Bitmap bm            = new Bitmap(imageWindow.getImage());
            Bitmap resultbBitmap = new Bitmap(imageWindow.getImage().Width, imageWindow.getImage().Height);
            Color  c;
            int    color;

            for (int x = 1; x < bm.Width - 1; x++)
            {
                for (int y = 1; y < bm.Height - 1; y++)
                {
                    switch (masksComboBox.SelectedIndex)
                    {
                    case 0:
                        int gx = Math.Abs(bm.GetPixel(x, y).R - bm.GetPixel(x + 1, y + 1).R);
                        int gy = Math.Abs(bm.GetPixel(x + 1, y).R - bm.GetPixel(x, y + 1).R);
                        color = scaleColor(gx + gy);
                        c     = Color.FromArgb(color, color, color);
                        resultbBitmap.SetPixel(x, y, c);
                        break;

                    case 1:
                        int sx = (bm.GetPixel(x - 1, y - 1).R + 2 * bm.GetPixel(x, y - 1).R + bm.GetPixel(x + 1, y - 1).R) -
                                 (bm.GetPixel(x - 1, y + 1).R + 2 * bm.GetPixel(x, y + 1).R + bm.GetPixel(x + 1, y + 1).R);
                        int sy = (bm.GetPixel(x + 1, y - 1).R + 2 * bm.GetPixel(x + 1, y).R + bm.GetPixel(x + 1, y + 1).R) -
                                 (bm.GetPixel(x - 1, y - 1).R + 2 * bm.GetPixel(x - 1, y).R + bm.GetPixel(x - 1, y + 1).R);
                        color = scaleColor(Convert.ToInt32(Math.Sqrt(Math.Pow(sx, 2) + Math.Pow(sy, 2))));
                        c     = Color.FromArgb(color, color, color);
                        resultbBitmap.SetPixel(x, y, c);
                        break;

                    case 2:
                        if (directionComboBox.SelectedIndex == 0)
                        {
                            int avgN =
                                NPrewitt[0, 0] * bm.GetPixel(x - 1, y - 1).R +
                                NPrewitt[0, 1] * bm.GetPixel(x - 1, y).R +
                                NPrewitt[0, 2] * bm.GetPixel(x - 1, y + 1).R +
                                NPrewitt[1, 0] * bm.GetPixel(x, y - 1).R +
                                NPrewitt[1, 1] * bm.GetPixel(x, y).R +
                                NPrewitt[1, 2] * bm.GetPixel(x, y + 1).R +
                                NPrewitt[2, 0] * bm.GetPixel(x + 1, y - 1).R +
                                NPrewitt[2, 1] * bm.GetPixel(x + 1, y).R +
                                NPrewitt[2, 2] * bm.GetPixel(x + 1, y + 1).R;
                            color = scaleColor(avgN);
                            c     = Color.FromArgb(color, color, color);
                            resultbBitmap.SetPixel(x, y, c);
                        }
                        else if (directionComboBox.SelectedIndex == 1)
                        {
                            int avgN =
                                SPrewitt[0, 0] * bm.GetPixel(x - 1, y - 1).R +
                                SPrewitt[0, 1] * bm.GetPixel(x - 1, y).R +
                                SPrewitt[0, 2] * bm.GetPixel(x - 1, y + 1).R +
                                SPrewitt[1, 0] * bm.GetPixel(x, y - 1).R +
                                SPrewitt[1, 1] * bm.GetPixel(x, y).R +
                                SPrewitt[1, 2] * bm.GetPixel(x, y + 1).R +
                                SPrewitt[2, 0] * bm.GetPixel(x + 1, y - 1).R +
                                SPrewitt[2, 1] * bm.GetPixel(x + 1, y).R +
                                SPrewitt[2, 2] * bm.GetPixel(x + 1, y + 1).R;
                            color = scaleColor(avgN);
                            c     = Color.FromArgb(color, color, color);
                            resultbBitmap.SetPixel(x, y, c);
                        }
                        break;

                    case 3:
                        if (directionComboBox.SelectedIndex == 0)
                        {
                            int avgN =
                                NKirsch[0, 0] * bm.GetPixel(x - 1, y - 1).R +
                                NKirsch[0, 1] * bm.GetPixel(x - 1, y).R +
                                NKirsch[0, 2] * bm.GetPixel(x - 1, y + 1).R +
                                NKirsch[1, 0] * bm.GetPixel(x, y - 1).R +
                                NKirsch[1, 1] * bm.GetPixel(x, y).R +
                                NKirsch[1, 2] * bm.GetPixel(x, y + 1).R +
                                NKirsch[2, 0] * bm.GetPixel(x + 1, y - 1).R +
                                NKirsch[2, 1] * bm.GetPixel(x + 1, y).R +
                                NKirsch[2, 2] * bm.GetPixel(x + 1, y + 1).R;
                            color = scaleColor(avgN);
                            c     = Color.FromArgb(color, color, color);
                            resultbBitmap.SetPixel(x, y, c);
                        }
                        else if (directionComboBox.SelectedIndex == 1)
                        {
                            int avgN =
                                SKirsch[0, 0] * bm.GetPixel(x - 1, y - 1).R +
                                SKirsch[0, 1] * bm.GetPixel(x - 1, y).R +
                                SKirsch[0, 2] * bm.GetPixel(x - 1, y + 1).R +
                                SKirsch[1, 0] * bm.GetPixel(x, y - 1).R +
                                SKirsch[1, 1] * bm.GetPixel(x, y).R +
                                SKirsch[1, 2] * bm.GetPixel(x, y + 1).R +
                                SKirsch[2, 0] * bm.GetPixel(x + 1, y - 1).R +
                                SKirsch[2, 1] * bm.GetPixel(x + 1, y).R +
                                SKirsch[2, 2] * bm.GetPixel(x + 1, y + 1).R;
                            color = scaleColor(avgN);
                            c     = Color.FromArgb(color, color, color);
                            resultbBitmap.SetPixel(x, y, c);
                        }
                        break;
                    }
                }
            }

            pictureBox1.Image = resultbBitmap;
            HistogramOperations.clearHistogram(chart1);
            HistogramOperations.drawHistogram(chart1, pictureBox1.Image, HistogramOperations.MaxBmpLevel(pictureBox1.Image));
        }
Esempio n. 21
0
        public void neibghMethodHisto()
        {
            int hAvg = 0;
            int R    = 0;
            int Hint = 0;

            int[] left  = new int[maxBmpLevel + 1];
            int[] right = new int[maxBmpLevel + 1];

            for (int i = 0; i < histoTab.Length; i++)
            {
                hAvg += histoTab[i];
            }

            Bitmap bm = new Bitmap(pictureBox1.Image);

            hAvg = hAvg / 256;

            for (int Z = 0; Z < histoTab.Length; Z++)
            {
                left[Z] = R;
                Hint    = Hint + histoTab[Z];
                while (Hint > hAvg)
                {
                    Hint = Hint - hAvg;
                    R++;
                }
                right[Z] = R;
            }

            for (int x = 1; x < bm.Width - 1; x++)
            {
                for (int y = 1; y < bm.Height - 1; y++)
                {
                    Color c = bm.GetPixel(x, y);
                    if (left[c.R] == right[c.R])
                    {
                        Color color = Color.FromArgb(255, left[c.R], left[c.R], left[c.R]);
                        bm.SetPixel(x, y, color);
                    }
                    else
                    {
                        int avgN = (bm.GetPixel(x - 1, y - 1).R + bm.GetPixel(x, y - 1).R + bm.GetPixel(x + 1, y - 1).R +
                                    bm.GetPixel(x - 1, y).R + bm.GetPixel(x, y).R + bm.GetPixel(x + 1, y).R + bm.GetPixel(x - 1, y + 1).R + bm.GetPixel(x, y + 1).R
                                    + bm.GetPixel(x + 1, y + 1).R) / 9;
                        if (avgN > right[c.R])
                        {
                            Color color = Color.FromArgb(255, right[c.R], right[c.R], right[c.R]);
                            bm.SetPixel(x, y, color);
                        }
                        else if (avgN < left[c.R])
                        {
                            Color color = Color.FromArgb(255, left[c.R], left[c.R], left[c.R]);
                            bm.SetPixel(x, y, color);
                        }
                        else
                        {
                            Color color = Color.FromArgb(255, avgN, avgN, avgN);
                            bm.SetPixel(x, y, color);
                        }
                    }
                }
            }

            pictureBox1.Image = bm;
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.clearHistogram(chart1);
            histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
        }