Example #1
0
        private void videoNewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap               bitmap           = (Bitmap)eventArgs.Frame.Clone();
            Threshold            thresholdFilter  = new Threshold(120);
            Grayscale            grayscaleFilter  = new Grayscale(0.2, 0.7, 0.07);
            BrightnessCorrection brightnessFilter = new BrightnessCorrection(brightnessVal);
            ContrastCorrection   contrastFilter   = new ContrastCorrection(contrastVal);
            SaturationCorrection saturationFilter = new SaturationCorrection(saturationVal);

            bitmap = brightnessFilter.Apply((Bitmap)bitmap.Clone());
            bitmap = contrastFilter.Apply((Bitmap)bitmap.Clone());
            bitmap = saturationFilter.Apply((Bitmap)bitmap.Clone());

            if (isGray)
            {
                bitmap = grayscaleFilter.Apply((Bitmap)bitmap.Clone());
            }
            if (isBW)
            {
                bitmap = grayscaleFilter.Apply((Bitmap)bitmap.Clone());
                bitmap = thresholdFilter.Apply(bitmap);
            }

            currentFrame = (Bitmap)bitmap.Clone();
            if (fileWriter != null)
            {
                fileWriter.WriteVideoFrame((Bitmap)bitmap.Clone());
            }
        }
        private void btnOperation(object sender, RoutedEventArgs e)
        {
            var master = sender as System.Windows.Controls.Button;

            switch (master.Name)
            {
            case ("btnThreshold"):
                var parmTh = (int)nudThreshold.Value;
                SrcMImg = SrcMImg.Add(Threshold.Apply(parmTh), StrThreshold.With(parmTh));
                break;

            case ("btnAdpThreshold"):
                var parmAdTh = (int)nudAdpThreshold.Value;
                SrcMImg = SrcMImg.Add(AdpTHreshold.Apply(parmAdTh), StrAdpTHreashold.With(parmAdTh));
                break;

            case ("btnMedian"):
                var parmMdn = (int)nudMedian.Value;
                SrcMImg = SrcMImg.Add(Median.Apply(parmMdn), StrMedian.With(parmMdn));
                break;

            case ("btnNormalize"):
                var parmNorm = (int)nudNormalize.Value;
                SrcMImg = SrcMImg.Add(Normalize.Apply(parmNorm), StrNormalize.With(parmNorm));
                break;
            }
            imgBack.Source        = ToBitmapSource(SrcMImg.GetLastValue());
            txbLog.Selection.Text = SrcMImg.GetLastPaper().Paper2TextHistory();
            var temp = SrcMImg.GetLastPaper().Paper2TextHistory();
        }
        private void blackAndWhiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Threshold thresholdObj = new Threshold();

            blackNwhiteImage  = thresholdObj.Apply(grayImage);
            pictureBox4.Image = blackNwhiteImage;
        }
