Example #1
0
        private void Erosion8(object sender, EventArgs e)
        {
            basicImageOpertions.ToGreyScale();
            KernelOpperations kernelOpperations = new KernelOpperations((Bitmap)this.pctbImage.Image);

            SetImageAndHist(kernelOpperations.Erosion(0, 1, 8));
        }
Example #2
0
        private void Dialation4_Click(object sender, EventArgs e)
        {
            basicImageOpertions.ToGreyScale();
            KernelOpperations kernelOpperations = new KernelOpperations((Bitmap)this.pctbImage.Image);

            SetImageAndHist(kernelOpperations.Dilatation(0, 1, 4));
        }
Example #3
0
        private void PerformBlur()
        {
            kernel = new KernelOpperations((Bitmap)this.pctbInput.Image);

            if (chbIgnore.Checked == true)
            {
                outlierMethod = 1;
            }

            if (chbRehash.Checked == true)
            {
                outlierMethod = 0;
            }

            if (chbUseExisting.Checked == true)
            {
                outlierMethod = 0;
            }

            output = kernel.MedianFilter((int)this.nudNumOfRows.Value, (int)this.nudNumOfColumns.Value, outlierMethod);

            pctbOutput.Image = output;
            panelOutput.Refresh();
            pctbOutput.Refresh();
        }
        private void PerformOpperation()
        {
            kernel = new KernelOpperations(orignal);

            int[,] mask = new int[3, 3] {
                { (int)nud1.Value, (int)nud2.Value, (int)nud3.Value },
                { (int)nud4.Value, (int)nud5.Value, (int)nud6.Value },
                { (int)nud7.Value, (int)nud8.Value, (int)nud9.Value }
            };

            divisor = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    divisor += mask[i, j];
                }
            }

            nudDivisor.Value = divisor;

            if (chbIgnore.Checked == true)
            {
                outlierMethod = 1;
            }

            if (chbRehash.Checked == true)
            {
                outlierMethod = 0;
            }

            if (chbUseExisting.Checked == true)
            {
                outlierMethod = 0;
            }

            if (chbProportional.Checked == true)
            {
                type = 1;
            }

            if (chbTriValue.Checked == true)
            {
                type = 2;
            }

            if (chbCutDown.Checked == true)
            {
                type = 3;
            }

            output = kernel.LinearFilter(mask, type, outlierMethod);

            pctbOutput.Image = output;
            panelOutput.Refresh();
            pctbOutput.Refresh();
        }
        private void cmbAngle_SelectedIndexChanged(object sender, EventArgs e)
        {
            KernelOpperations = new KernelOpperations((Bitmap)pctbInput.Image.Clone());

            int angle = Int32.Parse(cmbAngle.SelectedItem.ToString());

            output = KernelOpperations.LogicalFilter(angle);

            this.pctbOutput.Image = output;
        }
Example #6
0
        private void Opening4(object sender, EventArgs e)
        {
            basicImageOpertions.ToGreyScale();
            KernelOpperations kernelOpperations = new KernelOpperations((Bitmap)this.pctbImage.Image);

            this.pctbImage.Image = kernelOpperations.Dilatation(0, 1, 4);

            kernelOpperations = new KernelOpperations((Bitmap)this.pctbImage.Image);

            this.pctbImage.Image = kernelOpperations.Erosion(0, 1, 4);
            SetImageAndHist((Bitmap)this.pctbImage.Image);
        }
