Photoshop image Filter--Sketch algorithm (with MATLAB code)

Source: Internet
Author: User
Tags image filter

Second, Photoshop image Filter--Sketch algorithm


Sketch algorithm, there are many network, but the effect is not particularly ideal. Friends who are familiar with Photoshop know that the effect of drawing color pictures is only a few steps: 1, de-color, 2, copy the color layer, and inverse color, 3, the inverse color image gaussian blur, 4, the blurred image overlay mode to select the color Dodge effect.


The color of the image is relatively simple, not much to explain. Assuming that the original image is X, the processed image is Y, that is, for coordinates (I,J), the inverse color is y (i,j) =255-x (i,j). Gaussian Blur is quite similar to a low-pass filter, and friends can find information about Gaussian blur. The color Dodge algorithm is this: C =min (A + (AXB)/(255-b), 255), where c is the mixed result, a is the source pixel, and B is the target pixel point.


The MATLAB code is as follows:


I=imread (' a1.jpg ', ' jpg ');
Imshow (I);
Figure ();
Info_size=size (I);
Height=info_size (1);
Width=info_size (2);
N=zeros (height,width);
G=zeros (height,width);
Imggray=rgb2gray (I);
Out=zeros (height,width);

Spec=zeros (height,width,3);
For i=1:height for
    j=1:width
        
        N (i,j) =255-imggray (i,j);
        
    End
End for

i=2:height-1 for
    j=2:width-1
        sum=0;
        Sum=1*double (n (i-1,j-1)) +2*double (n (i-1,j)) +1*double (n (i-1,j+1));
        Sum=sum+2*double (n (i,j-1)) +4*double (n (i,j)) +2*double (n (i,j+1));
        Sum=sum+1*double (n (i+1,j-1)) +2*double (n (i+1,j)) +1*double (n (i+1,j+1));
        SUM=SUM/16;
        G (I,j) =sum;
    End
End for

i=1:height for
    j=1:width
        b=double (g (i,j));
        A=double (Imggray (i,j));
        temp=a+a*b/(256-b);
        Out (i,j) =uint8 (min (temp,255));
        
    End
End
imshow (out/255);

After processing the image is as follows:



Welcome friends more advice, welcome to share, please specify the source-----(WSFDL)!


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.