示例#1
0
 public Niblack(Form1 form)
 {
     InitializeComponent();
     mainForm = form;
     picture  = (Bitmap)mainForm.Picture.Clone();
     binary   = new BinarizationComponent(mainForm);
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int threshold = int.Parse(int32TextBox1.Text);

            if (threshold > 255 || threshold < 0)
            {
                MessageBox.Show("Zła wartość progu. Prawidłowa jest pomedzy 0 a 255");
            }
            else
            {
                mainForm.savedBitmap.Push((Bitmap)mainForm.Picture.Clone());
                if (mainForm.savedBitmap.Count() >= 0)
                {
                    mainForm.button1.Enabled = true;
                }
                BinarizationComponent binary = new BinarizationComponent(mainForm);
                binary.ManualThreshold(new Bitmap(picture), threshold);
                this.Close();
            }
        }
示例#3
0
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            BinarizationComponent binary = new BinarizationComponent(mainForm);

            binary.PercentOfBlackThreshold(new Bitmap(picture), trackBar1.Value * 2);
        }
示例#4
0
        public void ZhangSuenAlgorithm(Bitmap image)
        {
            Zad7.BinarizationComponent binarize = new Zad7.BinarizationComponent(mainForm);
            originalImage = new Bitmap(binarize.TransformOtsu(new Bitmap(image)));
            width         = originalImage.Width;
            height        = originalImage.Height;
            filteredImage = new Bitmap(image);
            CustomBitmapProcessing data    = new CustomBitmapProcessing(originalImage);
            CustomBitmapProcessing dataOut = new CustomBitmapProcessing(filteredImage);

            data.LockBits();
            dataOut.LockBits();

            imageM = new int[height, width];

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int col = (data.GetPixel(i, j) & 0xFF);
                    imageM[i, j] = BinaryValidator(col);
                }
            }
            while (true)
            {
                int[,] start = new int[height, width];

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        start[i, j] = imageM[i, j];
                    }
                }
                thiningIteration(0);
                thiningIteration(1);
                bool same = true;
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        if (start[i, j] != imageM[i, j])
                        {
                            same = false;
                            goto MainforLoop;
                        }
                    }
                }
MainforLoop:
                if (same)
                {
                    break;
                }
            }
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int col;
                    col = BinaryValidator2(imageM[i, j]);
                    int rgb = col + (col << 8) + (col << 16);
                    dataOut.SetPixel(i, j, rgb);
                }
            }
            data.UnlockBits();
            dataOut.UnlockBits();
            mainForm.Picture           = (Bitmap)filteredImage.Clone();
            mainForm.pictureBox1.Image = (Bitmap)filteredImage.Clone();
        }