Esempio n. 1
0
        public static Bitmap Smooth(Bitmap b, int nWeight)
        {
            ConvMatrix m = new ConvMatrix(1);

            m.Pixel  = nWeight;
            m.Factor = nWeight + 8;
            return(BitmapFilter.Conv3x3(b, m));
        }
Esempio n. 2
0
        public static Bitmap MeanRemoval(Bitmap b, int nWeight)
        {
            ConvMatrix m = new ConvMatrix(-1);

            m.Pixel  = nWeight;
            m.Factor = nWeight - 8;
            return(BitmapFilter.Conv3x3(b, m));
        }
Esempio n. 3
0
        public static Bitmap Sharpen(Bitmap b, int nWeight)
        {
            ConvMatrix m = new ConvMatrix(0);

            m.Pixel  = nWeight;
            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = -2;
            m.Factor = nWeight - 8;
            return(BitmapFilter.Conv3x3(b, m));
        }
Esempio n. 4
0
        public static Bitmap EmbossLaplacian(Bitmap b)
        {
            ConvMatrix m = new ConvMatrix(-1);

            m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0;
            m.Pixel  = 4;
            m.Offset = 127;
            return(BitmapFilter.Conv3x3(b, m));
        }
Esempio n. 5
0
        public static Bitmap Contrast(Bitmap b, sbyte nContrast)
        {
            if (nContrast < -100 || nContrast > 100)
            {
                throw new ArgumentException("Contrast must be a value between -100 and 100", "nContrast");
            }

            return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.Contrast, nContrast));
        }
Esempio n. 6
0
        public static Bitmap EdgeDetectQuick(Bitmap b)
        {
            ConvMatrix m = new ConvMatrix();

            m.TopLeft    = m.TopMid = m.TopRight = -1;
            m.MidLeft    = m.Pixel = m.MidRight = 0;
            m.BottomLeft = m.BottomMid = m.BottomRight = 1;
            m.Offset     = 127;
            return(BitmapFilter.Conv3x3(b, m));
        }
Esempio n. 7
0
        public static Bitmap GausianBlur(Bitmap b, int size, float weight)
        {
            //ConvMatrix m = new ConvMatrix(1);
            //m.Pixel = nWeight;
            //m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 2;
            //m.Factor = nWeight + 12;
            //return BitmapFilter.Conv3x3(b, m);
            GausianKernel kernel = new GausianKernel(size, weight);

            return(BitmapFilter.AdvConvFilter(b, kernel.Calc(), size, 0));
        }
Esempio n. 8
0
        public static Bitmap Color(Bitmap b, int red, int green, int blue)
        {
            if (red < -255 || red > 255)
            {
                throw new ArgumentException("Color must be an integer value between -255 and 255", "red");
            }
            else if (green < -255 || green > 255)
            {
                throw new ArgumentException("Color must be an integer value between -255 and 255", "green");
            }
            else if (blue < -255 || blue > 255)
            {
                throw new ArgumentException("Color must be an integer value between -255 and 255", "blue");
            }

            return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.Color, red, green, blue));
        }
Esempio n. 9
0
        public static Bitmap Gamma(Bitmap b, double red, double green, double blue)
        {
            if (red < 0.2 || red > 5)
            {
                throw new ArgumentException("Gamma values must a double precision value between 0.2 and 5.", "red");
            }
            else if (green < .2 || green > 5)
            {
                throw new ArgumentException("Gamma values must a double precision value between 0.2 and 5.", "green");
            }
            else if (blue < .2 || blue > 5)
            {
                throw new ArgumentException("Gamma values must a double precision value between 0.2 and 5.", "blue");
            }

            return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.Gamma, red, green, blue));
        }