Example #4
0
        public string decoder(Bitmap img)
        {
            //灰度
            Grayscale grayscaleFilter = new Grayscale(0.299, 0.587, 0.114);
            Bitmap    bitmapGrayscale = grayscaleFilter.Apply(img);
            //二值化
            Threshold thresholdFilter = new Threshold(128);
            Bitmap    bitmapThreshold = thresholdFilter.Apply(bitmapGrayscale);

            /////统计点数分布

            HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(bitmapThreshold);


            Histogram histogram = his.Gray;

            int[] dato = histogram.Values;

            /////分割验证码字符
            charCut(dato);
            ////////解码
            yuantongdecoder decode     = new yuantongdecoder();
            string          backNumber = decode.Decoder(bitmapThreshold, div);

            return(backNumber);
        }
        public void RunThreshold(int threshold, bool showGrayScale)
        {
            using (Bitmap newBitmap = LoadBitmap())
            {
                Rectangle rect = new Rectangle(0, 0, newBitmap.Width, newBitmap.Height);
                using (UnmanagedImage image = new UnmanagedImage(newBitmap.LockBits(rect, ImageLockMode.ReadWrite, newBitmap.PixelFormat)))
                {
                    using (UnmanagedImage grayImage = UnmanagedImage.Create(image.Width, image.Height, PixelFormat.Format8bppIndexed))
                    {
                        Grayscale.CommonAlgorithms.BT709.Apply(image, grayImage);

                        if (showGrayScale)
                        {
                            ImageForm.ShowImageDialog("Gray scale", grayImage);
                        }

                        Threshold thresholdFilter = new Threshold(threshold);

                        using (UnmanagedImage thresholdImage = thresholdFilter.Apply(grayImage))
                        {
                            ImageForm.ShowImageDialog("Threshold", thresholdImage);
                        }
                    }
                }
            }
        }
        public Bitmap ThreseHoldImage(Bitmap bmp)
        {
            Threshold filter         = new Threshold(100);
            Bitmap    blackenedImage = filter.Apply(bmp);

            return(blackenedImage);
        }
        public static Maybe <ProcFuncs> ConvertToPreProFunc(ProcRecipe src)
        {
            var name    = src.Item1;
            var strparm = src.Item2;
            int parameter;

            if (!Int32.TryParse(strparm, out parameter))
            {
                return(None);
            }

            switch (name)
            {
            case keyThreshold:
                return(Threshold.Apply(parameter));

            case keyNormalize:
                return(Normalize.Apply(parameter));

            case keyAdpThreshold:
                return(AdpThreshold.Apply(parameter));

            case keyMedian:
                return(Median.Apply(parameter));

            default:
                return(None);
            }
        }
Example #8
0
        private void btnBinaryYap_Click(object sender, EventArgs e)
        {
            Bitmap    image     = new Bitmap(pictureBox1.Image);
            Threshold threshold = new Threshold();

            pictureBox4.Image = threshold.Apply(Grayscale.CommonAlgorithms.BT709.Apply(image));
        }
Example #9
0
        private Bitmap getThresholdedFrame(Bitmap grayscaledFrame)
        {
            Threshold filter           = new Threshold(18);
            Bitmap    thresholdedFrame = filter.Apply(grayscaledFrame);

            return(thresholdedFrame);
        }
Example #10
0
        private Bitmap XXX(Bitmap bmpBefore, Bitmap bmpAfter)
        {
            var filter = new Grayscale(0.2125, 0.7154, 0.0721);

            bmpBefore = filter.Apply(bmpBefore);
            bmpAfter  = filter.Apply(bmpAfter);

            // create filters
            var     differenceFilter = new Difference();
            IFilter thresholdFilter  = new Threshold(15);

            // set backgroud frame as an overlay for difference filter
            differenceFilter.OverlayImage = bmpBefore;
            // apply the filters
            Bitmap  tmp1          = differenceFilter.Apply(bmpAfter);
            Bitmap  tmp2          = thresholdFilter.Apply(tmp1);
            IFilter erosionFilter = new Erosion();
            // apply the filter
            Bitmap tmp3 = erosionFilter.Apply(tmp2);

            IFilter pixellateFilter = new Pixellate();
            // apply the filter
            Bitmap tmp4 = pixellateFilter.Apply(tmp3);

            return(tmp4);
        }
        public string decodeBitmap(Bitmap img)
        {
            /////////图像处理
            //转为灰度图
            Grayscale grayscaleFilter = new Grayscale(0.299, 0.587, 0.114);
            Bitmap    bitmapGrayscale = grayscaleFilter.Apply(img);
            //二值化
            Threshold thresholdFilter = new Threshold(128);
            Bitmap    bitmapThreshold = thresholdFilter.Apply(bitmapGrayscale);
            ////////中值滤波
            Median mediafil  = new Median();
            Bitmap medianBit = mediafil.Apply(bitmapThreshold);
            //锐化
            Sharpen sharpPic = new Sharpen();
            Bitmap  sharpOut = sharpPic.Apply(medianBit);
            //统计点数
            HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(sharpOut);
            Histogram histogram = his.Gray;

            int[] dato = histogram.Values;
            /////分割图像
            charCut(dato);
            shunfengdecoder decode   = new shunfengdecoder();
            string          backcode = decode.Decoder(sharpOut, div);

            return(backcode);
        }
        private void detectSkin()
        {
            //skin detection
            Color  clr       = Color.FromArgb(Color.White.ToArgb());
            Color  clr1      = Color.FromArgb(Color.Black.ToArgb());
            int    imgHeight = imageGot.Height;
            int    imgWidth  = imageGot.Width;
            String sc        = "";

            var rect  = new Rectangle(0, 0, imgWidth, imgHeight);
            var data  = imageGot.LockBits(rect, ImageLockMode.ReadWrite, imageGot.PixelFormat);
            var depth = Bitmap.GetPixelFormatSize(data.PixelFormat) / 8; //bytes per pixel

            var buffer = new byte[data.Width * data.Height * depth];

            //copy pixels to buffer
            Marshal.Copy(data.Scan0, buffer, 0, buffer.Length);
            ProcessDetectSkin(buffer, 0, 0, data.Width, data.Height, data.Width, depth);
            //Copy the buffer back to image
            Marshal.Copy(buffer, 0, data.Scan0, buffer.Length);

            imageGot.UnlockBits(data);

            GrayscaleBT709 gs = new GrayscaleBT709();

            imageGot = gs.Apply(imageGot);
            Threshold th = new Threshold();

            imageGot = th.Apply(imageGot);
        }
        private void blackNWhiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Threshold gb = new Threshold();

            newImg            = gb.Apply(newImg);
            pictureBox3.Image = newImg;
        }
