+ // create filter
+ Shrink filter = new Shrink( Color.Black );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // get filter's IFilterInformation interface
+ IFilterInformation info = (IFilterInformation) filter;
+ // check if the filter supports our image's format
+ if ( info.FormatTranslations.ContainsKey( image.PixelFormat )
+ {
+ // format is supported, check what will be result of image processing
+ PixelFormat resultingFormat = info.FormatTranslations[image.PixelFormat];
+ }
+ ///
+
+ // create filter - rotate for 30 degrees keeping original image size
+ RotateNearestNeighbor filter = new RotateNearestNeighbor( 30, true );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ ConservativeSmoothing filter = new ConservativeSmoothing( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ RotateChannels filter = new RotateChannels( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ GammaCorrection filter = new GammaCorrection( 0.5 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ BrightnessCorrection filter = new BrightnessCorrection( -50 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ | * | 8 | 4 |
+ | 2 | 4 | 8 | 4 | 2 |
+ | 1 | 2 | 4 | 2 | 1 |
+
+ / 42
+
+
+
+ // create filter
+ StuckiDithering filter = new StuckiDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ int[][] coefficients = new int[2][] {
+ new int[1] { 7 },
+ new int[3] { 3, 5, 1 }
+ };
+
+
+
+ | * | 7 |
+ | 3 | 5 | 1 |
+
+ / 16
+
+
+
+ // create filter
+ ErrorDiffusionToAdjacentNeighbors filter = new ErrorDiffusionToAdjacentNeighbors(
+ new int[3][] {
+ new int[2] { 5, 3 },
+ new int[5] { 2, 4, 5, 4, 2 },
+ new int[3] { 2, 3, 2 }
+ } );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+ // create filter sequence
+ FiltersSequence filterSequence = new FiltersSequence( );
+ // add 8 thinning filters with different structuring elements
+ 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 ) );
+ // create filter iterator for 10 iterations
+ FilterIterator filter = new FilterIterator( filterSequence, 10 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ Threshold filter = new Threshold( 100 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Add filter = new Add( overlayImage );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ | * | 8 | 4 |
+ | 2 | 4 | 8 | 4 | 2 |
+ | 1 | 2 | 4 | 2 | 1 |
+
+ / 42
+
+
+
+ // create color image quantization routine
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // create 64 colors table
+ Color[] colorTable = ciq.CalculatePalette( image, 64 );
+ // create dithering routine
+ StuckiColorDithering dithering = new StuckiColorDithering( );
+ dithering.ColorTable = colorTable;
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ int[][] coefficients = new int[2][] {
+ new int[1] { 7 },
+ new int[3] { 3, 5, 1 }
+ };
+
+
+
+ | * | 7 |
+ | 3 | 5 | 1 |
+
+ / 16
+
+
+
+ // create dithering routine
+ ColorErrorDiffusionToAdjacentNeighbors dithering = new ColorErrorDiffusionToAdjacentNeighbors(
+ new int[3][] {
+ new int[2] { 5, 3 },
+ new int[5] { 2, 4, 5, 4, 2 },
+ new int[3] { 2, 3, 2 }
+ } );
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+ | * | 7 |
+ | 3 | 5 | 1 |
+
+ / 16
+
+
+
+ // create color image quantization routine
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // create 16 colors table
+ Color[] colorTable = ciq.CalculatePalette( image, 16 );
+ // create dithering routine
+ FloydSteinbergColorDithering dithering = new FloydSteinbergColorDithering( );
+ dithering.ColorTable = colorTable;
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ xxx
+ xxxxx
+ xxxxxxx
+ xxxxxxx
+ xxxxxxx
+ xxxxx
+ xxx
+
+
+ // create corners detector's instance
+ SusanCornersDetector scd = new SusanCornersDetector( );
+ // process image searching for corners
+ List<IntPoint> corners = scd.ProcessImage( image );
+ // process points
+ foreach ( IntPoint corner in corners )
+ {
+ // ...
+ }
+
+
+ // create filter - rotate for 30 degrees keeping original image size
+ RotateBilinear filter = new RotateBilinear( 30, true );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ WaterWave filter = new WaterWave( );
+ filter.HorizontalWavesCount = 10;
+ filter.HorizontalWavesAmplitude = 5;
+ filter.VerticalWavesCount = 3;
+ filter.VerticalWavesAmplitude = 15;
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create corner detector's instance
+ SusanCornersDetector scd = new SusanCornersDetector( );
+ // create corner maker filter
+ CornersMarker filter = new CornersMarker( scd, Color.Red );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ PointedMeanFloodFill filter = new PointedMeanFloodFill( );
+ // configre the filter
+ filter.Tolerance = Color.FromArgb( 150, 92, 92 );
+ filter.StartingPoint = new IntPoint( 150, 100 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ ColorFiltering filter = new ColorFiltering( );
+ // set color ranges to keep
+ filter.Red = new IntRange( 100, 255 );
+ filter.Green = new IntRange( 0, 75 );
+ filter.Blue = new IntRange( 0, 75 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ | * | 7 | 5 |
+ | 3 | 5 | 7 | 5 | 3 |
+ | 1 | 3 | 5 | 3 | 1 |
+
+ / 48
+
+
+
+ // create color image quantization routine
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // create 32 colors table
+ Color[] colorTable = ciq.CalculatePalette( image, 32 );
+ // create dithering routine
+ JarvisJudiceNinkeColorDithering dithering = new JarvisJudiceNinkeColorDithering( );
+ dithering.ColorTable = colorTable;
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ // create filter
+ SimpleSkeletonization filter = new SimpleSkeletonization( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ ConnectedComponentsLabeling filter = new ConnectedComponentsLabeling( );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+ // check objects count
+ int objectCount = filter.ObjectCount;
+
+
+
+ // create filter
+ Morph filter = new Morph( overlayImage );
+ filter.SourcePercent = 0.75;
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // create complex image
+ ComplexImage complexImage = ComplexImage.FromBitmap( image );
+ // do forward Fourier transformation
+ complexImage.ForwardFourierTransform( );
+ // create filter
+ FrequencyFilter filter = new FrequencyFilter( new IntRange( 20, 128 ) );
+ // apply filter
+ filter.Apply( complexImage );
+ // do backward Fourier transformation
+ complexImage.BackwardFourierTransform( );
+ // get complex image as bitmat
+ Bitmap fourierImage = complexImage.ToBitmap( );
+
+
+
+ // create filter
+ ResizeBicubic filter = new ResizeBicubic( 400, 300 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // define quadrilateral's corners
+ List<IntPoint> corners = new List<IntPoint>( );
+ corners.Add( new IntPoint( 99, 99 ) );
+ corners.Add( new IntPoint( 156, 79 ) );
+ corners.Add( new IntPoint( 184, 126 ) );
+ corners.Add( new IntPoint( 122, 150 ) );
+ // create filter
+ QuadrilateralTransformation filter =
+ new QuadrilateralTransformation( corners, 200, 200 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ SaturationCorrection filter = new SaturationCorrection( -0.5f );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // define emboss kernel
+ int[,] kernel = {
+ { -2, -1, 0 },
+ { -1, 1, 1 },
+ { 0, 1, 2 } };
+ // create filter
+ Convolution filter = new Convolution( kernel );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ GrayscaleToRGB filter = new GrayscaleToRGB( );
+ // apply the filter
+ Bitmap rgbImage = filter.Apply( image );
+
+
+
+ // create the filter
+ BradleyLocalThresholding filter = new BradleyLocalThresholding( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ x y
+ I(x,y) = SUM( SUM( G(i,j) ) )
+ i=0 j=0
+
+
+
+ // create integral image
+ IntegralImage im = IntegralImage.FromBitmap( image );
+ // get pixels' mean value in the specified rectangle
+ float mean = im.GetRectangleMean( 10, 10, 20, 30 )
+
+
+ // gather statistics
+ ImageStatistics stat = new ImageStatistics( image );
+ // get red channel's histogram
+ Histogram red = stat.Red;
+ // check mean value of red channel
+ if ( red.Mean > 128 )
+ {
+ // do further processing
+ }
+
+
+ // collect statistics
+ HorizontalIntensityStatistics his = new HorizontalIntensityStatistics( sourceImage );
+ // get gray histogram (for grayscale image)
+ Histogram histogram = his.Gray;
+ // output some histogram's information
+ System.Diagnostics.Debug.WriteLine( "Mean = " + histogram.Mean );
+ System.Diagnostics.Debug.WriteLine( "Min = " + histogram.Min );
+ System.Diagnostics.Debug.WriteLine( "Max = " + histogram.Max );
+
+
+
+ // create filter
+ Median filter = new Median( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ TexturedFilter filter = new TexturedFilter( new CloudsTexture( ),
+ new HueModifier( 50 ) );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ TexturedFilter filter = new TexturedFilter( new CloudsTexture( ),
+ new GrayscaleBT709( ), new Sepia( ) );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ TopHat filter = new TopHat( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ P1 P2 P3
+ P8 x P4
+ P7 P6 P5
+
+ The corresponding pixel of the result image equals to:
+
+ max( |P1-P5|, |P2-P6|, |P3-P7|, |P4-P8| )
+
+
+ // create filter
+ DifferenceEdgeDetector filter = new DifferenceEdgeDetector( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ 1 1 1
+ 1 1 1
+ 1 1 1
+
+
+
+ // create filter
+ Mean filter = new Mean( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ LevelsLinear filter = new LevelsLinear( );
+ // set ranges
+ filter.InRed = new IntRange( 30, 230 );
+ filter.InGreen = new IntRange( 50, 240 );
+ filter.InBlue = new IntRange( 10, 210 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ SISThreshold filter = new SISThreshold( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Difference filter = new Difference( overlayImage );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // sample 1 - wrapping .NET image into unmanaged without
+ // making extra copy of image in memory
+ BitmapData imageData = image.LockBits(
+ new Rectangle( 0, 0, image.Width, image.Height ),
+ ImageLockMode.ReadWrite, image.PixelFormat );
+
+ try
+ {
+ UnmanagedImage unmanagedImage = new UnmanagedImage( imageData ) );
+ // apply several routines to the unmanaged image
+ }
+ finally
+ {
+ image.UnlockBits( imageData );
+ }
+
+
+ // sample 2 - converting .NET image into unmanaged
+ UnmanagedImage unmanagedImage = UnmanagedImage.FromManagedImage( image );
+ // apply several routines to the unmanaged image
+ ...
+ // conver to managed image if it is required to display it at some point of time
+ Bitmap managedImage = unmanagedImage.ToManagedImage( );
+
+
+ 0.2125 * Red + 0.7154 * Green + 0.0721 * Blue
+
+
+ // create texture generator
+ CloudsTexture textureGenerator = new CloudsTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+
+ // get corners of the quadrilateral
+ QuadrilateralFinder qf = new QuadrilateralFinder( );
+ List<IntPoint> corners = qf.ProcessImage( image );
+
+ // lock image to draw on it with AForge.NET's methods
+ // (or draw directly on image without locking if it is unmanaged image)
+ BitmapData data = image.LockBits( new Rectangle( 0, 0, image.Width, image.Height ),
+ ImageLockMode.ReadWrite, image.PixelFormat );
+
+ Drawing.Polygon( data, corners, Color.Red );
+ for ( int i = 0; i < corners.Count; i++ )
+ {
+ Drawing.FillRectangle( data,
+ new Rectangle( corners[i].X - 2, corners[i].Y - 2, 5, 5 ),
+ Color.FromArgb( i * 32 + 127 + 32, i * 64, i * 64 ) );
+ }
+
+ image.UnlockBits( data );
+
+
+
+ HoughLineTransformation lineTransform = new HoughLineTransformation( );
+ // apply Hough line transofrm
+ lineTransform.ProcessImage( sourceImage );
+ Bitmap houghLineImage = lineTransform.ToBitmap( );
+ // get lines using relative intensity
+ HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity( 0.5 );
+
+ foreach ( HoughLine line in lines )
+ {
+ // get line's radius and theta values
+ int r = line.Radius;
+ double t = line.Theta;
+
+ // check if line is in lower part of the image
+ if ( r < 0 )
+ {
+ t += 180;
+ r = -r;
+ }
+
+ // convert degrees to radians
+ t = ( t / 180 ) * Math.PI;
+
+ // get image centers (all coordinate are measured relative
+ // to center)
+ int w2 = image.Width /2;
+ int h2 = image.Height / 2;
+
+ double x0 = 0, x1 = 0, y0 = 0, y1 = 0;
+
+ if ( line.Theta != 0 )
+ {
+ // none-vertical line
+ x0 = -w2; // most left point
+ x1 = w2; // most right point
+
+ // calculate corresponding y values
+ y0 = ( -Math.Cos( t ) * x0 + r ) / Math.Sin( t );
+ y1 = ( -Math.Cos( t ) * x1 + r ) / Math.Sin( t );
+ }
+ else
+ {
+ // vertical line
+ x0 = line.Radius;
+ x1 = line.Radius;
+
+ y0 = h2;
+ y1 = -h2;
+ }
+
+ // draw line on the image
+ Drawing.Line( sourceData,
+ new IntPoint( (int) x0 + w2, h2 - (int) y0 ),
+ new IntPoint( (int) x1 + w2, h2 - (int) y1 ),
+ Color.Red );
+ }
+
+
+
+ HoughLineTransformation lineTransform = new HoughLineTransformation( );
+ // apply Hough line transofrm
+ lineTransform.ProcessImage( sourceImage );
+ Bitmap houghLineImage = lineTransform.ToBitmap( );
+ // get lines using relative intensity
+ HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity( 0.5 );
+
+ foreach ( HoughLine line in lines )
+ {
+ // ...
+ }
+
+
+
+ // define quadrilateral's corners
+ List<IntPoint> corners = new List<IntPoint>( );
+ corners.Add( new IntPoint( 99, 99 ) );
+ corners.Add( new IntPoint( 156, 79 ) );
+ corners.Add( new IntPoint( 184, 126 ) );
+ corners.Add( new IntPoint( 122, 150 ) );
+ // create filter
+ SimpleQuadrilateralTransformation filter =
+ new SimpleQuadrilateralTransformation( corners, 200, 200 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ Texturer filter = new Texturer( new TextileTexture( ), 0.3, 0.7 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ HSLLinear filter = new HSLLinear( );
+ // configure the filter
+ filter.InLuminance = new Range( 0, 0.85f );
+ filter.OutSaturation = new Range( 0.25f, 1 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ 1 2 3 2 1
+ 2 4 5 4 2
+ 3 5 6 5 3
+ 2 4 5 4 2
+ 1 2 3 2 1
+
+
+
+ // create filter
+ Blur filter = new Blur( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ SimplePosterization filter = new SimplePosterization( );
+ // process image
+ filter.ApplyInPlace( sourceImage );
+
+
+
+ | * | 7 | 5 |
+ | 3 | 5 | 7 | 5 | 3 |
+ | 1 | 3 | 5 | 3 | 1 |
+
+ / 48
+
+
+
+ // create filter
+ JarvisJudiceNinkeDithering filter = new JarvisJudiceNinkeDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create the color quantization algorithm
+ IColorQuantizer quantizer = new MedianCutQuantizer( );
+ // process colors (taken from image for example)
+ for ( int i = 0; i < pixelsToProcess; i++ )
+ {
+ quantizer.AddColor( /* pixel color */ );
+ }
+ // get palette reduced to 16 colors
+ Color[] palette = quantizer.GetPalette( 16 );
+
+
+ // create texture generator
+ LabyrinthTexture textureGenerator = new LabyrinthTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+
+ // create YCbCrExtractChannel filter for channel extracting
+ YCbCrExtractChannel extractFilter = new YCbCrExtractChannel(
+ YCbCr.CbIndex );
+ // extract Cb channel
+ Bitmap cbChannel = extractFilter.Apply( image );
+ // invert the channel
+ Invert invertFilter = new Invert( );
+ invertFilter.ApplyInPlace( cbChannel );
+ // put the channel back into the source image
+ YCbCrReplaceChannel replaceFilter = new YCbCrReplaceChannel(
+ YCbCr.CbIndex, cbChannel );
+ replaceFilter.ApplyInPlace( image );
+
+
+
+ w(x, y) = exp( -1 * (Gx^2 + Gy^2) / (2 * factor^2) )
+ Gx(x, y) = (I(x + 1, y) - I(x - 1, y)) / 2
+ Gy(x, y) = (I(x, y + 1) - I(x, y - 1)) / 2
+
,
+ where
+ // create filter
+ AdaptiveSmoothing filter = new AdaptiveSmoothing( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ BlobsFiltering filter = new BlobsFiltering( );
+ // configure filter
+ filter.CoupledSizeFiltering = true;
+ filter.MinWidth = 70;
+ filter.MinHeight = 70;
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // define kernel to remove pixels on the right side of objects
+ // (pixel is removed, if there is white pixel on the left and
+ // black pixel on the right)
+ short[,] se = new short[,] {
+ { -1, -1, -1 },
+ { 1, 1, 0 },
+ { -1, -1, -1 }
+ };
+ // create filter
+ HitAndMiss filter = new HitAndMiss( se, HitAndMiss.Modes.Thinning );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ P1 P2 P3
+ P8 x P4
+ P7 P6 P5
+
+ The corresponding pixel of the result image equals to:
+
+ max( |x-P1|, |x-P2|, |x-P3|, |x-P4|,
+ |x-P5|, |x-P6|, |x-P7|, |x-P8| )
+
+
+ // create filter
+ HomogenityEdgeDetector filter = new HomogenityEdgeDetector( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter with kernel size equal to 11
+ // and Gaussia sigma value equal to 4.0
+ GaussianSharpen filter = new GaussianSharpen( 4, 11 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Merge filter = new Merge( overlayImage );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // create instance of skew checker
+ DocumentSkewChecker skewChecker = new DocumentSkewChecker( );
+ // get documents skew angle
+ double angle = skewChecker.GetSkewAngle( documentImage );
+ // create rotation filter
+ RotateBilinear rotationFilter = new RotateBilinear( -angle );
+ rotationFilter.FillColor = Color.White;
+ // rotate image applying the filter
+ Bitmap rotatedImage = rotationFilter.Apply( documentImage );
+
+
+
+ // create texture generator
+ WoodTexture textureGenerator = new WoodTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+
+ // create filter
+ YCbCrExtractChannel filter = new YCbCrExtractChannel( YCbCr.CrIndex );
+ // apply the filter
+ Bitmap crChannel = filter.Apply( image );
+
+
+ // create filter
+ ResizeNearestNeighbor filter = new ResizeNearestNeighbor( 400, 300 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ Crop filter = new Crop( new Rectangle( 75, 75, 320, 240 ) );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ PointedColorFloodFill filter = new PointedColorFloodFill( );
+ // configure the filter
+ filter.Tolerance = Color.FromArgb( 150, 92, 92 );
+ filter.FillColor = Color.FromArgb( 255, 255, 255 );
+ filter.StartingPoint = new IntPoint( 150, 100 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ FlatFieldCorrection filter = new FlatFieldCorrection( bgImage );
+ // process image
+ filter.ApplyInPlace( sourceImage );
+
+
+
+ // create filter
+ HSLFiltering filter = new HSLFiltering( );
+ // set color ranges to keep
+ filter.Hue = new IntRange( 335, 0 );
+ filter.Saturation = new Range( 0.6f, 1 );
+ filter.Luminance = new Range( 0.1f, 1 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ HSLFiltering filter = new HSLFiltering( );
+ // configure the filter
+ filter.Hue = new IntRange( 340, 20 );
+ filter.UpdateLuminance = false;
+ filter.UpdateHue = false;
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter with kernel size equal to 11
+ // and Gaussia sigma value equal to 4.0
+ GaussianBlur filter = new GaussianBlur( 4, 11 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ 0 -1 0
+ -1 4 -1
+ 0 -1 0
+
+
+
+ // create filter
+ Edges filter = new Edges( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ OtsuThreshold filter = new OtsuThreshold( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+ // check threshold value
+ byte t = filter.ThresholdValue;
+ // ...
+
+
+
+ // create filter
+ IterativeThreshold filter = new IterativeThreshold( 2, 128 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ ThresholdedEuclideanDifference filter = new ThresholdedEuclideanDifference( 60 );
+ // apply the filter
+ filter.OverlayImage = backgroundImage;
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // create filter
+ Intersect filter = new Intersect( overlayImage );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ | * | 5 | 3 |
+ | 2 | 4 | 5 | 4 | 2 |
+ | 2 | 3 | 2 |
+
+ / 32
+
+
+
+ // create dithering routine (use default color table)
+ SierraColorDithering dithering = new SierraColorDithering( );
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ // create texture generator
+ WoodTexture textureGenerator = new WoodTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+ // create texture generator
+ TextileTexture textureGenerator = new TextileTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+
+ // create an instance of blob counter algorithm
+ RecursiveBlobCounter bc = new RecursiveBlobCounter( );
+ // process binary image
+ bc.ProcessImage( image );
+ Rectangle[] rects = bc.GetObjectsRectangles( );
+ // process blobs
+ foreach ( Rectangle rect in rects )
+ {
+ // ...
+ }
+
+
+ // create an instance of blob counter algorithm
+ BlobCounterBase bc = new ...
+ // set filtering options
+ bc.FilterBlobs = true;
+ bc.MinWidth = 5;
+ bc.MinHeight = 5;
+ // process binary image
+ bc.ProcessImage( image );
+ Blob[] blobs = bc.GetObjects( image, false );
+ // process blobs
+ foreach ( Blob blob in blobs )
+ {
+ // ...
+ // blob.Rectangle - blob's rectangle
+ // blob.Image - blob's image
+ }
+
+
+ // create blob counter and process image
+ BlobCounter bc = new BlobCounter( sourceImage );
+ // specify sort order
+ bc.ObjectsOrder = ObjectsOrder.Size;
+ // get objects' information (blobs without image)
+ Blob[] blobs = bc.GetObjectInformation( );
+ // process blobs
+ foreach ( Blob blob in blobs )
+ {
+ // check blob's properties
+ if ( blob.Rectangle.Width > 50 )
+ {
+ // the blob looks interesting, let's extract it
+ bc.ExtractBlobsImage( sourceImage, blob );
+ }
+ }
+
+
+ // gather statistics
+ ImageStatisticsHSL stat = new ImageStatisticsHSL( image );
+ // get saturation channel's histogram
+ ContinuousHistogram saturation = stat.Saturation;
+ // check mean value of saturation channel
+ if ( saturation.Mean > 0.5 )
+ {
+ // do further processing
+ }
+
+
+ // create and configure the filter
+ FillHoles filter = new FillHoles( );
+ filter.MaxHoleHeight = 20;
+ filter.MaxHoleWidth = 20;
+ filter.CoupledSizeFiltering = false;
+ // apply the filter
+ Bitmap result = filter.Apply( image );
+
+
+
+ // create filter
+ CanvasMove filter = new CanvasMove( new IntPoint( -50, -50 ), Color.Green );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // extract red channel
+ ExtractChannel extractFilter = new ExtractChannel( RGB.R );
+ Bitmap channel = extractFilter.Apply( image );
+ // threshold channel
+ Threshold thresholdFilter = new Threshold( 230 );
+ thresholdFilter.ApplyInPlace( channel );
+ // put the channel back
+ ReplaceChannel replaceFilter = new ReplaceChannel( RGB.R, channel );
+ replaceFilter.ApplyInPlace( image );
+
+
+
+ // create grayscale filter (BT709)
+ Grayscale filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
+ // apply the filter
+ Bitmap grayImage = filter.Apply( image );
+
+
+
+ // apply the filter
+ Bitmap grayImage = Grayscale.CommonAlgorithms.BT709.Apply( image );
+
+
+ // apply the filter
+ Bitmap grayImage = Grayscale.CommonAlgorithms.RMY.Apply( image );
+
+
+ // apply the filter
+ Bitmap grayImage = Grayscale.CommonAlgorithms.Y.Apply( image );
+
+
+ // create filter
+ Threshold filter = new Threshold( 100 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ | * | 8 | 4 |
+ | 2 | 4 | 8 | 4 | 2 |
+
+ / 32
+
+
+
+ // create color image quantization routine
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // create 8 colors table
+ Color[] colorTable = ciq.CalculatePalette( image, 8 );
+ // create dithering routine
+ BurkesColorDithering dithering = new BurkesColorDithering( );
+ dithering.ColorTable = colorTable;
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ // create corner detector's instance
+ MoravecCornersDetector mcd = new MoravecCornersDetector( );
+ // process image searching for corners
+ List<IntPoint> corners = scd.ProcessImage( image );
+ // process points
+ foreach ( IntPoint corner in corners )
+ {
+ // ...
+ }
+
+
+ // create filter
+ Mirror filter = new Mirror( false, true );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create the filter
+ MaskedFilter maskedFilter = new MaskedFilter( new Sepia( ), maskImage );
+ // apply the filter
+ maskedFilter.ApplyInPlace( image );
+
+
+
+ byte[,] mask = new byte[480, 640];
+
+
+ // create filter
+ Jitter filter = new Jitter( 4 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ CanvasFill filter = new CanvasFill( new Rectangle(
+ 5, 5, image.Width - 10, image.Height - 10 ), Color.Red );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+ // create filter
+ HistogramEqualization filter = new HistogramEqualization( );
+ // process image
+ filter.ApplyInPlace( sourceImage );
+
+
+
+ // create filter
+ ExtractChannel filter = new ExtractChannel( RGB.G );
+ // apply the filter
+ Bitmap channelImage = filter.Apply( image );
+
+
+
+ | * | 7 |
+ | 3 | 5 | 1 |
+
+ / 16
+
+
+
+ // create filter
+ FloydSteinbergDithering filter = new FloydSteinbergDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ Bitmap image = AForge.Imaging.Image.FromFile( "test.jpg" );
+
+
+ // create filter
+ YCbCrLinear filter = new YCbCrLinear( );
+ // configure the filter
+ filter.InCb = new Range( -0.276f, 0.163f );
+ filter.InCr = new Range( -0.202f, 0.500f );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ ResizeBilinear filter = new ResizeBilinear( 400, 300 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ OilPainting filter = new OilPainting( 15 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ r = R / (R + G + B ),
+ g = G / (R + G + B ),
+ b = B / (R + G + B ),
+
+ where R, G and B are components of RGB color space and
+ r, g and b are components of normalized RGB color space.
+
+ // create filter
+ ExtractNormalizedRGBChannel filter = new ExtractNormalizedRGBChannel( RGB.G );
+ // apply the filter
+ Bitmap channelImage = filter.Apply( image );
+
+
+
+ |G| = |Gx| + |Gy] ,
+
+ where Gx and Gy are calculate utilizing Sobel convolution kernels:
+
+ Gx Gy
+ -1 0 +1 +1 +2 +1
+ -2 0 +2 0 0 0
+ -1 0 +1 -1 -2 -1
+
+ Using the above kernel the approximated magnitude for pixel x is calculate using
+ the next equation:
+
+ P1 P2 P3
+ P8 x P4
+ P7 P6 P5
+
+ |G| = |P1 + 2P2 + P3 - P7 - 2P6 - P5| +
+ |P3 + 2P4 + P5 - P1 - 2P8 - P7|
+
+
+ // create filter
+ SobelEdgeDetector filter = new SobelEdgeDetector( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ 0 -1 0
+ -1 5 -1
+ 0 -1 0
+
+
+
+ // create filter
+ Sharpen filter = new Sharpen( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ Y = 0.299 * R + 0.587 * G + 0.114 * B
+ I = 0.596 * R - 0.274 * G - 0.322 * B
+ Q = 0.212 * R - 0.523 * G + 0.311 * B
+
+
+ I = 51
+ Q = 0
+
+
+ R = 1.0 * Y + 0.956 * I + 0.621 * Q
+ G = 1.0 * Y - 0.272 * I - 0.647 * Q
+ B = 1.0 * Y - 1.105 * I + 1.702 * Q
+
+
+ // create filter
+ Sepia filter = new Sepia( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Invert filter = new Invert( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ EuclideanColorFiltering filter = new EuclideanColorFiltering( );
+ // set center colol and radius
+ filter.CenterColor = new RGB( 215, 30, 30 );
+ filter.Radius = 100;
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create template matching algorithm's instance
+ ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching( 0.9f );
+ // find all matchings with specified above similarity
+ TemplateMatch[] matchings = tm.ProcessImage( sourceImage, templateImage );
+ // highlight found matchings
+ BitmapData data = sourceImage.LockBits(
+ new Rectangle( 0, 0, sourceImage.Width, sourceImage.Height ),
+ ImageLockMode.ReadWrite, sourceImage.PixelFormat );
+ foreach ( TemplateMatch m in matchings )
+ {
+ Drawing.Rectangle( data, m.Rectangle, Color.White );
+ // do something else with matching
+ }
+ sourceImage.UnlockBits( data );
+
+
+
+ // create template matching algorithm's instance
+ // use zero similarity to make sure algorithm will provide anything
+ ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching( 0 );
+ // compare two images
+ TemplateMatch[] matchings = tm.ProcessImage( image1, image2 );
+ // check similarity level
+ if ( matchings[0].Similarity > 0.95f )
+ {
+ // do something with quite similar images
+ }
+
+
+
+ // collect reference points using corners detector (for example)
+ SusanCornersDetector scd = new SusanCornersDetector( 30, 18 );
+ List<IntPoint> points = scd.ProcessImage( sourceImage );
+
+ // create block matching algorithm's instance
+ ExhaustiveBlockMatching bm = new ExhaustiveBlockMatching( 8, 12 );
+ // process images searching for block matchings
+ List<BlockMatch> matches = bm.ProcessImage( sourceImage, points, searchImage );
+
+ // draw displacement vectors
+ BitmapData data = sourceImage.LockBits(
+ new Rectangle( 0, 0, sourceImage.Width, sourceImage.Height ),
+ ImageLockMode.ReadWrite, sourceImage.PixelFormat );
+
+ foreach ( BlockMatch match in matches )
+ {
+ // highlight the original point in source image
+ Drawing.FillRectangle( data,
+ new Rectangle( match.SourcePoint.X - 1, match.SourcePoint.Y - 1, 3, 3 ),
+ Color.Yellow );
+ // draw line to the point in search image
+ Drawing.Line( data, match.SourcePoint, match.MatchPoint, Color.Red );
+
+ // check similarity
+ if ( match.Similarity > 0.98f )
+ {
+ // process block with high similarity somehow special
+ }
+ }
+
+ sourceImage.UnlockBits( data );
+
+
+
+ // create complex image
+ ComplexImage complexImage = ComplexImage.FromBitmap( image );
+ // do forward Fourier transformation
+ complexImage.ForwardFourierTransform( );
+ // get complex image as bitmat
+ Bitmap fourierImage = complexImage.ToBitmap( );
+
+
+
+ // create color image quantization routine
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // create 256 colors table
+ Color[] colorTable = ciq.CalculatePalette( image, 256 );
+ // create dithering routine
+ OrderedColorDithering dithering = new OrderedColorDithering( );
+ dithering.ColorTable = colorTable;
+ // apply the dithering routine
+ Bitmap newImage = dithering.Apply( image );
+
+
+
+ 2 18 6 22
+ 26 10 30 14
+ 8 24 4 20
+ 32 16 28 12
+
+
+ HoughCircleTransformation circleTransform = new HoughCircleTransformation( 35 );
+ // apply Hough circle transform
+ circleTransform.ProcessImage( sourceImage );
+ Bitmap houghCirlceImage = circleTransform.ToBitmap( );
+ // get circles using relative intensity
+ HoughCircle[] circles = circleTransform.GetCirclesByRelativeIntensity( 0.5 );
+
+ foreach ( HoughCircle circle in circles )
+ {
+ // ...
+ }
+
+
+
+ // define quadrilateral's corners
+ List<IntPoint> corners = new List<IntPoint>( );
+ corners.Add( new IntPoint( 99, 99 ) );
+ corners.Add( new IntPoint( 156, 79 ) );
+ corners.Add( new IntPoint( 184, 126 ) );
+ corners.Add( new IntPoint( 122, 150 ) );
+ // create filter
+ BackwardQuadrilateralTransformation filter =
+ new BackwardQuadrilateralTransformation( sourceImage, corners );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // build warp map
+ int width = image.Width;
+ int height = image.Height;
+
+ IntPoint[,] warpMap = new IntPoint[height, width];
+
+ int size = 8;
+ int maxOffset = -size + 1;
+
+ for ( int y = 0; y < height; y++ )
+ {
+ for ( int x = 0; x < width; x++ )
+ {
+ int dx = ( x / size ) * size - x;
+ int dy = ( y / size ) * size - y;
+
+ if ( dx + dy <= maxOffset )
+ {
+ dx = ( x / size + 1 ) * size - 1 - x;
+ }
+
+ warpMap[y, x] = new IntPoint( dx, dy );
+ }
+ }
+ // create filter
+ ImageWarp filter = new ImageWarp( warpMap );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ HorizontalRunLengthSmoothing hrls = new HorizontalRunLengthSmoothing( 32 );
+ // apply the filter
+ hrls.ApplyInPlace( image );
+
+
+
+ // create filter
+ ExtractBiggestBlob filter = new ExtractBiggestBlob( );
+ // apply the filter
+ Bitmap biggestBlobsImage = filter.Apply( image );
+
+
+
+ // create an instance of blob counter algorithm
+ BlobCounter bc = new BlobCounter( );
+ // process binary image
+ bc.ProcessImage( image );
+ Rectangle[] rects = bc.GetObjectsRectangles( );
+ // process blobs
+ foreach ( Rectangle rect in rects )
+ {
+ // ...
+ }
+
+
+ // gather statistics
+ ImageStatisticsYCbCr stat = new ImageStatisticsYCbCr( image );
+ // get Y channel's histogram
+ ContinuousHistogram y = stat.Y;
+ // check mean value of Y channel
+ if ( y.Mean > 0.5 )
+ {
+ // do further processing
+ }
+
+
+ // create filter
+ YCbCrFiltering filter = new YCbCrFiltering( );
+ // set color ranges to keep
+ filter.Cb = new Range( -0.2f, 0.0f );
+ filter.Cr = new Range( 0.26f, 0.5f );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ BilateralSmoothing filter = new BilateralSmoothing( );
+ filter.KernelSize = 7;
+ filter.SpatialFactor = 10;
+ filter.ColorFactor = 60;
+ filter.ColorPower = 0.5;
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Opening filter = new Opening( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ // create filter
+ Dilatation filter = new Dilatation( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ // create filter, which is binarization sequence
+ FiltersSequence filter = new FiltersSequence(
+ new GrayscaleBT709( ),
+ new Threshold( )
+ );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+ // create filter
+ ContrastCorrection filter = new ContrastCorrection( 15 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create texture generator
+ MarbleTexture textureGenerator = new MarbleTexture( );
+ // generate new texture
+ float[,] texture = textureGenerator.Generate( 320, 240 );
+ // convert it to image to visualize
+ Bitmap textureImage = TextureTools.ToBitmap( texture );
+
+
+
+ // create filter
+ TransformToPolar filter = new TransformToPolar( );
+ filter.OffsetAngle = 0;
+ filter.CirlceDepth = 1;
+ filter.UseOriginalImageSize = false;
+ filter.NewSize = new Size( 200, 200 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ TransformFromPolar filter = new TransformFromPolar( );
+ filter.OffsetAngle = 0;
+ filter.CirlceDepth = 1;
+ filter.UseOriginalImageSize = false;
+ filter.NewSize = new Size( 360, 120 );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter - rotate for 30 degrees keeping original image size
+ RotateBicubic filter = new RotateBicubic( 30, true );
+ // apply the filter
+ Bitmap newImage = filter.Apply( image );
+
+
+
+ // create filter
+ VerticalRunLengthSmoothing vrls = new VerticalRunLengthSmoothing( 32 );
+ // apply the filter
+ vrls.ApplyInPlace( image );
+
+
+
+ // create filter
+ SaltAndPepperNoise filter = new SaltAndPepperNoise( 10 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create random generator
+ IRandomNumberGenerator generator = new UniformGenerator( new Range( -50, 50 ) );
+ // create filter
+ AdditiveNoise filter = new AdditiveNoise( generator );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Closing filter = new Closing( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ // create filter
+ HueModifier filter = new HueModifier( 180 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ BayerFilter filter = new BayerFilter( );
+ // apply the filter
+ Bitmap rgbImage = filter.Apply( image );
+
+
+ // create map
+ byte[] map = new byte[256];
+ for ( int i = 0; i < 256; i++ )
+ {
+ map[i] = (byte) Math.Min( 255, Math.Pow( 2, (double) i / 32 ) );
+ }
+ // create filter
+ ColorRemapping filter = new ColorRemapping( map, map, map );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create binarization matrix
+ byte[,] matrix = new byte[4, 4]
+ {
+ { 95, 233, 127, 255 },
+ { 159, 31, 191, 63 },
+ { 111, 239, 79, 207 },
+ { 175, 47, 143, 15 }
+ };
+ // create filter
+ OrderedDithering filter = new OrderedDithering( matrix );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ byte[,] matrix = new byte[4, 4]
+ {
+ { 0, 192, 48, 240 },
+ { 128, 64, 176, 112 },
+ { 32, 224, 16, 208 },
+ { 160, 96, 144, 80 }
+ };
+
+
+
+ // create filter
+ BayerDithering filter = new BayerDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // collect statistics
+ VerticalIntensityStatistics vis = new VerticalIntensityStatistics( sourceImage );
+ // get gray histogram (for grayscale image)
+ Histogram histogram = vis.Gray;
+ // output some histogram's information
+ System.Diagnostics.Debug.WriteLine( "Mean = " + histogram.Mean );
+ System.Diagnostics.Debug.WriteLine( "Min = " + histogram.Min );
+ System.Diagnostics.Debug.WriteLine( "Max = " + histogram.Max );
+
+
+
+ // create filter
+ TexturedMerge filter = new TexturedMerge( new TextileTexture( ) );
+ // create an overlay image to merge with
+ filter.OverlayImage = new Bitmap( image.Width, image.Height,
+ PixelFormat.Format24bppRgb );
+ // fill the overlay image with solid color
+ PointedColorFloodFill fillFilter = new PointedColorFloodFill( Color.DarkKhaki );
+ fillFilter.ApplyInPlace( filter.OverlayImage );
+ // apply the merge filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ TexturedMerge filter = new TexturedMerge( new CloudsTexture( ) );
+ // create 2 images with modified Hue
+ HueModifier hm1 = new HueModifier( 50 );
+ HueModifier hm2 = new HueModifier( 200 );
+ filter.OverlayImage = hm2.Apply( image );
+ hm1.ApplyInPlace( image );
+ // apply the merge filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ CanvasCrop filter = new CanvasCrop( new Rectangle(
+ 5, 5, image.Width - 10, image.Height - 10 ), Color.Red );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ Erosion filter = new Erosion( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ // create filter
+ BottomHat filter = new BottomHat( );
+ // apply the filter
+ filter.Apply( image );
+
+
+
+ // create filter
+ ContrastStretch filter = new ContrastStretch( );
+ // process image
+ filter.ApplyInPlace( sourceImage );
+
+
+
+ // create filter
+ ChannelFiltering filter = new ChannelFiltering( );
+ // set channels' ranges to keep
+ filter.Red = new IntRange( 0, 255 );
+ filter.Green = new IntRange( 100, 255 );
+ filter.Blue = new IntRange( 100, 255 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ BayerFilter filter = new BayerFilter( );
+ // apply the filter
+ Bitmap rgbImage = filter.Apply( image );
+
+
+
+ new int[2, 2] { { RGB.G, RGB.R }, { RGB.B, RGB.G } }
+
,
+ which corresponds to
+
+ G R
+ B G
+
+ pattern.
+
+ // create filter
+ MoveTowards filter = new MoveTowards( overlayImage, 20 );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // instantiate the images' color quantization class
+ ColorImageQuantizer ciq = new ColorImageQuantizer( new MedianCutQuantizer( ) );
+ // get 16 color palette for a given image
+ Color[] colorTable = ciq.CalculatePalette( image, 16 );
+
+ // ... or just reduce colors in the specified image
+ Bitmap newImage = ciq.ReduceColors( image, 16 );
+
+
+
+ // create filter
+ Pixellate filter = new Pixellate( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ byte[,] mask = new byte[480, 640];
+
+
+ // create filter
+ CannyEdgeDetector filter = new CannyEdgeDetector( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ LevelsLinear16bpp filter = new LevelsLinear16bpp( );
+ // set ranges
+ filter.InRed = new IntRange( 3000, 42000 );
+ filter.InGreen = new IntRange( 5000, 37500 );
+ filter.InBlue = new IntRange( 1000, 60000 );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+ | * | 5 | 3 |
+ | 2 | 4 | 5 | 4 | 2 |
+ | 2 | 3 | 2 |
+
+ / 32
+
+
+
+ // create filter
+ SierraDithering filter = new SierraDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ | * | 8 | 4 |
+ | 2 | 4 | 8 | 4 | 2 |
+
+ / 32
+
+
+
+ // create filter
+ BurkesDithering filter = new BurkesDithering( );
+ // apply the filter
+ filter.ApplyInPlace( image );
+
+
+
+ // create filter
+ ThresholdedDifference filter = new ThresholdedDifference( 60 );
+ // apply the filter
+ filter.OverlayImage = backgroundImage;
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // create filter
+ Subtract filter = new Subtract( overlayImage );
+ // apply the filter
+ Bitmap resultImage = filter.Apply( sourceImage );
+
+
+
+ // create filter
+ StereoAnaglyph filter = new StereoAnaglyph( );
+ // set right image as overlay
+ filter.Overlay = rightImage
+ // apply the filter (providing left image)
+ Bitmap resultImage = filter.Apply( leftImage );
+
+
+
+ // enumerate video devices
+ videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );
+ // list devices
+ foreach ( FilterInfo device in videoDevices )
+ {
+ // ...
+ }
+
+
+ // enumerate video devices
+ videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );
+ // create video source
+ VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
+ // set NewFrame event handler
+ videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
+ // start the video source
+ videoSource.Start( );
+ // ...
+ // signal to stop when you no longer need capturing
+ videoSource.SignalToStop( );
+ // ...
+
+ private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
+ {
+ // get new frame
+ Bitmap bitmap = eventArgs.Frame;
+ // process the frame
+ }
+
+
+ // create video source
+ FileVideoSource videoSource = new FileVideoSource( fileName );
+ // set NewFrame event handler
+ videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
+ // start the video source
+ videoSource.Start( );
+ // ...
+ // signal to stop
+ videoSource.SignalToStop( );
+ // ...
+
+ // New frame event handler, which is invoked on each new available video frame
+ private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
+ {
+ // get new frame
+ Bitmap bitmap = eventArgs.Frame;
+ // process the frame
+ }
+
+
+ // usage of AsyncVideoSource is the same as usage of any
+ // other video source class, so code change is very little
+
+ // create nested video source, for example JPEGStream
+ JPEGStream stream = new JPEGStream( "some url" );
+ // create async video source
+ AsyncVideoSource asyncSource = new AsyncVideoSource( stream );
+ // set NewFrame event handler
+ asyncSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
+ // start the video source
+ asyncSource.Start( );
+ // ...
+
+ private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
+ {
+ // get new frame
+ Bitmap bitmap = eventArgs.Frame;
+ // process the frame
+ }
+
+
+ // get entire desktop area size
+ Rectangle screenArea = Rectangle.Empty;
+ foreach ( System.Windows.Forms.Screen screen in
+ System.Windows.Forms.Screen.AllScreens )
+ {
+ screenArea = Rectangle.Union( screenArea, screen.Bounds );
+ }
+
+ // create screen capture video source
+ ScreenCaptureStream stream = new ScreenCaptureStream( screenArea );
+
+ // set NewFrame event handler
+ stream.NewFrame += new NewFrameEventHandler( video_NewFrame );
+
+ // start the video source
+ stream.Start( );
+
+ // ...
+ // signal to stop
+ stream.SignalToStop( );
+ // ...
+
+ private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
+ {
+ // get new frame
+ Bitmap bitmap = eventArgs.Frame;
+ // process the frame
+ }
+
+
+ // create MJPEG video source
+ MJPEGStream stream = new MJPEGStream( "some url" );
+ // set event handlers
+ stream.NewFrame += new NewFrameEventHandler( video_NewFrame );
+ // start the video source
+ stream.Start( );
+ // ...
+
+
+
+ <configuration>
+ <system.net>
+ <settings>
+ <httpWebRequest useUnsafeHeaderParsing="true" />
+ </settings>
+ </system.net>
+ </configuration>
+
+
+ // create JPEG video source
+ JPEGStream stream = new JPEGStream( "some url" );
+ // set NewFrame event handler
+ stream.NewFrame += new NewFrameEventHandler( video_NewFrame );
+ // start the video source
+ stream.Start( );
+ // ...
+ // signal to stop
+ stream.SignalToStop( );
+ // ...
+
+ private void video_NewFrame( object sender, NewFrameEventArgs eventArgs )
+ {
+ // get new frame
+ Bitmap bitmap = eventArgs.Frame;
+ // process the frame
+ }
+
+
+
+ <configuration>
+ <system.net>
+ <settings>
+ <httpWebRequest useUnsafeHeaderParsing="true" />
+ </settings>
+ </system.net>
+ </configuration>
+
+
+ // assigning coordinates in the constructor
+ IntPoint p1 = new IntPoint( 10, 20 );
+ // creating a point and assigning coordinates later
+ IntPoint p2;
+ p2.X = 30;
+ p2.Y = 40;
+ // calculating distance between two points
+ float distance = p1.DistanceTo( p2 );
+
+
+ // expression written in polish notation
+ string expression = "2 $0 / 3 $1 * +";
+ // variables for the expression
+ double[] vars = new double[] { 3, 4 };
+ // expression evaluation
+ double result = PolishExpression.Evaluate( expression, vars );
+
+
+ // create [0.25, 1.5] range
+ DoubleRange range1 = new DoubleRange( 0.25, 1.5 );
+ // create [1.00, 2.25] range
+ DoubleRange range2 = new DoubleRange( 1.00, 2.25 );
+ // check if values is inside of the first range
+ if ( range1.IsInside( 0.75 ) )
+ {
+ // ...
+ }
+ // check if the second range is inside of the first range
+ if ( range1.IsInside( range2 ) )
+ {
+ // ...
+ }
+ // check if two ranges overlap
+ if ( range1.IsOverlapping( range2 ) )
+ {
+ // ...
+ }
+
+
+ // assigning coordinates in the constructor
+ Point p1 = new Point( 10, 20 );
+ // creating a point and assigning coordinates later
+ Point p2;
+ p2.X = 30;
+ p2.Y = 40;
+ // calculating distance between two points
+ float distance = p1.DistanceTo( p2 );
+
+
+ // create [1, 10] range
+ IntRange range1 = new IntRange( 1, 10 );
+ // create [5, 15] range
+ IntRange range2 = new IntRange( 5, 15 );
+ // check if values is inside of the first range
+ if ( range1.IsInside( 7 ) )
+ {
+ // ...
+ }
+ // check if the second range is inside of the first range
+ if ( range1.IsInside( range2 ) )
+ {
+ // ...
+ }
+ // check if two ranges overlap
+ if ( range1.IsOverlapping( range2 ) )
+ {
+ // ...
+ }
+
+
+ // create [0.25, 1.5] range
+ Range range1 = new Range( 0.25f, 1.5f );
+ // create [1.00, 2.25] range
+ Range range2 = new Range( 1.00f, 2.25f );
+ // check if values is inside of the first range
+ if ( range1.IsInside( 0.75f ) )
+ {
+ // ...
+ }
+ // check if the second range is inside of the first range
+ if ( range1.IsInside( range2 ) )
+ {
+ // ...
+ }
+ // check if two ranges overlap
+ if ( range1.IsOverlapping( range2 ) )
+ {
+ // ...
+ }
+
+
+ Parallel.For( 0, 20, delegate( int i )
+ // which is equivalent to
+ // for ( int i = 0; i < 20; i++ )
+ {
+ System.Diagnostics.Debug.WriteLine( "Iteration: " + i );
+ // ...
+ } );
+
+
+ // assigning coordinates in the constructor
+ DoublePoint p1 = new DoublePoint( 10, 20 );
+ // creating a point and assigning coordinates later
+ DoublePoint p2;
+ p2.X = 30;
+ p2.Y = 40;
+ // calculating distance between two points
+ double distance = p1.DistanceTo( p2 );
+
+ + |-1 0 1| + |-2 0 2| + |-1 0 1|+ kernel and the second one corresponds to +
+ |-1 -2 -1| + | 0 0 0| + | 1 2 1|+ or +
+ | 1 2 1| + | 0 0 0| + |-1 -2 -1|+ kernel, depending on the image origin (origin field of IplImage structure). No scaling is done, so the destination image usually has larger by absolute value numbers than the source image. To avoid overflow, the function requires 16-bit destination image if the source image is 8-bit. The result can be converted back to 8-bit using cvConvertScale or cvConvertScaleAbs functions. Besides 8-bit images the function can process 32-bit floating-point images. Both source and destination must be single-channel images of equal size or ROI size +