Esempio n. 10
0
        public static Bitmap Flip(Bitmap b, bool bHorz, bool bVert)
        {
            try
            {
                Point[,] ptFlip = new Point[b.Width, b.Height];

                int nWidth  = b.Width;
                int nHeight = b.Height;

                for (int x = 0; x < nWidth; ++x)
                {
                    for (int y = 0; y < nHeight; ++y)
                    {
                        ptFlip[x, y].X = (bHorz) ? nWidth - (x + 1) : x;
                        ptFlip[x, y].Y = (bVert) ? nHeight - (y + 1) : y;
                    }
                }
                b = BitmapFilter.OffsetFilterAbs(b, ptFlip);
            }
            catch
            { throw; }

            return(b);
        }
Esempio n. 11
0
 //***************************************************************************
 // Static Methods
 //
 public static Bitmap Invert(Bitmap b)
 {
     return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.Invert));
 }
Esempio n. 12
0
 public static Bitmap Brightness(Bitmap b, int nBrightness)
 {
     return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.Brightness, nBrightness));
 }
Esempio n. 13
0
        public static Bitmap EdgeDetectConvolution(Bitmap b, EdgeDetectionMethod nType, byte nThreshold)
        {
            ConvMatrix m = new ConvMatrix();

            // First we need to keep a copy of the original Bitmap.
            using (Bitmap bTemp = (Bitmap)b.Clone())
            {
                try
                {
                    switch (nType)
                    {
                    case EdgeDetectionMethod.Sobel:
                        m.SetAll(0);
                        m.TopLeft  = m.BottomLeft = 1;
                        m.TopRight = m.BottomRight = -1;
                        m.MidLeft  = 2;
                        m.MidRight = -2;
                        m.Offset   = 0;
                        break;

                    case EdgeDetectionMethod.Prewitt:
                        m.SetAll(0);
                        m.TopLeft  = m.MidLeft = m.BottomLeft = -1;
                        m.TopRight = m.MidRight = m.BottomRight = 1;
                        m.Offset   = 0;
                        break;

                    case EdgeDetectionMethod.Kirsh:
                        m.SetAll(-3);
                        m.Pixel   = 0;
                        m.TopLeft = m.MidLeft = m.BottomLeft = 5;
                        m.Offset  = 0;
                        break;
                    }
                    BitmapFilter.Conv3x3(b, m);

                    switch (nType)
                    {
                    case EdgeDetectionMethod.Sobel:
                        m.SetAll(0);
                        m.TopLeft    = m.TopRight = 1;
                        m.BottomLeft = m.BottomRight = -1;
                        m.TopMid     = 2;
                        m.BottomMid  = -2;
                        m.Offset     = 0;
                        break;

                    case EdgeDetectionMethod.Prewitt:
                        m.SetAll(0);
                        m.BottomLeft = m.BottomMid = m.BottomRight = -1;
                        m.TopLeft    = m.TopMid = m.TopRight = 1;
                        m.Offset     = 0;
                        break;

                    case EdgeDetectionMethod.Kirsh:
                        m.SetAll(-3);
                        m.Pixel      = 0;
                        m.BottomLeft = m.BottomMid = m.BottomRight = 5;
                        m.Offset     = 0;
                        break;
                    }
                    BitmapFilter.Conv3x3(bTemp, m);
                }
                catch
                { throw; }

                // GDI+ lies - return format is BGR, not RGB.
                BitmapData bmpData  = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                BitmapData bmpData2 = bTemp.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

                try
                {
                    int stride = bmpData.Stride;

                    unsafe
                    {
                        byte *p  = (byte *)(void *)bmpData.Scan0;
                        byte *p2 = (byte *)(void *)bmpData2.Scan0;

                        int nOffset = stride - b.Width * 3;
                        int nWidth  = b.Width * 3;

                        int nPixel = 0;

                        for (int y = 0; y < b.Height; ++y)
                        {
                            for (int x = 0; x < nWidth; ++x)
                            {
                                nPixel = (int)System.Math.Sqrt((p[0] * p[0]) + (p2[0] * p2[0]));
                                if (nPixel < nThreshold)
                                {
                                    nPixel = nThreshold;
                                }
                                if (nPixel > 255)
                                {
                                    nPixel = 255;
                                }
                                p[0] = (byte)nPixel;
                                ++p;
                                ++p2;
                            }
                            p  += nOffset;
                            p2 += nOffset;
                        }
                    }
                }
                catch
                { throw; }
                finally
                {
                    b.UnlockBits(bmpData);
                    bTemp.UnlockBits(bmpData2);
                }
            }
            return(b);
        }