Example #14
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog openDialog  = new OpenFileDialog();
            var            returnValue = openDialog.ShowDialog();

            if (returnValue == DialogResult.OK)
            {
                originalImage     = new Bitmap(openDialog.FileName);
                pictureBox1.Image = originalImage;

                // pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;
                Grayscale GrayImage = new Grayscale(0.2125, 0.7154, 0.0721);
                Bitmap    graycolor = GrayImage.Apply(originalImage);

                Threshold BinaryImageE = new Threshold();
                Bitmap    binaryimage  = BinaryImageE.Apply(graycolor);
                pictureBox1.Image = graycolor;
                //graycolor.Save(@"E:\Works\Machine Learning - OCR\raw\graycolor.jpg");

                List <Bitmap> temp_bound = new List <Bitmap>();
                //Bitmap boundedimage1 = new Bitmap("E://Works//Machine Learning - OCR//raw//graycolor.jpg");
                temp_bound.Add(graycolor);

                List <Bitmap> boundedimage = BoundImage(temp_bound);
                pictureBox2.Image = boundedimage[0];
                //boundedimage[0].Save(@"E:\Works\Machine Learning - OCR\raw\boundedimage.jpg");
                List <Bitmap> segments = Segment(boundedimage[0]);
                pictureBox2.Image = segments[0];
                List <float[]> test_feature = Zone(segments);
                write_testfile(test_feature);
                TestClassifier();
            }
        }
        /// <summary>
        /// 根据图片的纵横灰度情况截取图片
        /// 使用Aforge类库
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Rectangle GetByGrayPoint(Bitmap image)
        {
            //灰度化
            Grayscale g = new Grayscale(0.2125, 0.7154, 0.0721);
            // apply the filter
            var grayImg = g.Apply(image);
            //二值化
            var threshold = new Threshold();

            threshold.ThresholdValue = 80;
            var thresholdImage = threshold.Apply(grayImg);

            //找出纵横灰度值
            HorizontalIntensityStatistics hs = new HorizontalIntensityStatistics(thresholdImage);
            VerticalIntensityStatistics   vs = new VerticalIntensityStatistics(thresholdImage);
            var vThreshold = (image.Height / 4) * 255;
            var hThreshold = (image.Width / 4) * 255;
            var hGrays     = hs.Gray.Values.ToList();
            var vGrays     = vs.Gray.Values.ToList();
            var hmin       = FindPaperBorder(hGrays, true, hThreshold, 0);
            var hmax       = FindPaperBorder(hGrays, false, hThreshold, 0);
            var vmin       = FindPaperBorder(vGrays, true, vThreshold, 0);;
            var vmax       = FindPaperBorder(vGrays, false, vThreshold, 0);

            return(new Rectangle(hmin, vmin, hmax - hmin, vmax - vmin));
        }
