private void btnEffectApply_Click(object sender, EventArgs e)
 {
     resizerControl.Visible = true;
     IFilter imgeFilter = default(IFilter);
     Button effect = (Button)sender;
     Bitmap imgEffect = img;
     if (effect.Name == "btnGray")
     {
         imgeFilter = new GrayscaleBT709();
     }
     else if (effect.Name == "btnSeperia")
     {
         imgeFilter = new Sepia();
     }
     else if (effect.Name == "btnInvert")
     {
         imgeFilter = new Invert();
     }
     else if (effect.Name == "btnCommon")
     {
         imgeFilter = new BurkesDithering();
     }
     else if (effect.Name == "btnBlur")
     {
         imgeFilter = new Blur();
     }
     else if (effect.Name == "btnJitter")
     {
         imgeFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(10, 11), 0.7f, 0.3f);
     }
     else if (effect.Name == "btnCyan")
     {
         imgeFilter = new ChannelFiltering(new IntRange(0, 0), new IntRange(0, 255), new IntRange(0, 255));
     }
     else if (effect.Name == "btnBlackWhite")
     {
         imgeFilter = new YCbCrExtractChannel(AForge.Imaging.YCbCr.CrIndex);
     }
     imgEffect = imgeFilter.Apply(img);
     panelImage.BackgroundImage = imgEffect;
     //img = imgEffect;
 }
Example #2
0
        private void FillPictureBoxes(ref Bitmap image)
        {
            Bitmap tmpImg  = image;
            Bitmap tmpImg2 = image;


            try
            {
                bool hasFilter = false;
                //setup resize and filtersequesce


                //resize img to fit picturebox
                ResizeBicubic resizeFilter = new ResizeBicubic(0, 0);

                resizeFilter = new ResizeBicubic(pbCapture.Width, pbCapture.Height);
                tmpImg       = resizeFilter.Apply(tmpImg);

                resizeFilter = new ResizeBicubic(pbShapes.Width, pbShapes.Height);
                tmpImg2      = resizeFilter.Apply(tmpImg2);



                FiltersSequence processingFilter = new FiltersSequence();


                //List all filters
                IFilter ConservativeSmoothingFilter = new AForge.Imaging.Filters.ConservativeSmoothing();
                IFilter InvertFilter          = new AForge.Imaging.Filters.Invert();
                IFilter HSLFilteringFilter    = new AForge.Imaging.Filters.HSLFiltering();
                IFilter SepiaFilter           = new AForge.Imaging.Filters.Sepia();
                IFilter grayscaleFilter       = new AForge.Imaging.Filters.GrayscaleBT709();
                IFilter SkeletonizationFilter = new AForge.Imaging.Filters.SimpleSkeletonization();
                IFilter pixFilter             = new AForge.Imaging.Filters.Pixellate();


                ////apply filter and process img---------------------------------------------



                if (ConservativeSmoothing)
                {
                    processingFilter.Add(ConservativeSmoothingFilter);
                    hasFilter = true;
                }

                if (Invert)
                {
                    processingFilter.Add(InvertFilter);
                    hasFilter = true;
                }

                if (HSLswitch)
                {
                    processingFilter.Add(HSLFilteringFilter);
                    hasFilter = true;
                }

                if (sepiaSwitch)
                {
                    processingFilter.Add(SepiaFilter);
                    hasFilter = true;
                }


                if (Skeletonization)
                {
                    processingFilter.Add(grayscaleFilter);
                    processingFilter.Add(SkeletonizationFilter);
                    hasFilter = true;
                }

                //apply the filter(s) to image
                if (hasFilter)
                {
                    //tmpImg = processingFilter.Apply(tmpImg);
                    tmpImg2 = processingFilter.Apply(tmpImg2);
                }

                processingFilter.Clear();


                if (bwSwitch)
                {
                    switchBandW(ref tmpImg);
                }



                if (CannyEdgeDetector)
                {
                    // create filter
                    CannyEdgeDetector filter = new CannyEdgeDetector();
                    // apply the filter
                    tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg);
                    filter.ApplyInPlace(tmpImg);


                    // image = DrawFocusArea(gsImage);
                }
                else
                {
                    // image = DrawFocusArea(image);
                }


                if (DifferenceEdgeDetector)
                {
                    DifferenceEdgeDetector dFilter = new DifferenceEdgeDetector();
                    // apply the filter
                    tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg);
                    dFilter.ApplyInPlace(tmpImg);
                }


                if (HomogenityEdgeDetector)
                {
                    HomogenityEdgeDetector hFilter = new HomogenityEdgeDetector();
                    // apply the filter
                    tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg);
                    hFilter.ApplyInPlace(tmpImg);
                }


                if (SobelEdgeDetector)
                {
                    SobelEdgeDetector hFilter = new SobelEdgeDetector();
                    // apply the filter
                    tmpImg = Grayscale.CommonAlgorithms.BT709.Apply(tmpImg);
                    hFilter.ApplyInPlace(tmpImg);

                    BlobCounter bc    = new BlobCounter(tmpImg);
                    Rectangle[] brecs = bc.GetObjectsRectangles();


                    //Graphics pg = Graphics.FromImage(tmpImg);
                    //Pen p = new Pen(Color.White, 2);

                    //foreach (Rectangle r in brecs)
                    //{
                    //    pg.DrawRectangle(p, r);
                    //}
                }



                if (findShapes)
                {
                    tmpImg = FindShapes(tmpImg, ref tmpImg2);
                    //ProcessImage(image);
                }
                else
                {
                    pbCapture.Image = tmpImg;  //set picturebox image----------------
                    pbShapes.Image  = tmpImg2; //set picturebox image----------------
                }



                // Graphics g = Graphics.FromImage(tmpImg);
                // Pen p = new Pen(Color.Red, 2);

                // Rectangle lr = new Rectangle(100, 120, 80, 40);
                //// Rectangle rr = new Rectangle(360, 220, 80, 40);

                // g.DrawRectangle(p, lr);
                // //g.DrawRectangle(p, rr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


            //  pbCapture.Image = tmpImg;//set picturebox image----------------
            //   pbShapes.Image = tmpImg2;//set picturebox image----------------
        }
 private void Effect()
 {
     IFilter imgeFilter = new BurkesDithering();
     Bitmap bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnCommon.Image = bitimg;
     imgeFilter = new GrayscaleBT709();
     btnGray.Image = new Bitmap(imgeFilter.Apply(img), 90, 111);
     imgeFilter = new Sepia();
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnSeperia.Image = bitimg;
     imgeFilter = new Invert();
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnInvert.Image = bitimg;
     imgeFilter = new Blur();
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnBlur.Image = bitimg;
     imgeFilter = new Texturer(new AForge.Imaging.Textures.MarbleTexture(10, 11), 0.7f, 0.3f);
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnJitter.Image = bitimg;
     imgeFilter = new ChannelFiltering(new IntRange(0, 0), new IntRange(0, 255), new IntRange(0, 255));
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnCyan.Image = bitimg;
     imgeFilter = new YCbCrExtractChannel(AForge.Imaging.YCbCr.CrIndex);
     bitimg = new Bitmap(imgeFilter.Apply(img), 90, 111);
     btnBlackWhite.Image = bitimg;
 }
Example #4
0
 public static Bitmap ToSepia(this Bitmap bitmap)
 {
     AForge.Imaging.Filters.Sepia filter = new AForge.Imaging.Filters.Sepia();
     return(filter.Apply(AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format24bppRgb)));
 }