Exemplo n.º 1
0
        public Bitmap Adelgazar()
        {
            Invert ivert = new Invert();
            imagen = ivert.Apply(imagen);

            FiltersSequence filterSequence = new FiltersSequence();

            filterSequence.Add(new HitAndMiss(
                new short[,] { { 0, 0, 0 },
                               { -1, 1, -1 },
                               { 1, 1, 1 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { -1, 0, 0 },
                               { 1, 1, 0 },
                               { -1, 1, -1 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { 1, -1, 0 },
                               { 1, 1, 0 },
                               { 1, -1, 0 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { -1, 1, -1 },
                               { 1, 1, 0 },
                               { -1, 0, 0 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { 1, 1, 1 },
                               { -1, 1, -1 },
                               { 0, 0, 0 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { -1, 1, -1 },
                               { 0, 1, 1 },
                               { 0, 0, -1 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { 0, -1, 1 },
                               { 0, 1, 1 },
                               { 0, -1, 1 } },
                HitAndMiss.Modes.Thinning));
            filterSequence.Add(new HitAndMiss(
                new short[,] { { 0, 0, -1 },
                               { 0, 1, 1 },
                               { -1, 1, -1 } },
                HitAndMiss.Modes.Thinning));

            FilterIterator filterIterator = new FilterIterator(filterSequence, 15);

            imagen = filterIterator.Apply(imagen);

            imagen = ivert.Apply(imagen);

            return imagen;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            var width  = image.Width;
            var height = image.Height;

            // 1 - invert the source image
            var invertFilter  = new Invert( );
            var invertedImage = invertFilter.Apply(image);

            // 2 - use blob counter to find holes (they are white objects now on the inverted image)
            var blobCounter = new BlobCounter( );

            blobCounter.ProcessImage(invertedImage);
            var blobs = blobCounter.GetObjectsInformation( );

            // 3 - check all blobs and determine which should be filtered
            var newObjectColors = new byte[blobs.Length + 1];

            newObjectColors[0] = 255; // don't touch the objects, which have 0 ID

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                var blob = blobs[i];

                if ((blob.Rectangle.Left == 0) || (blob.Rectangle.Top == 0) ||
                    (blob.Rectangle.Right == width) || (blob.Rectangle.Bottom == height))
                {
                    newObjectColors[blob.ID] = 0;
                }
                else
                {
                    if (((this.coupledSizeFiltering) && (blob.Rectangle.Width <= this.maxHoleWidth) && (blob.Rectangle.Height <= this.maxHoleHeight)) |
                        ((!this.coupledSizeFiltering) && ((blob.Rectangle.Width <= this.maxHoleWidth) || (blob.Rectangle.Height <= this.maxHoleHeight))))
                    {
                        newObjectColors[blob.ID] = 255;
                    }
                    else
                    {
                        newObjectColors[blob.ID] = 0;
                    }
                }
            }

            // 4 - process the source image image and fill holes
            var ptr    = (byte *)image.ImageData.ToPointer( );
            var offset = image.Stride - width;

            var objectLabels = blobCounter.ObjectLabels;

            for (int y = 0, i = 0; y < height; y++)
            {
                for (var x = 0; x < width; x++, i++, ptr++)
                {
                    *ptr = newObjectColors[objectLabels[i]];
                }
                ptr += offset;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            int width  = image.Width;
            int height = image.Height;

            // 1 - invert the source image
            Invert         invertFilter  = new Invert();
            UnmanagedImage invertedImage = invertFilter.Apply(image);

            // 2 - use blob counter to find holes (they are white objects now on the inverted image)
            BlobCounter blobCounter = new BlobCounter();

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

            // 3 - check all blobs and determine which should be filtered
            byte[] newObjectColors = new byte[blobs.Length + 1];
            newObjectColors[0] = 255;           // don't touch the objects, which have 0 ID

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                Blob blob = blobs[i];

                if ((blob.Rectangle.Left == 0) || (blob.Rectangle.Top == 0) ||
                    (blob.Rectangle.Right == width) || (blob.Rectangle.Bottom == height))
                {
                    newObjectColors[blob.ID] = 0;                   // background image
                }
                else
                {
                    if (blob.Area <= maxArea)
                    {
                        newObjectColors[blob.ID] = 255;                       // fill hole, set to bright 255
                        NumFilled++; AreaFilled += blob.Area;
                    }
                    else
                    {
                        newObjectColors[blob.ID]     = 0;                   // do no fill, remain dark zero
                        NumUnfilled++; AreaUnfilled += blob.Area;
                    }
                }
            }

            // 4 - process the source image image and fill holes
            byte *ptr    = (byte *)image.ImageData.ToPointer();
            int   offset = image.Stride - width;

            int[] objectLabels = blobCounter.ObjectLabels;

            for (int y = 0, i = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++, i++, ptr++)
                {
                    *ptr = newObjectColors[objectLabels[i]];
                }
                ptr += offset;
            }
        }
Exemplo n.º 4
0
 private Bitmap filter()
 {
     Bitmap filtered_image;
     AForge.Imaging.Filters.Grayscale gr = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
     AForge.Imaging.Filters.Threshold th = new AForge.Imaging.Filters.Threshold(100);
     AForge.Imaging.Filters.Invert invert = new AForge.Imaging.Filters.Invert();
     filtered_image = gr.Apply(scanned_image);
     filtered_image = invert.Apply(filtered_image);
     filtered_image = th.Apply(filtered_image);
     return filtered_image;
 }
Exemplo n.º 5
0
        private Bitmap filter()
        {
            Bitmap filtered_image;

            AForge.Imaging.Filters.Grayscale gr     = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
            AForge.Imaging.Filters.Threshold th     = new AForge.Imaging.Filters.Threshold(100);
            AForge.Imaging.Filters.Invert    invert = new AForge.Imaging.Filters.Invert();
            filtered_image = gr.Apply(scanned_image);
            filtered_image = invert.Apply(filtered_image);
            filtered_image = th.Apply(filtered_image);
            return(filtered_image);
        }
Exemplo n.º 6
0
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int            width       = image.Width;
            int            height      = image.Height;
            Invert         invert      = new Invert();
            UnmanagedImage image2      = invert.Apply(image);
            BlobCounter    blobCounter = new BlobCounter();

            blobCounter.ProcessImage(image2);
            Blob[] objectsInformation = blobCounter.GetObjectsInformation();
            byte[] array = new byte[objectsInformation.Length + 1];
            array[0] = byte.MaxValue;
            int i = 0;

            for (int num = objectsInformation.Length; i < num; i++)
            {
                Blob blob = objectsInformation[i];
                if (blob.Rectangle.Left == 0 || blob.Rectangle.Top == 0 || blob.Rectangle.Right == width || blob.Rectangle.Bottom == height)
                {
                    array[blob.ID] = 0;
                }
                else if ((coupledSizeFiltering && blob.Rectangle.Width <= maxHoleWidth && blob.Rectangle.Height <= maxHoleHeight) | (!coupledSizeFiltering && (blob.Rectangle.Width <= maxHoleWidth || blob.Rectangle.Height <= maxHoleHeight)))
                {
                    array[blob.ID] = byte.MaxValue;
                }
                else
                {
                    array[blob.ID] = 0;
                }
            }
            byte *ptr  = (byte *)image.ImageData.ToPointer();
            int   num2 = image.Stride - width;

            int[] objectLabels = blobCounter.ObjectLabels;
            int   j            = 0;
            int   num3         = 0;

            for (; j < height; j++)
            {
                int num4 = 0;
                while (num4 < width)
                {
                    *ptr = array[objectLabels[num3]];
                    num4++;
                    num3++;
                    ptr++;
                }
                ptr += num2;
            }
        }
        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 static Bitmap Inverse(Bitmap img)
 {
     IFilter filter = new Invert();
     return filter.Apply(img);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image )
        {
            int width  = image.Width;
            int height = image.Height;

            // 1 - invert the source image
            Invert invertFilter = new Invert( );
            UnmanagedImage invertedImage = invertFilter.Apply( image );

            // 2 - use blob counter to find holes (they are white objects now on the inverted image)
            BlobCounter blobCounter = new BlobCounter( );
            blobCounter.ProcessImage( invertedImage );
            Blob[] blobs = blobCounter.GetObjectsInformation( );

            // 3 - check all blobs and determine which should be filtered
            byte[] newObjectColors = new byte[blobs.Length + 1];
            newObjectColors[0] = 255; // don't touch the objects, which have 0 ID

            for ( int i = 0, n = blobs.Length; i < n; i++ )
            {
                Blob blob = blobs[i];

                if ( ( blob.Rectangle.Left == 0 ) || ( blob.Rectangle.Top == 0 ) ||
                     ( blob.Rectangle.Right == width ) || ( blob.Rectangle.Bottom == height ) )
                {
                    newObjectColors[blob.ID] = 0;
                }
                else
                {
                    if ( ( ( coupledSizeFiltering ) && ( blob.Rectangle.Width <= maxHoleWidth ) && ( blob.Rectangle.Height <= maxHoleHeight ) ) |
                         ( ( !coupledSizeFiltering ) && ( ( blob.Rectangle.Width <= maxHoleWidth ) || ( blob.Rectangle.Height <= maxHoleHeight ) ) ) )
                    {
                        newObjectColors[blob.ID] = 255;
                    }
                    else
                    {
                        newObjectColors[blob.ID] = 0;
                    }
                }
            }

            // 4 - process the source image image and fill holes
            byte* ptr = (byte*) image.ImageData.ToPointer( );
            int offset = image.Stride - width;

            int[] objectLabels = blobCounter.ObjectLabels;

            for ( int y = 0, i = 0; y < height; y++ )
            {
                for ( int x = 0; x < width; x++, i++, ptr++ )
                {
                    *ptr = newObjectColors[objectLabels[i]];
                }
                ptr += offset;
            }
        }
Exemplo n.º 10
0
 private void InvertImage()
 {
     Invert invertfilter = new Invert();
     _markersimg = invertfilter.Apply(_recogimg);
 }
Exemplo n.º 11
0
 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;
 }
 public static Bitmap ApplyInvert(Bitmap pBitmap)
 {
     var filter = new Invert();
     return filter.Apply(pBitmap);
 }
Exemplo n.º 13
0
 public static Bitmap ToInvert(this Bitmap bitmap)
 {
     AForge.Imaging.Filters.Invert filter = new AForge.Imaging.Filters.Invert();
     return(filter.Apply(AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format24bppRgb)));
 }