Image Filter art --- Sketch Filter, sketchfilter

Source: Internet
Author: User
Tags image filter

Image Filter art --- Sketch Filter, sketchfilter

(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

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.