Example #7
0
 private void szkieletyzacjaToolStripMenuItem_Click(object sender, EventArgs e)
 {
     bool[][] t = KernelOpperations.Image2Bool(pctbImage.Image);
     t = KernelOpperations.ZhangSuenThinning(t);
     SetImageAndHist((Bitmap)KernelOpperations.Bool2Image(t));
 }
        public Bitmap MedianFilter(int m, int n, int outlierMethod)
        {
            int indexM = m - m / 2 - 1;
            int indexN = n - n / 2 - 1;

            Point[,] temp = new Point[m, n];

            for (int i = -indexM; i <= indexM; i++)
            {
                for (int j = -indexN; j <= indexN; j++)
                {
                    temp[i + indexM, j + indexN] = new Point(i, j);
                }
            }

            byte[] pixels = new byte[m * n];

            if (outlierMethod == 0)
            {
                indexM = 0;
                indexN = 0;
            }

            try
            {
                this.bitmapData          = BasicImageOpertions.BitmapToBitmapData(bmp);
                this.secondaryBitmapData = BasicImageOpertions.BitmapToBitmapData(SecondaryBitmap);

                unsafe                                                                // C# doesn't support pointer arithmetic
                {
                    byte *PtrFirstPixelFirst     = (byte *)bitmapData.Scan0;          // Point to first pixel of first image
                    byte *PtrFirstPixelSecondary = (byte *)secondaryBitmapData.Scan0; // Point to first pixel of helper image

                    for (int y = indexN; y < heightInPixels - indexN; y++)
                    {
                        byte *currentLineOld = PtrFirstPixelFirst + (y * bitmapData.Stride);
                        byte *currentLineNew = PtrFirstPixelSecondary + (y * secondaryBitmapData.Stride);

                        for (int x = indexM * bytesPerPixel; x < widthInBytes - indexM * bytesPerPixel; x += bytesPerPixel)
                        {
                            int p = 0;

                            for (int k = 0; k < m; k++)
                            {
                                for (int l = 0; l < n; l++)
                                {
                                    if (x + temp[k, l].X * bytesPerPixel >= 0 && x + temp[k, l].X * bytesPerPixel < widthInBytes && y + temp[k, l].Y >= 0 && y + temp[k, l].Y < heightInPixels)
                                    {
                                        byte *col = (byte *)(PtrFirstPixelFirst + ((y + temp[k, l].Y) * bitmapData.Stride) + x + temp[k, l].X * bytesPerPixel);
                                        pixels[p] = *col;
                                        ++p;
                                    }
                                }
                            }

                            Array.Sort(pixels);

                            byte finalColor = KernelOpperations.GetMedian(pixels);

                            currentLineNew[x]     = (byte)finalColor;
                            currentLineNew[x + 1] = (byte)finalColor;
                            currentLineNew[x + 2] = (byte)finalColor;
                        }
                    }
                }
                bmp.UnlockBits(bitmapData);
                SecondaryBitmap.UnlockBits(secondaryBitmapData);
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Please select image first", "Error");
            }
            return(SecondaryBitmap);
        }
Example #9
0
        private void PerformOpperation()
        {
            this.pctbInput.Image = orignal;
            kernel = new KernelOpperations((Bitmap)this.pctbInput.Image);
            //FillFiveByFiveMask();
            FillMatrix();


            if (chbIgnore.Checked == true)
            {
                outlierMethod = 1;
            }

            if (chbRehash.Checked == true)
            {
                outlierMethod = 0;
            }

            if (chbUseExisting.Checked == true)
            {
                outlierMethod = 0;
            }

            if (chbProportional.Checked == true)
            {
                type = 1;
            }

            if (chbTriValue.Checked == true)
            {
                type = 2;
            }

            if (chbCutDown.Checked == true)
            {
                type = 3;
            }

            //int divisor5x5 = 0;

            //int divisor3x3_1 = 0;
            //int divisor3x3_2 = 0;

            //for (int i = 0; i < 5; i++)
            //    for (int j = 0; j < 5; j++)
            //        divisor5x5 += twoOpMask[i, j];

            //for (int i = 0; i < 3; i++)
            //{
            //    for (int j = 0; j < 3; j++)
            //    {
            //        divisor3x3_1 += maskHor[i, j];
            //        divisor3x3_2 += maskVer[i, j];
            //    }
            //}

            if (chbTwoMasks.Checked == true)
            {
                output = kernel.TwoMaskFilter(maskHor, maskVer, type, outlierMethod);

                //Bitmap output1 = kernel.LinearFilter(maskHor, type, outlierMethod);
                //kernel = new KernelOpperations(output1);
                //output = kernel.LinearFilter(maskVer, type, outlierMethod);
            }
            else if (chbOneMask.Checked == true)
            {
                output = kernel.LinearFilter(twoOpMask, type, outlierMethod);
            }



            pctbOutput.Image = output;
            panelOutput.Refresh();
            pctbOutput.Refresh();
        }