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]);
        }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 public MorphologicalWindow(ImageWindow imageWindow)
 {
     InitializeComponent();
     this.imageWindow  = imageWindow;
     pictureBox1.Image = (Image)imageWindow.getImage().Clone();
     acttualImage      = new Image <Gray, byte>((Bitmap)pictureBox1.Image);
     maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);
     bitmapCopy = (Bitmap)imageWindow.getImage().Clone();
 }
Exemplo n.º 4
0
        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;
        }
        public GradientWindow(ImageWindow imageWindow)
        {
            InitializeComponent();
            this.imageWindow  = imageWindow;
            pictureBox1.Image = (Image)imageWindow.getImage().Clone();
            maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            minBMPLevel       = HistogramOperations.MinBmpLevel(pictureBox1.Image);
            HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);

            masksComboBox.Items.Add("Maska Robertsa");
            masksComboBox.Items.Add("Maska Sobela");
            masksComboBox.Items.Add("Maski Prewitta");
            masksComboBox.Items.Add("Maski Kirscha");
            masksComboBox.SelectedIndex = 0;

            scalingMethodsComboBox.Items.Add("Metoda Proporcjonalna");
            scalingMethodsComboBox.Items.Add("Metoda Trójwartościowa");
            scalingMethodsComboBox.Items.Add("Metoda Obcinająca");
            scalingMethodsComboBox.SelectedIndex = 0;

            directionComboBox.Items.Add("N");
            directionComboBox.Items.Add("S");

            directionComboBox.Visible = false;
            directionLabel.Visible    = false;
        }
Exemplo n.º 6
0
        private void uopCalc()
        {
            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 = uopChart.Series["Series1"].Points;
                    for (int i = 0; i < points.Count - 1; ++i)
                    {
                        if (c.R >= points[i].XValue && c.R <= points[i + 1].XValue)
                        {
                            double a = (points[i + 1].YValues[0] - points[i].YValues[0]) / (points[i + 1].XValue - points[i].XValue);
                            double b = points[i].YValues[0] - (a * points[i].XValue);

                            int   q     = Convert.ToInt32((a * c.R) + b);
                            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);
        }
Exemplo n.º 7
0
 public LogicalWindow(ImageWindow imageWindow)
 {
     InitializeComponent();
     this.imageWindow  = imageWindow;
     pictureBox1.Image = (Image)imageWindow.getImage().Clone();
     maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);
 }
Exemplo n.º 8
0
 public StretchWindow(ImageWindow imageWindowRef)
 {
     InitializeComponent();
     imageWindow             = imageWindowRef;
     pictureBox1.Image       = (Image)imageWindowRef.getImage().Clone();
     maxBmpLevel             = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
     histoTab                = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);
     bottomValueTextBox.Text = bottomTrackBar.Value.ToString();
     upperValueTextBox.Text  = upperTrackBar.Value.ToString();
 }
Exemplo n.º 9
0
        public UOPWindow(ImageWindow imageWindow)
        {
            InitializeComponent();
            this.imageWindow = imageWindow;
            pictureBox.Image = (Image)imageWindow.getImage().Clone();
            maxBmpLevel      = HistogramOperations.MaxBmpLevel(pictureBox.Image);
            histoTab         = HistogramOperations.drawHistogram(chart1, pictureBox.Image, maxBmpLevel);

            initializeUopChart();
            uopCalc();
        }
Exemplo n.º 10
0
        public MedianWindow(ImageWindow imageWindow)
        {
            InitializeComponent();
            this.imageWindow = imageWindow;

            firstDomainUpDown.SelectedIndex  = 2;
            secondDomainUpDown.SelectedIndex = 2;

            pictureBox1.Image = (Image)imageWindow.getImage().Clone();
            maxBMPLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBMPLevel);
        }
