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;
                }
        }
Exemple #2
0
        public Bitmap Apply(Bitmap image)
        {
            Bitmap bitmap = dilatation.Apply(image);
            Bitmap result = errosion.Apply(bitmap);

            bitmap.Dispose();
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Apply filter to an image.
        /// </summary>
        ///
        /// <param name="image">Source image to apply filter to.</param>
        ///
        /// <returns>Returns filter's result obtained by applying the filter to
        /// the source image.</returns>
        ///
        /// <remarks>The method keeps the source image unchanged and returns
        /// the result of image processing filter as new image.</remarks>
        ///
        /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image.</exception>
        ///
        public Bitmap Apply(Bitmap image)
        {
            Bitmap tempImage = errosion.Apply(image);
            Bitmap destImage = dilatation.Apply(tempImage);

            tempImage.Dispose( );

            return(destImage);
        }
        public double GetTemperature()
        {
            var temp = 0.0;

            var image = Image.FromFile(filename);

            var grayscale = new Grayscale(0.2125, 0.7154, 0.0721);
            image = grayscale.Apply(image);

            var invert = new Invert();
            image = invert.Apply(image);

            var stats = new ImageStatistics(image);
            var levelsLinear = new LevelsLinear
            {
                InGray = stats.Gray.GetRange(2.90)
            };

            image = levelsLinear.Apply(image);

            var contrast = new ContrastStretch();
            image = contrast.Apply(image);

            var erosion = new Erosion();
            image = erosion.Apply(image);

            var blur = new GaussianBlur(2, 3);
            image = blur.Apply(image);

            var threshold = new Threshold(79);
            image = threshold.Apply(image);

            image.Save(processedFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
            image.Dispose();
            var text = Recognise();

            double.TryParse(text.Replace(',', '.'), out temp);

            return temp;
        }
        public void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            // get new frame
            CheckForIllegalCrossThreadCalls = false;
            Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
            if (pictureBox1.Image == null)
            {
                bitmap.Save(@"modelo0.jpg");
                bgFrame = bitmap;
            }
            else
            {
                try
                {
                    bgFrame = (Bitmap)pictureBox1.Image.Clone();
                    //bitmap.Save(@"currImage.jpg");
                    currentFrame = (Bitmap)bitmap.Clone();

                    Bitmap gcurrent = Grayscale.CommonAlgorithms.BT709.Apply(bitmap);
                    Bitmap gbground = Grayscale.CommonAlgorithms.BT709.Apply(bgFrame);

                    Difference differenceFilter = new Difference();
                    differenceFilter.OverlayImage = gbground;
                    Bitmap currentImg = differenceFilter.Apply(gcurrent);

                    //bloqueo temporal de current image
                    BitmapData currentData = currentImg.LockBits(new Rectangle(0, 0, framesProcessing.fWidth,
                                        framesProcessing.fHeight), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);

                    //**Thresholdfilter
                    Threshold thresholdFilter = new Threshold(15);
                    thresholdFilter.ApplyInPlace(currentData);
                    IFilter erosionFilter = new Erosion();
                    Bitmap tmp2 = erosionFilter.Apply(currentData);

                    currentImg.UnlockBits(currentData);
                    i = framesProcessing.CalculateWhitePixels(tmp2);

                    if (i > 300)
                    {
                        mov = mov2 = true;
                    }
                    else
                        mov = false;

                    pictureBox2.Image = currentImg;
                }
                catch{//MessageBox.Show(ex.Message.ToString());
                }

            }
            pictureBox1.Image = bitmap;
        }
 public static Bitmap Erosion(Bitmap bmp)
 {
     // create filter
     Erosion filter = new Erosion();
     // apply the filter
     filter.Apply(bmp);
     return bmp;
 }
Exemple #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;
            }
        }
 public static Bitmap ApplyErosion(Bitmap pBitmap)
 {
     Erosion filter = new Erosion();
     return filter.Apply(pBitmap);
 }
