(Sketch filter) sketch Filter Sketch Filter Implementation method is relatively simple, here we directly write the algorithm process is as follows: 1, the original s for the de-color command to get the grayscale image A; 2, the inverse color of a to get the image B; 3, Gaussian Blur to B is obtained figure C; 4, the layer blending algorithm of C and B for color Dodge: P (x, y) = PB (x, y) + (Pb (x, y) * Pc (x, Y))/(256-PC (x, y)); In step 3, you can add variable edgeintensity (edgeintensity>=0) to control the edge strength of the sketch; The above is the algorithm implementation of the sketch. 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 < H; 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 shown below: Original Sketch Filter Finally put the full C#/C program demo download Connection: http://www.zealpixel.com/thread-64-1-1.html |