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)