PS filter-sketch algorithm (1)

Source: Internet
Author: User

This algorithm is implemented in combination with the color fade mode in Gaussian filtering and layer mixing.

Refer to related blogs:

Http://blog.csdn.net/wsfdl/article/details/7610634


This article adds a bit of color to make the final sketch effect not only black and white, but also different background colors.


% Convert image to black and white color
% Copy the image and invert the copied Image
% Perform Gaussian blur on the copied Image
% Mix the blurred image with the original image in the color fade Mode
% Set a background color layer
% Sketch

CLC;
Clear all;
Addpath ('e: \ Photoshop algortihm \ image processing \ PS algorithm ');
Image1_imread('9.jpg ');
Image = double (image)/255;

I = (image (:,:, 1) + image (:,:, 2) + image (:,:, 3)/3;
I _invert = 1-I;
F_size = 20;
F_gaussian = fspecial ('gaussian ', f_size, f_size/6 );
I _gaussian = imfilter (I _invert, f_gaussian, 'conv ');

Delta = 0.001;
I _dodge = (I + delta)./(1-i_gaussian + delta );

Max_value = max (I _dodge (:));
[Row, Col] = size (I );
Threshold = 0.95;
For I = 1: Row
For j = 1: Col
If (I _dodge (I, j)> threshold)
I _dodge (I, j) = threshold + I _dodge (I, j)/max_value * (1-threshold );
End
End
End

Image_dodge (:,:, 1) = I _dodge;
Image_dodge (:,:, 2) = I _dodge;
Image_dodge (:,:, 3) = I _dodge;
% Figure, imshow (image_dodge );

Base_layer = image_dodge;
Base_layer (:,:, 1) = 210/255;
Base_layer (:,:, 2) = 225/255;
Base_layer (:,:, 3) = 105/255;

Alpha = 0.7;
Image1 = Alpha * image_dodge + (1-alpha) * base_layer;
R = image1 (:,:, 1 );
G = image1 (:,:, 2 );
B = image1 (:,:, 3 );
% Figure, imshow (image1 );

Image3 = image_dodge. * image1;
Figure, imshow (image3 );



Source image




PS filter-sketch algorithm (1)

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.