Example #16
0
        private Bitmap preProcess(Bitmap originalImage)
        {
            Invert invertObj   = new Invert();
            Bitmap invertImage = invertObj.Apply((Bitmap)originalImage.Clone());


            invertImage = Grayscale.CommonAlgorithms.BT709.Apply(invertImage);
            Threshold bwObject = new Threshold();

            invertImage = bwObject.Apply(invertImage);

            ExtractBiggestBlob blobObject = new ExtractBiggestBlob();

            invertImage = blobObject.Apply(invertImage);

            ResizeBicubic resize = new ResizeBicubic(60, 90);

            invertImage = resize.Apply(invertImage);


            //CannyEdgeDetector edgeDetector = new CannyEdgeDetector();
            //invertImage = edgeDetector.Apply(invertImage);

            return(invertImage);
        }
Example #17
0
        void VideoSourcePlayerNewFrame(object sender, ref Bitmap image)
        {
            lock (this)
            {
                Bitmap    img_copy    = new Bitmap(image);
                Grayscale gray_filter = new Grayscale(0.2125, 0.7154, 0.0721);
                img_copy = gray_filter.Apply(img_copy);
                Threshold thresh = new Threshold(thresh_val);
                img_copy = thresh.Apply(img_copy);
                BlobCounter bc = new BlobCounter();
                bc.FilterBlobs = true;
                bc.MinHeight   = min_size_val;
                bc.MinWidth    = min_size_val;
                bc.MaxHeight   = min_size_val + 50;
                bc.MaxWidth    = min_size_val + 50;
                bc.ProcessImage(img_copy);
                Rectangle[] rects = bc.GetObjectsRectangles();

                Graphics g = videoSourcePlayer.CreateGraphics();
                using (Pen p = new Pen(Color.Red))
                {
                    foreach (Rectangle r in rects)
                    {
                        g.DrawRectangle(p, r);
                        g.DrawString("a", new Font("Consolas", 10), Brushes.Red, r.X, r.Y);
                    }
                }
                image = img_copy;
            }
        }
Example #18
0
 private void button4_Click(object sender, EventArgs e)
 {
     int.TryParse(textBox1.Text, out Threshold);
     BinFilter.ThresholdValue = Threshold;
     BinBmp        = BinFilter.Apply(grayBmp);
     process.Image = BinBmp;
     this.Text     = Threshold.ToString();
 }
Example #19
0
        public IImage Apply(IImage image)
        {
            var grayScale = ToGrayScale(image);
            var filter    = new Threshold(factor);
            var bmp       = filter.Apply(grayScale.ToGray().Lock().AsAForgeImage());

            return(bmp.AsImage());
        }
Example #20
0
        private void otsuÇıkarımToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Threshold filter = new Threshold(100);
            // apply the filter
            Bitmap otsu = filter.Apply((Bitmap)pictureBox7.Image);

            pictureBox8.Image = otsu;
        }
