(Sketch Filter) Sketch Filter The implementation method of the sketch filter is relatively simple. Here we directly write the algorithm process as follows: 1. Run the de-color command on the source image S to obtain grayscale image; 2. reversed A to obtain image B; 3. Perform Gaussian blur on B to obtain fig C; 4. The algorithm of mixing the layers of C and B with the color fades: P (x, y) = Pb (x, y) + (Pb (x, y) * Pc (x, y)/(256-Pc (x, y, y )); In step 3, you can add the variable edgeIntensity (edgeIntensity> = 0) to control the edge strength of the sketch; The above is the implementation of the sketch algorithm. The core code is as follows: Private Bitmap SketchFilterProcess (Bitmap src, int edgeIntensity) { Bitmap gaussBitmap = gf. Apply (src, edgeIntensity ); Bitmap dst = new Bitmap (src ); Int w = dst. Width; Int h = dst. Height; BitmapData dstData = dst. LockBits (new Rectangle (0, 0, w, h), ImageLockMode. ReadWrite, PixelFormat. Format32bppArgb ); BitmapData edgeData = gaussBitmap. LockBits (new Rectangle (0, 0, w, h), ImageLockMode. ReadOnly, PixelFormat. Format32bppArgb ); Byte * pGauss = (byte *) edgeData. Scan0; Byte * pDst = (byte *) dstData. Scan0; Int offset = dstData. Stride-w * 4; Int gray, graySrc, grayGauss; For (int j = 0; j { For (int I = 0; I <w; I ++) { GraySrc = (pDst [0] + pDst [1] + pDst [2])/3; GrayGauss = 255-(pGauss [0] + pGauss [1] + pGauss [2])/3; Gray = graySrc + (graySrc * grayGauss)/(256-grayGauss ); Gray = Math. Min (255, Math. Max (0, gray )); PDst [0] = (byte) gray; PDst [1] = (byte) gray; PDst [2] = (byte) gray; PDst [3] = (byte) 255; PGauss + = 4; PDst + = 4; } PGauss + = offset; PDst + = offset; } Dst. UnlockBits (dstData ); GaussBitmap. UnlockBits (edgeData ); Return dst; } As follows: Source image Sketch Filter Finally put the complete C #/C program DEMO download connection: http://www.zealpixel.com/thread-64-1-1.html |