forked from candycat1992/PencilDrawing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PencilDrawing.m
executable file
·55 lines (46 loc) · 1.55 KB
/
PencilDrawing.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function I = PencilDrawing(im, ks, width, dirNum, gammaS, gammaI)
% ==============================================
% Generate the pencil drawing I based on the method described in
% "Combining Sketch and Tone for Pencil Drawing Production" Cewu Lu, Li Xu, Jiaya Jia
% International Symposium on Non-Photorealistic Animation and Rendering (NPAR 2012), June, 2012
%
% Paras:
% @im : the input image.
% @ks : the length of convolution line.
% @width : the width of the stroke.
% @dirNum : the number of directions.
% @gammaS : the darkness of the stroke.
% @gammaI : the darkness of the resulted image.
%
%% Read the image
im = im2double(im);
[H, W, sc] = size(im);
%% Convert from rgb to yuv when nessesary
if (sc == 3)
yuvIm = rgb2ycbcr(im);
lumIm = yuvIm(:,:,1);
else
lumIm = im;
end
%% Generate the stroke map
S = GenStroke(lumIm, ks, width, dirNum) .^ gammaS; % darken the result by gamma
% figure, imshow(S)
%% Generate the tone map
J = GenToneMap(lumIm) .^ gammaI; % darken the result by gamma
% figure, imshow(J)
%% Read the pencil texture
P = im2double(imread('pencils/pencil0.jpg'));
P = rgb2gray(P);
%% Generate the pencil map
T = GenPencil(lumIm, P, J);
% figure, imshow(T)
%% Compute the result
lumIm = S .* T;
if (sc == 3)
yuvIm(:,:,1) = lumIm;
% resultIm = lumIm;
I = ycbcr2rgb(yuvIm);
else
I = lumIm;
end
end