public static unsafe IntegralImage FromBitmap(UnmanagedImage image) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new ArgumentException("Source image can be graysclae (8 bpp indexed) image only."); } int width = image.Width; int height = image.Height; int num3 = image.Stride - width; IntegralImage image2 = new IntegralImage(width, height); uint[,] integralImage = image2.integralImage; byte *numPtr = (byte *)image.ImageData.ToPointer(); for (int i = 1; i <= height; i++) { uint num5 = 0; int num6 = 1; while (num6 <= width) { num5 += numPtr[0]; integralImage[i, num6] = num5 + integralImage[i - 1, num6]; num6++; numPtr++; } numPtr += num3; } return(image2); }
public unsafe static IntegralImage FromBitmap(UnmanagedImage image) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new ArgumentException("Source image can be graysclae (8 bpp indexed) image only."); } int num = image.Width; int num2 = image.Height; int num3 = image.Stride - num; IntegralImage integralImage = new IntegralImage(num, num2); uint[,] array = integralImage.integralImage; byte *ptr = (byte *)image.ImageData.ToPointer(); for (int i = 1; i <= num2; i++) { uint num4 = 0u; int num5 = 1; while (num5 <= num) { num4 += *ptr; array[i, num5] = num4 + array[i - 1, num5]; num5++; ptr++; } ptr += num3; } return(integralImage); }
public static IntegralImage FromBitmap(Bitmap image) { if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new UnsupportedImageFormatException("Source image can be graysclae (8 bpp indexed) image only."); } BitmapData imageData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); IntegralImage image2 = FromBitmap(imageData); image.UnlockBits(imageData); return(image2); }
public IntegralImageTest( ) { UnmanagedImage uImage = UnmanagedImage.Create( 10, 10, PixelFormat.Format8bppIndexed ); for ( int y = 0; y < 10; y++ ) { for ( int x = 0; x < 10; x++ ) { uImage.SetPixel( x, y, ( ( x + y ) % 2 == 0 ) ? Color.FromArgb( 0, 0, 0 ) : Color.FromArgb( 1, 1, 1 ) ); } } integralImage = IntegralImage.FromBitmap( uImage ); }
/// <summary> /// Construct integral image from source grayscale image. /// </summary> /// /// <param name="image">Source unmanaged image.</param> /// /// <returns>Returns integral image.</returns> /// /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception> /// public static IntegralImage FromBitmap(UnmanagedImage image) { // check image format if (image.PixelFormat != PixelFormat.Format8bppIndexed) { throw new ArgumentException("Source image can be graysclae (8 bpp indexed) image only."); } // get source image size int width = image.Width; int height = image.Height; int offset = image.Stride - width; // create integral image IntegralImage im = new IntegralImage(width, height); uint[,] integralImage = im.integralImage; // do the job unsafe { byte *src = (byte *)image.ImageData.ToPointer( ); // for each line for (int y = 1; y <= height; y++) { uint rowSum = 0; // for each pixel for (int x = 1; x <= width; x++, src++) { rowSum += *src; integralImage[y, x] = rowSum + integralImage[y - 1, x]; } src += offset; } } return(im); }
/// <summary> /// Construct integral image from source grayscale image. /// </summary> /// /// <param name="image">Source unmanaged image.</param> /// /// <returns>Returns integral image.</returns> /// /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception> /// public static IntegralImage FromBitmap( UnmanagedImage image ) { // check image format if ( image.PixelFormat != PixelFormat.Format8bppIndexed ) { throw new ArgumentException( "Source image can be graysclae (8 bpp indexed) image only." ); } // get source image size int width = image.Width; int height = image.Height; int offset = image.Stride - width; // create integral image IntegralImage im = new IntegralImage( width, height ); uint[,] integralImage = im.integralImage; // do the job unsafe { byte* src = (byte*) image.ImageData.ToPointer( ); // for each line for ( int y = 1; y <= height; y++ ) { // for each pixel for ( int x = 1; x <= width; x++, src++ ) { integralImage[y, x] = *src + integralImage[y, x - 1] + integralImage[y - 1, x] - integralImage[y - 1, x - 1]; } src += offset; } } return im; }