Example #1
0
        /// <summary>Process the filter on the specified image.</summary>
        /// <param name="image">Source image data.</param>
        protected override unsafe void ProcessFilter(UnmanagedImage 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++)
            {
                int y1 = (y - radius < 0) ? 0 : y - radius;
                int y2 = (y + radius > heightM1) ? heightM1 : y + radius;
                for (int x = 0; x < width; x++, ptr++)
                {
                    int   x1   = (x - radius < 0) ? 0 : x - radius;
                    int   x2   = (x + radius > widthM1) ? widthM1 : x + radius;
                    float mean = im.GetRectangleMeanUnsafe(x1, y1, x2, y2);
                    *     ptr  = (byte)((mean < upperLimit && *ptr < (int)(mean * avgBrightnessPart)) ? 0 : 255);
                }
                ptr += offset;
            }
        }
Example #2
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        ///
        /// <param name="image">Source image data.</param>
        ///
        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 = (byte) ( im.GetRectangleMeanUnsafe( x1, y1, x2, y2 ) * 255);
                    ptr[RGB.R] = ptr[RGB.R] = ptr[RGB.R] = (byte)(im.GetRectangleMeanUnsafe(x1, y1, x2, y2));
                }

                ptr += offset;
            }
        }
Example #3
0
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            IntegralImage image2 = IntegralImage.FromBitmap(image);
            int           width  = image.Width;
            int           height = image.Height;
            int           num3   = width - 1;
            int           num4   = height - 1;
            int           num5   = image.Stride - width;
            int           num6   = this.windowSize / 2;
            float         num7   = 1f - this.pixelBrightnessDifferenceLimit;
            byte *        numPtr = (byte *)image.ImageData.ToPointer();

            for (int i = 0; i < height; i++)
            {
                int num9  = i - num6;
                int num10 = i + num6;
                if (num9 < 0)
                {
                    num9 = 0;
                }
                if (num10 > num4)
                {
                    num10 = num4;
                }
                int num11 = 0;
                while (num11 < width)
                {
                    int num12 = num11 - num6;
                    int num13 = num11 + num6;
                    if (num12 < 0)
                    {
                        num12 = 0;
                    }
                    if (num13 > num3)
                    {
                        num13 = num3;
                    }
                    numPtr[0] = (numPtr[0] < ((int)(image2.GetRectangleMeanUnsafe(num12, num9, num13, num10) * num7))) ? ((byte)0) : ((byte)0xff);
                    num11++;
                    numPtr++;
                }
                numPtr += num5;
            }
        }
Example #4
0
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            IntegralImage integralImage = IntegralImage.FromBitmap(image);
            int           width         = image.Width;
            int           height        = image.Height;
            int           num           = width - 1;
            int           num2          = height - 1;
            int           num3          = image.Stride - width;
            int           num4          = windowSize / 2;
            float         num5          = 1f - pixelBrightnessDifferenceLimit;
            byte *        ptr           = (byte *)image.ImageData.ToPointer();

            for (int i = 0; i < height; i++)
            {
                int num6 = i - num4;
                int num7 = i + num4;
                if (num6 < 0)
                {
                    num6 = 0;
                }
                if (num7 > num2)
                {
                    num7 = num2;
                }
                int num8 = 0;
                while (num8 < width)
                {
                    int num9  = num8 - num4;
                    int num10 = num8 + num4;
                    if (num9 < 0)
                    {
                        num9 = 0;
                    }
                    if (num10 > num)
                    {
                        num10 = num;
                    }
                    *ptr = (byte)((*ptr >= (int)(integralImage.GetRectangleMeanUnsafe(num9, num6, num10, num7) * num5)) ? 255 : 0);
                    num8++;
                    ptr++;
                }
                ptr += num3;
            }
        }
Example #5
0
        /// <summary>
        /// Process the filter on the specified image.
        ///
        /// </summary>
        /// <param name="image">Source image data.</param>
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            IntegralImage integralImage = IntegralImage.FromBitmap(image);
            int           width         = image.Width;
            int           height        = image.Height;
            int           num1          = width - 1;
            int           num2          = height - 1;
            int           num3          = image.Stride - width;
            int           num4          = _windowSize / 2;
            float         num5          = 1f - _pixelBrightnessDifferenceLimit;
            byte *        numPtr        = (byte *)image.ImageData.ToPointer();

            for (int index = 0; index < height; ++index)
            {
                int y1 = index - num4;
                int y2 = index + num4;
                if (y1 < 0)
                {
                    y1 = 0;
                }
                if (y2 > num2)
                {
                    y2 = num2;
                }
                int num6 = 0;
                while (num6 < width)
                {
                    int x1 = num6 - num4;
                    int x2 = num6 + num4;
                    if (x1 < 0)
                    {
                        x1 = 0;
                    }
                    if (x2 > num1)
                    {
                        x2 = num1;
                    }
                    *numPtr = (int)*numPtr < (int)((double)integralImage.GetRectangleMeanUnsafe(x1, y1, x2, y2) * (double)num5) ? (byte)0 : byte.MaxValue;
                    ++num6;
                    ++numPtr;
                }
                numPtr += num3;
            }
        }