protected override unsafe void ProcessFilter( UnmanagedImage image )
{
// create integral image
IntegralImage im = IntegralImage.FromBitmap( image );
int width = image.Width;
int height = image.Height;
int widthM1 = width - 1;
int heightM1 = height - 1;
int offset = image.Stride - width;
int radius = windowSize / 2;
float avgBrightnessPart = 1.0f - pixelBrightnessDifferenceLimit;
byte* ptr = (byte*) image.ImageData.ToPointer( );
for ( int y = 0; y < height; y++ )
{
// rectangle's Y coordinates
int y1 = y - radius;
int y2 = y + radius;
if ( y1 < 0 )
y1 = 0;
if ( y2 > heightM1 )
y2 = heightM1;
for ( int x = 0; x < width; x++, ptr++ )
{
// rectangle's X coordinates
int x1 = x - radius;
int x2 = x + radius;
if ( x1 < 0 )
x1 = 0;
if ( x2 > widthM1 )
x2 = widthM1;
*ptr = (byte) ( ( *ptr < (int) ( im.GetRectangleMeanUnsafe( x1, y1, x2, y2 ) * avgBrightnessPart ) ) ? 0 : 255 );
}
ptr += offset;
}
}
}