Accord.Imaging.Filters.Logarithm.ProcessFilter C# (CSharp) Method

ProcessFilter() protected method

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage image ) : void
image Accord.Imaging.UnmanagedImage Source image data.
return void
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int width = image.Width;
            int height = image.Height;
            PixelFormat format = image.PixelFormat;
            int pixelSize = System.Drawing.Bitmap.GetPixelFormatSize(format) / 8;

            int lineWidth = width * pixelSize;

            int srcStride = image.Stride;
            int srcOffset = srcStride - lineWidth;
            double scale = 255.0 / Math.Log(255);

            byte* src = (byte*)image.ImageData.ToPointer();


            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < lineWidth; x++, src++)
                {
                    if (*src > 0)
                    {
                        double v = Math.Log(*src) * scale;

                        *src = (byte)(v > 0 ? (v < 255 ? v : 255) : 0);
                    }

                }

                src += srcOffset;
            }
        }
    }