Example #21
0
        private void binarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GrayscaleBT709 grayoject = new GrayscaleBT709();

            pictureBox2.Image = grayoject.Apply((Bitmap)pictureBox1.Image);
            Threshold filter = new Threshold();

            pictureBox2.Image = filter.Apply((Bitmap)pictureBox2.Image);
        }
        /// <summary>
        /// Generate a binary BitmapImage
        /// </summary>
        /// <param name="bitmapImage"></param>
        /// <param name="thresholdLevel"></param>
        /// <returns></returns>
        public static BitmapImage Binary(this BitmapImage bitmapImage, int thresholdLevel)
        {
            Bitmap    bitmap    = bitmapImage.BitmapImage2Bitmap();
            Threshold threshold = new Threshold(thresholdLevel);
            IFilter   filter    = Grayscale.CommonAlgorithms.BT709;

            bitmap = filter.Apply(bitmap);
            return(threshold.Apply(bitmap).ToBitmapImage());
        }
        public void Binarize(object sender, DoWorkEventArgs e)
        {
            Bitmap InputImage = null;

            if (inPutRb.Checked)
            {
                InputImage = Accord.Imaging.Filters.Grayscale.CommonAlgorithms.BT709.Apply((Bitmap)input_PB.Image.Clone());
            }
            else if (outPutRB.Checked)
            {
                InputImage = (Bitmap)outputImageBox.Image.Clone();
            }
            if (wolfRb.Checked)
            {
                var wolfFilter = new Accord.Imaging.Filters.WolfJolionThreshold();
                if (holderTb_1.Text != String.Empty)
                {
                    wolfFilter.K = double.Parse(holderTb_1.Text);
                }
                if (holderTb_2.Text != String.Empty)
                {
                    wolfFilter.R = double.Parse(holderTb_2.Text);
                }
                if (holderTb_3.Text != String.Empty)
                {
                    wolfFilter.Radius = int.Parse(holderTb_3.Text);
                }
                Bitmap raw_img = InputImage;

                UnmanagedImage res = wolfFilter.Apply(UnmanagedImage.FromManagedImage(raw_img));
                outputImageBox.Image.Dispose();
                outputImageBox.Image = res.ToManagedImage();
            }
            else if (simpleThresh.Checked)
            {
                int Thresh       = int.Parse(holderTb_1.Text);
                var simpleThresh = new Threshold();
                simpleThresh.ThresholdValue = Thresh;
                Bitmap raw_img = InputImage;

                UnmanagedImage res = simpleThresh.Apply(UnmanagedImage.FromManagedImage(raw_img));
                outputImageBox.Image.Dispose();
                outputImageBox.Image = res.ToManagedImage();
            }
            else if (OtsuRb.Checked)
            {
                int Thresh     = int.Parse(holderTb_1.Text);
                var OtsuThresh = new Threshold();
                OtsuThresh.ThresholdValue = Thresh;
                Bitmap raw_img = InputImage;

                UnmanagedImage res = OtsuThresh.Apply(UnmanagedImage.FromManagedImage(raw_img));
                outputImageBox.Image.Dispose();
                outputImageBox.Image = res.ToManagedImage();
            }
        }
Example #24
0
        public Bitmap GetNewFrame(Bitmap source)
        {
            // get grayscale image
            var source1  = Grayscale.CommonAlgorithms.RMY.Apply(source);
            var newFrame = threshold.Apply(source1);

            source.Dispose();
            source1.Dispose();
            return(newFrame);
        }
Example #25
0
 private void thresoldToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (pictureBox1.Image != null)
     {
         Threshold thresold = new Threshold((int)trackBartThresold.Value);
         Bitmap    org      = new Bitmap(pictureBox1.Image);
         Bitmap    clone    = org.Clone(new Rectangle(0, 0, org.Width, org.Height), PixelFormat.Format24bppRgb);
         pictureBox2.Image = thresold.Apply(clone);
     }
 }
