Opening operator from Mathematical Morphology
Inheritance: IFilter
Example #1
1
 private string reconhecerCaptcha(Image img)
 {
     Bitmap imagem = new Bitmap(img);
     imagem = imagem.Clone(new Rectangle(0, 0, img.Width, img.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
     Erosion erosion = new Erosion();
     Dilatation dilatation = new Dilatation();
     Invert inverter = new Invert();
     ColorFiltering cor = new ColorFiltering();
     cor.Blue = new AForge.IntRange(200, 255);
     cor.Red = new AForge.IntRange(200, 255);
     cor.Green = new AForge.IntRange(200, 255);
     Opening open = new Opening();
     BlobsFiltering bc = new BlobsFiltering();
     Closing close = new Closing();
     GaussianSharpen gs = new GaussianSharpen();
     ContrastCorrection cc = new ContrastCorrection();
     bc.MinHeight = 10;
     FiltersSequence seq = new FiltersSequence(gs, inverter, open, inverter, bc, inverter, open, cc, cor, bc, inverter);
     pictureBox.Image = seq.Apply(imagem);
     string reconhecido = OCR((Bitmap)pictureBox.Image);
     return reconhecido;
 }
Example #2
1
        private void cBFilters_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bitmap pictureTransform = (Bitmap)pbChoose.Image;
                if ((string)cBFilters.SelectedItem == "HSL_Filter")
                {
                    AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1);
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Mediana")
                {
                    AForge.Imaging.Filters.Median filter = new Median();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation")
                {
                 Complex[] dst = new Complex[n];

                    AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform);
                    Bitmap newImage = filter.Apply();
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }*/

                if ((string)cBFilters.SelectedItem == "Binarization")
                {
                    pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                    Threshold threshold = new Threshold(127);
                    threshold.ApplyInPlace(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = pictureTransform;
                }

                if ((string)cBFilters.SelectedItem == "Grayscale")
                {
                    AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "FillHoles")
                {

                    pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                    Threshold threshold = new Threshold(127);
                    threshold.ApplyInPlace(pictureTransform);
                    AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles();
                    filter.MaxHoleHeight = 5;
                    filter.MaxHoleWidth = 15;
                    filter.CoupledSizeFiltering = false;
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Opening")
                {
                    AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Closing")
                {
                    AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Erosion")
                {
                    AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Dilatation")
                {
                    AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Edges")
                {
                    AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }
        }
        internal FrameWrapper compute(Method method, Bitmap frame)
        {
            Bitmap differenceFrame = getDifference(method, frame);

            lastButOneFrame = lastFrame;
            lastFrame = frame;

            // if we cannot compute diffference yet, we return empty list of areas
            if (differenceFrame == null)
            {
                return new FrameWrapper(frame, new List<Rectangle>());
            }

            Bitmap grayscaledFrame = transformToGrayscale(differenceFrame);
            Bitmap thresholdedFrame = getThresholdedFrame(grayscaledFrame);

            if (mainWindow.UseOpeningFilter)
            {
                //Console.WriteLine("openning openingFilter used");
                Opening openingFilter = new Opening();
                thresholdedFrame = openingFilter.Apply(thresholdedFrame);
            }

            List<Rectangle> areas = getAreas(thresholdedFrame);
            List<Rectangle> movingObjects = mergeAreas(areas);

            Bitmap outputFrame = null;

            switch (mainWindow.OutputFrameType)
            {
                case Output.Source:
                    if (method == Method.ThreeFrame)
                    {
                        outputFrame = lastFrame;
                    }
                    else
                    {
                        outputFrame = frame;
                    }
                    break;
                case Output.Differenced:
                    outputFrame = differenceFrame;
                    break;
                case Output.Greyscaled:
                    outputFrame = grayscaledFrame;
                    break;
                case Output.Thresholded:
                    outputFrame = thresholdedFrame;
                    break;
            }

            return new FrameWrapper(outputFrame, movingObjects);
        }
Example #4
0
        /// <summary>
        /// Celem metody jest przykadrowanie otrzymanego obrazka, tak aby widok zawierał jedynie kartkę papieru, oraz zwrócenie go do metody UploadFile
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public System.Drawing.Image CropImage(System.Drawing.Image img)
        {
            //DocumentSkewChecker skewChecker = new DocumentSkewChecker();
            //double angle = skewChecker.GetSkewAngle(image);
            //RotateBilinear rotationFilter = new RotateBilinear(-angle);
            //rotationFilter.FillColor = Color.White;
            //Bitmap rotatedImage = rotationFilter.Apply(image);

            Bitmap image = new Bitmap(img);

            UnmanagedImage grayImage = null;

            if (image.PixelFormat == PixelFormat.Format8bppIndexed)
            {
                grayImage = UnmanagedImage.FromManagedImage(image);
            }
            else
            {
                grayImage = UnmanagedImage.Create(image.Width, image.Height,
                    PixelFormat.Format8bppIndexed);
                Grayscale.CommonAlgorithms.BT709.Apply(UnmanagedImage.FromManagedImage(image), grayImage);
            }

            CannyEdgeDetector edgeDetector = new CannyEdgeDetector();
            UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);

            OtsuThreshold thresholdFilter = new OtsuThreshold();
            thresholdFilter.ApplyInPlace(edgesImage);

            Dilatation DilatationFilter = new Dilatation();
            DilatationFilter.Apply(edgesImage);

            Opening OpeningFilter = new Opening();
            OpeningFilter.Apply(edgesImage);

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinHeight = 32;
            blobCounter.MinWidth = 32;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;

            blobCounter.ProcessImage(edgesImage);
            Blob[] blobs = blobCounter.GetObjectsInformation();

            ExtractBiggestBlob BiggestBlob = new ExtractBiggestBlob();
            Bitmap biggestBlobsImage = BiggestBlob.Apply(edgesImage.ToManagedImage());
            AForge.IntPoint BiggestBlogCorners = BiggestBlob.BlobPosition;

            Crop cropFilter = new Crop(new Rectangle(BiggestBlogCorners.X, BiggestBlogCorners.Y, biggestBlobsImage.Width, biggestBlobsImage.Height));
            Bitmap croppedImage = cropFilter.Apply(image);
            return croppedImage;
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopHat"/> class.
 /// </summary>
 /// 
 /// <param name="se">Structuring element to pass to <see cref="Opening"/> operator.</param>
 /// 
 public TopHat( short[,] se ) : this( )
 {
     opening = new Opening( se );
 }
Example #6
0
 public TopHat(short[,] se)
     : this()
 {
     opening = new Opening(se);
 }
Example #7
0
        private void cBFilters_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bitmap pictureTransform = (Bitmap)pbChoose.Image;

            if ((string)cBFilters.SelectedItem == "HSL_Filter")
            {
                AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1);
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Mediana")
            {
                AForge.Imaging.Filters.Median filter = new Median();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation")
             * {
             * Complex[] dst = new Complex[n];
             *
             *  AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform);
             *  Bitmap newImage = filter.Apply();
             *  pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
             *  pBNew.Image = newImage;
             * }*/

            if ((string)cBFilters.SelectedItem == "Binarization")
            {
                pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                Threshold threshold = new Threshold(127);
                threshold.ApplyInPlace(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = pictureTransform;
            }

            if ((string)cBFilters.SelectedItem == "Grayscale")
            {
                AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "FillHoles")
            {
                pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                Threshold threshold = new Threshold(127);
                threshold.ApplyInPlace(pictureTransform);
                AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles();
                filter.MaxHoleHeight        = 5;
                filter.MaxHoleWidth         = 15;
                filter.CoupledSizeFiltering = false;
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Opening")
            {
                AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Closing")
            {
                AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Erosion")
            {
                AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Dilatation")
            {
                AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }

            if ((string)cBFilters.SelectedItem == "Edges")
            {
                AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges();
                Bitmap newImage = filter.Apply(pictureTransform);
                pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                pBNew.Image       = newImage;
            }
        }
Example #8
0
        private void InitFilters()
        {
            L_brownFilter = new ColorFiltering();
            D_brownFilter = new ColorFiltering();

            L_brownFilter.Red = new IntRange(125, 140);
            L_brownFilter.Green = new IntRange(95, 110);
            L_brownFilter.Blue = new IntRange(110, 130);

            D_brownFilter.Red = new IntRange(55, 85);
            D_brownFilter.Green = new IntRange(45, 75);
            D_brownFilter.Blue = new IntRange(45, 75);

            blobFilter = new BlobsFiltering();
            blobFilter.CoupledSizeFiltering = true;
            blobFilter.MinWidth = 70;
            blobFilter.MinHeight = 70;

            diffFilter = new Difference();
            diffFilter.OverlayImage = back;

            thresholdFilter = new Threshold(40);

            erosionFilter = new Erosion();

            edgeFilter = new Edges();

            openFilter = new Opening();

            pixelFilter = new Pixellate();

            morphFilter = new Morph();
            morphFilter.SourcePercent = 0.9;

            towardsFilter = new MoveTowards();
            towardsFilter.StepSize = 10;

            blobCounter = new BlobCounter();
            blobGrabber = new ExtractBiggestBlob();
        }
Example #9
0
        // opening
        private void button56_Click(object sender, EventArgs e)
        {
            ///////////// ini 객체 생성 시작 /////////////////////////////////////////////////////
            //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe
            FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe");
            string pathini = exefileinfo.Directory.FullName.ToString();  //프로그램 실행되고 있는데 path 가져오기
            string fileName = @"\PLOCRconfig.ini";  // 환경설정 파일명
            string filePath = pathini + fileName;   //ini 파일 경로
            DocumentAnalysis.IniUtil ini = new DocumentAnalysis.IniUtil(filePath);   // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌)
            //////////// ini 객체 생성 끝 /////////////////////////////////////////////////////////

            Bitmap source = Global.source;
            Bitmap tmp = source;
            // convert to 24 bits per pixel
            source = imageProcess.Clone(tmp, PixelFormat.Format24bppRgb);
            // delete old image
            tmp.Dispose();

            // create filter
            Opening filter = new Opening();
            // apply the filter
            filter.Apply(source);

            Global.source = source;
            pictureBox1.Image = Global.source;
            pictureBox1.Refresh();

            textBox27.Text = (int.Parse(textBox24.Text) + 1).ToString();
            ini.SetIniValue("opening", "opening횟수", textBox27.Text.ToString());
        }