Exemplo n.º 11
0
        private void calcMedian()
        {
            Bitmap bm           = new Bitmap(imageWindow.getImage());
            Bitmap resultBitmap = new Bitmap(bm.Width, bm.Height);

            int width  = Convert.ToInt32(firstDomainUpDown.SelectedItem);
            int height = Convert.ToInt32(secondDomainUpDown.SelectedItem);

            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    int   i = 0;
                    int[] medianArrayInts = new int[height * width];
                    for (int x1 = -width / 2; x1 <= width / 2; x1++)
                    {
                        for (int y1 = -height / 2; y1 <= height / 2; y1++)
                        {
                            if (x + x1 >= 0 && y + y1 >= 0 && x + x1 < bm.Width && y + y1 < bm.Height)
                            {
                                medianArrayInts[i++] = bm.GetPixel(x + x1, y + y1).R;
                            }
                        }
                    }
                    Array.Sort(medianArrayInts, 0, i);
                    if (i % 2 == 1)
                    {
                        resultBitmap.SetPixel(x, y, Color.FromArgb(medianArrayInts[i / 2], medianArrayInts[i / 2], medianArrayInts[i / 2]));
                    }
                    else
                    {
                        int val = (medianArrayInts[i / 2] + medianArrayInts[i / 2 + 1]) / 2;
                        resultBitmap.SetPixel(x, y, Color.FromArgb(val, val, val));
                    }
                }
            }
            currentImage = resultBitmap;
        }
        public TresholdingWindow(ImageWindow imageWindow)
        {
            InitializeComponent();
            this.imageWindow  = imageWindow;
            pictureBox1.Image = (Image)imageWindow.getImage().Clone();
            maxBmpLevel       = HistogramOperations.MaxBmpLevel(pictureBox1.Image);
            histoTab          = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel);

            //TrackBars and labels init
            bottomValueTrackBar.Maximum = maxBmpLevel;
            upperValueTrackBar.Maximum  = maxBmpLevel;
            bottomValueLabel.Text       = "0";
            upperValueLabel.Text        = maxBmpLevel.ToString();
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public GrayscaleReductionWindow(ImageWindow imageWindow)
        {
            InitializeComponent();
            this.imageWindow = imageWindow;
            pictureBox.Image = (Image)imageWindow.getImage().Clone();
            maxBmpLevel      = HistogramOperations.MaxBmpLevel(pictureBox.Image);
            histoTab         = HistogramOperations.drawHistogram(chart1, pictureBox.Image, maxBmpLevel);
            initializeReductionChart(2);

            for (int i = 29; i > 1; --i)
            {
                domainUpDown1.Items.Add(i);
            }

            domainUpDown1.SelectedIndex = 27;

            chartDrawing.ChartAreas[0].AxisX.Maximum = maxBmpLevel;
            chartDrawing.ChartAreas[0].AxisX.Minimum = 0;

            chartDrawing.ChartAreas[0].AxisY.Maximum = maxBmpLevel;
            chartDrawing.ChartAreas[0].AxisY.Minimum = 0;
        }
        private void operatioCalc()
        {
            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++)
                {
                    int avgN = (Convert.ToInt32(numericUpDown1.Value) * bm.GetPixel(x - 1, y - 1).R + Convert.ToInt32(numericUpDown2.Value) * bm.GetPixel(x - 1, y).R +
                                Convert.ToInt32(numericUpDown3.Value) * bm.GetPixel(x - 1, y + 1).R + Convert.ToInt32(numericUpDown4.Value) * bm.GetPixel(x, y - 1).R +
                                Convert.ToInt32(numericUpDown5.Value) * bm.GetPixel(x, y).R + Convert.ToInt32(numericUpDown6.Value) * bm.GetPixel(x, y + 1).R +
                                Convert.ToInt32(numericUpDown7.Value) * bm.GetPixel(x + 1, y - 1).R + Convert.ToInt32(numericUpDown8.Value) * bm.GetPixel(x + 1, y).R +
                                Convert.ToInt32(numericUpDown9.Value) * bm.GetPixel(x + 1, y + 1).R) / k;
                    if (k == 1)
                    {
                        switch (scalingMethodsComboBox.SelectedIndex)
                        {
                        case 0:
                            avgN = ((avgN - minBMPValue) / (maxBMPValue - minBMPValue)) * 255;
                            //TODO Jak to ma w koncu dzialac
                            //avgN=(int)((((double)avgN - (double)0) / ((double)255 - (double)0)) * 255);
                            if (avgN > 255)
                            {
                                avgN = 255;
                            }
                            else if (avgN < 0)
                            {
                                avgN = 0;
                            }
                            break;

                        case 1:
                            if (avgN > 0)
                            {
                                avgN = 255;
                            }
                            else if (avgN < 0)
                            {
                                avgN = 0;
                            }
                            else
                            {
                                avgN = 255 / 2;
                            }
                            break;

                        case 2:
                            if (avgN < 0)
                            {
                                avgN = 0;
                            }
                            else if (avgN > 255)
                            {
                                avgN = 255;
                            }
                            break;
                        }
                    }

                    try
                    {
                        resultbBitmap.SetPixel(x, y, Color.FromArgb(avgN, avgN, avgN));
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Niepoprawna maska!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }

            currentImage = resultbBitmap;
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
 public CompressWindow(ImageWindow imageWindow)
 {
     InitializeComponent();
     imageClone = (Image)imageWindow.getImage().Clone();
 }