Exemple #9
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;
        }
 /// <summary>
 /// processes Frame for Motion Detection based on frame comparison
 /// </summary>
 /// <param name="frame">
 /// Takes in 2 Bitmap parameters, currentFrame and backgroundFrame
 /// </param>
 /// <returns>
 /// frame in which motion is marked
 /// </returns>
 public Bitmap processFrame(params Bitmap[] frame)
 {
     Bitmap currentFrame = frame[0];
     // create grayscale filter (BT709)
     Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
     Bitmap GScurrentFrame = filter.Apply(currentFrame);
     if (this.backgroundFrame == null)
     {
         this.backgroundFrame = (Bitmap)GScurrentFrame.Clone();
         GScurrentFrame.Dispose();
         return currentFrame;
     }
     else
     {
         Difference differenceFilter = new Difference();
         IFilter thresholdFilter = new Threshold(15);
         // set backgroud frame as an overlay for difference filter
         differenceFilter.OverlayImage = backgroundFrame;
         Bitmap tmp = thresholdFilter.Apply(differenceFilter.Apply(GScurrentFrame));
         //reduce noise
         IFilter erosionFilter = new Erosion();
         Bitmap tmp1 = erosionFilter.Apply(tmp);
         tmp.Dispose();
         // Highlight Motions
         IFilter extractChannel = new ExtractChannel(RGB.G);
         Bitmap redChannel = extractChannel.Apply(currentFrame);
         Merge mergeFilter = new Merge();
         mergeFilter.OverlayImage = tmp1;
         Bitmap t3 = mergeFilter.Apply(redChannel);
         ReplaceChannel rc = new ReplaceChannel(RGB.G, t3);
         t3 = rc.Apply(currentFrame);
         this.backgroundFrame = (Bitmap)GScurrentFrame.Clone();
         redChannel.Dispose();
         tmp1.Dispose();
         GScurrentFrame.Dispose();
         return t3;
     }
 }
        private void DetectMotion()
        {
            if ((_previousFrame != null) && (_currentFrame != null))
            {
                Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
                using (Bitmap frame1GS = grayscaleFilter.Apply(_previousFrame))
                {
                    using (Bitmap frame2GS = grayscaleFilter.Apply(_currentFrame))
                    {
                        Difference differenceFilter = new Difference();
                        IFilter thresholdFilter = new Threshold(15);
                        // set backgroud frame as an overlay for difference filter

                        differenceFilter.OverlayImage = (Bitmap)frame1GS;
                        // apply the filters

                        using (Bitmap tmp1 = differenceFilter.Apply((Bitmap)frame2GS))
                        {
                            using (Bitmap tmp2 = thresholdFilter.Apply(tmp1))
                            {

                                IFilter erosionFilter = new Erosion();
                                // apply the filter

                                using (Bitmap tmp3 = erosionFilter.Apply(tmp2))
                                {
                                    int whitePixelsCount = CalculateWhitePixels(tmp3);

                                    if (whitePixelsCount > 1000)
                                    {
                                        MotionDetectionEvent motionEvent = new MotionDetectionEvent()
                                        {
                                            CameraDevice = _camera,
                                            NumberOfPixelsDetected = whitePixelsCount,
                                            InputDevice = _camera
                                        };
                                        MotionDetectedEventArgs args = new MotionDetectedEventArgs(motionEvent);
                                        OnMotionDetected(args);
                                    }

                                    //// extract red channel from the original image

                                    //IFilter extrachChannel = new ExtractChannel(RGB.R);
                                    //Bitmap redChannel = extrachChannel.Apply(frame2);
                                    ////  merge red channel with motion regions

                                    //Merge mergeFilter = new Merge();
                                    //mergeFilter.OverlayImage = tmp3;
                                    //Bitmap tmp4 = mergeFilter.Apply(redChannel);
                                    //// replace red channel in the original image

                                    //ReplaceChannel replaceChannel = new ReplaceChannel(RGB.R, tmp4);
                                    //replaceChannel.ChannelImage = tmp4;
                                    //Bitmap tmp5 = replaceChannel.Apply(frame2);
                                }
                            }
                        }
                    }
                }
            }
        }