Example #26
0
 private void trackBartThresold_Scroll(object sender, EventArgs e)
 {
     if (pictureBox1.Image != null)
     {
         Threshold thresold = new Threshold((int)trackBartThresold.Value);
         Bitmap    org      = new Bitmap(pictureBox1.Image);
         Bitmap    clone    = org.Clone(new Rectangle(0, 0, org.Width, org.Height), PixelFormat.Format8bppIndexed);
         pictureBox2.Image = thresold.Apply(clone);
     }
 }
        public EdgeImage Generate(Bitmap source)
        {
            // Make GrayScale Version of image
            Grayscale filter    = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap    grayImage = filter.Apply(source);

            // Apply Sobel Edge Detection to the image
            SobelEdgeDetector sobelFilter = new SobelEdgeDetector();
            Bitmap            edgeImage   = sobelFilter.Apply(grayImage);

            // Apply Threshold to edge detected image
            // Edges are white pixels with value 255 otherwise black with value 0
            Threshold thresholdFilter = new Threshold(Threshold);
            Bitmap    thresholdImage  = thresholdFilter.Apply(edgeImage);

            // Render Image
            var newImg = new Bitmap(thresholdImage.Width, thresholdImage.Height);

            if (thresholdImage != null)
            {
                var g = Graphics.FromImage(newImg);

                var srcRect  = new Rectangle(0, 0, thresholdImage.Width, thresholdImage.Height);
                var destRect = new Rectangle(0, 0, thresholdImage.Width, thresholdImage.Height);

                g.DrawImage(thresholdImage, destRect, srcRect, GraphicsUnit.Pixel);
            }

            var edgeLocations = new List <PixelCoordinates>();

            // Save location of edges
            for (int x = 0; x < newImg.Width; x++)
            {
                for (int y = 0; y < newImg.Height; y++)
                {
                    if (newImg.GetPixel(x, y).R >= Threshold)
                    {
                        edgeLocations.Add(new PixelCoordinates()
                        {
                            X = x, Y = y
                        });
                    }
                }
            }

            // Dispose of the created images
            grayImage.Dispose();
            edgeImage.Dispose();
            thresholdImage.Dispose();

            return(new EdgeImage()
            {
                Image = newImg, Edges = edgeLocations
            });
        }
Example #28
0
        //-------------------------------------------------------------
        private void process_imginput(Bitmap img, String Plate_Type)
        {
            //grayscale
            IFilter way_filt;//= new GrayscaleY();

            //process_image = way_filt.Apply(img);
            //resize
            if (Plate_Type == "1hang")
            {
                way_filt = new ResizeBilinear(600, 120); //bien 1 hang
            }
            else
            {
                way_filt = new ResizeBilinear(300, 200); //bien 2 hang
            }

            process_image = way_filt.Apply(img);
            //process_image = get_plate(process_image, 10, 210, 30, 330);
            input_image = way_filt.Apply(input_image);
            p           = process_image;
            //threshold
            way_filt      = new Threshold(125);
            process_image = way_filt.Apply(process_image);


            //K-means
            process_image = kmean(process_image);


            //invert
            way_filt      = new Invert();
            process_image = way_filt.Apply(process_image);


            //liembt
            //UCM
            way_filt      = new Median();
            process_image = way_filt.Apply(process_image);

            //way_filt = new AdaptiveSmooth();
            //process_image = way_filt.Apply(process_image);

            //end liembt
            //filter k
            BlobsFiltering filter = new BlobsFiltering();

            filter.MinHeight = 25;//50
            filter.MinWidth  = 10;
            filter.MaxHeight = 100;
            filter.ApplyInPlace(process_image);
            //p = process_image;
            input_width  = process_image.Width;
            input_height = process_image.Height;
        }
        /// <summary>
        /// Binarize image with threshold filter
        /// </summary>
        /// <param name="image"></param>
        /// <param name="threshold">threshold for binarization</param>
        public static Bitmap Threshold(this Bitmap image, byte threshold)
        {
            if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new NotSupportedException("Filter can be applied to binary 8bpp images only");
            }

            Threshold thresholdFilter = new Threshold(threshold);

            return(thresholdFilter.Apply(image));
        }
Example #30
0
        public static Bitmap Binaryzation(Bitmap b, int limit)
        {
            Threshold th = new Threshold();

            th.ThresholdValue = limit;
            Bitmap bx = ImageSupporter.ColorToGrayscale((Bitmap)b.Clone());

            GrayscaleToRGB grayscaleToRGB = new GrayscaleToRGB();

            return(grayscaleToRGB.Apply(th.Apply(ImageSupporter.ColorToGrayscale(bx))));
        }