AForge.Imaging.Filters.IterativeThreshold.CalculateThreshold C# (CSharp) Method

CalculateThreshold() public method

Calculate binarization threshold for the given image.

The method is used to calculate binarization threshold only. The threshold later may be applied to the image using Threshold image processing filter.

Source pixel format is not supported by the routine. It should /// 8 bpp grayscale (indexed) or 16 bpp grayscale image.
public CalculateThreshold ( Bitmap image, Rectangle rect ) : int
image System.Drawing.Bitmap Image to calculate binarization threshold for.
rect System.Drawing.Rectangle Rectangle to calculate binarization threshold for.
return int
        public int CalculateThreshold( Bitmap image, Rectangle rect )
        {
            int calculatedThreshold = 0;

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

            try
            {
                calculatedThreshold = CalculateThreshold( data, rect );
            }
            finally
            {
                // unlock image
                image.UnlockBits( data );
            }

            return calculatedThreshold;
        }

Same methods

IterativeThreshold::CalculateThreshold ( BitmapData image, Rectangle rect ) : int
IterativeThreshold::CalculateThreshold ( UnmanagedImage image, Rectangle rect ) : int