AForge.Imaging.ImageStatistics.ImageStatistics C# (CSharp) Method

ImageStatistics() public method

Initializes a new instance of the ImageStatistics class.

The mask image must be a grayscale/binary (8bpp) image of the same size as the specified source image, where black pixels (value 0) correspond to areas which should be excluded from processing. So statistics is calculated only for pixels, which are none black in the mask image.

Source pixel format is not supported. Mask image must be 8 bpp grayscale image. Mask must have the same size as the source image to get statistics for.
public ImageStatistics ( Bitmap image, Bitmap mask ) : System
image System.Drawing.Bitmap Image to gather statistics about.
mask System.Drawing.Bitmap Mask image which specifies areas to collect statistics for.
return System
        public ImageStatistics( Bitmap image, Bitmap mask )
        {
            CheckSourceFormat( image.PixelFormat );
            CheckMaskProperties( mask.PixelFormat, new Size( mask.Width, mask.Height ), new Size( image.Width, image.Height ) );

            // lock bitmap and mask data
            BitmapData imageData = image.LockBits(
                new Rectangle( 0, 0, image.Width, image.Height ),
                ImageLockMode.ReadOnly, image.PixelFormat );
            BitmapData maskData = mask.LockBits(
                new Rectangle( 0, 0, mask.Width, mask.Height ),
                ImageLockMode.ReadOnly, mask.PixelFormat );

            try
            {
                // gather statistics
                unsafe
                {
                    ProcessImage( new UnmanagedImage( imageData ), (byte*) maskData.Scan0.ToPointer( ), maskData.Stride );
                }
            }
            finally
            {
                // unlock images
                image.UnlockBits( imageData );
                mask.UnlockBits( maskData );
            }
        }

Same methods

ImageStatistics::ImageStatistics ( Bitmap image ) : System
ImageStatistics::ImageStatistics ( Bitmap image, byte mask ) : System
ImageStatistics::ImageStatistics ( UnmanagedImage image ) : System
ImageStatistics::ImageStatistics ( UnmanagedImage image, UnmanagedImage mask ) : System
ImageStatistics::ImageStatistics ( UnmanagedImage image, byte mask ) : System