Esempio n. 14
0
        //public static Bitmap Conv3x3(Bitmap b, ConvMatrix m)
        //{
        //    // Avoid divide by zero errors.
        //    if (m.Factor == 0)
        //        throw new ArgumentException("Conversion matrix factor must be greater than zero.", "m");

        //    using (Bitmap bSrc = (Bitmap)b.Clone())
        //    {
        //        // GDI+ lies - the return format is BGR, not RGB (stupid little-endian)
        //        BitmapData bmpData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
        //        BitmapData bmpSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

        //        try
        //        {
        //            int stride = bmpData.Stride;
        //            int stride2 = stride * 2;

        //            unsafe
        //            {
        //                byte* p = (byte*)(void*)bmpData.Scan0;
        //                byte* pSrc = (byte*)(void*)bmpSrc.Scan0;

        //                int nOffset = stride - b.Width * 3;
        //                int nWidth = b.Width - 2;
        //                int nHeight = b.Height - 2;

        //                int nPixel;

        //                for (int y = 0; y < nHeight; ++y)
        //                {
        //                    for (int x = 0; x < nWidth; ++x)
        //                    {
        //                        nPixel = ((((pSrc[2] * m.TopLeft) + (pSrc[5] * m.TopMid) + (pSrc[8] * m.TopRight) +
        //                                (pSrc[2 + stride] * m.MidLeft) + (pSrc[5 + stride] * m.Pixel) + (pSrc[8 + stride] * m.MidRight) +
        //                                (pSrc[2 + stride2] * m.BottomLeft) + (pSrc[5 + stride2] * m.BottomMid) + (pSrc[8 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);

        //                        nPixel = (int)System.Math.Min(0, System.Math.Max(nPixel, 255));
        //                        p[5 + stride] = (byte)nPixel;

        //                        nPixel = ((((pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
        //                                (pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
        //                                (pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);

        //                        nPixel = (int)System.Math.Min(0, System.Math.Max(nPixel, 255));
        //                        p[4 + stride] = (byte)nPixel;

        //                        nPixel = ((((pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] + m.TopRight) +
        //                                (pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
        //                                (pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);

        //                        nPixel = (int)System.Math.Min(0, System.Math.Max(nPixel, 255));
        //                        p[3 + stride] = (byte)nPixel;

        //                        p += 3;
        //                        pSrc += 3;
        //                    }
        //                    p += nOffset;
        //                    pSrc += nOffset;
        //                }
        //            }
        //        }
        //        catch
        //        { throw; }
        //        finally
        //        {
        //            b.UnlockBits(bmpData);
        //            bSrc.UnlockBits(bmpSrc);
        //        }
        //    }
        //    return b;
        //}
        public static Bitmap Smooth(Bitmap b)
        {
            return(BitmapFilter.Smooth(b, 1));
        }
Esempio n. 15
0
 public static Bitmap GausianBlur(Bitmap b)
 {
     return(BitmapFilter.GausianBlur(b, 3, 5.5f));
 }
Esempio n. 16
0
 public static Bitmap Sharpen(Bitmap b)
 {
     return(BitmapFilter.Sharpen(b, 11));
 }
Esempio n. 17
0
 public static Bitmap GrayScale(Bitmap b)
 {
     return(BitmapFilter.ProcessBitmap(b, BitmapFilterType.GrayScale));
 }
Esempio n. 18
0
 public static Bitmap MeanRemoval(Bitmap b)
 {
     return(BitmapFilter.MeanRemoval(b, 9));
 }