There are many algorithms for pencil effects, and it's no surprise that such a powerful software like Photoshop has this feature. Occasionally idle to do nothing, collect some of this information, feel quite interesting. Recently, I saw a Jayaya professor of the Chinese University of Hong Kong paper, of course, he just hung a name, because he is not the first author, should be his student's work. Needless to say, this paper title is "combining Sketch and Tone for Pencil Drawing Production". It's amazing to see the effect of this paper. This is the best pencil-effect algorithm I've ever seen, not one of them. The principle of the article is also very simple. Hope interested friends to go down and study. You deserve it!
The following posted their own code, very rough, but also look crossing Mo to laughed at.
1 clear All;2 close all;3 CLC;4ks=Ten;5dirnum=8;6[Filename,pathname]=uigetfile ({'*.jpg';'*.png';'*.bmp'},'Open an Image File');7img=Imread ([PathName FileName]);8 figure,imshow (IMG);9[H, W, SC] =size (IMG);Ten ifsc = =3 OneI =Rgb2gray (IMG); A End -PC = Phasecongmono (I,5,3,2.5,0.55,2.0); - figure,imshow (PC); thepc=pc.^0.65; - -%%convolution kernel with horizontal direction -Kerref = Zeros (ks*2+1); +Kerref (ks+1,:) =1; - +%%Classification AResponse =zeros (h,w,dirnum); atSresponse =zeros (h,w,dirnum); - forII =0: (dirnum-1) -Ker = Imrotate (Kerref, ii* the/dirnum,'bilinear','Crop'); -Response (:,:, ii+1) = Conv2 (PC, Ker,'same'); - End -[~, index] = sort (response,3); inDirs = (Index (:,:, End)-1)* the/Dirnum; -maxindex=index (:,:, end); toC =zeros (h,w,dirnum); + fork=1:d Irnum - forI=1: H the forj=1: W * if(Maxindex (i,j) = =k) $C (i,j,k) =PC (i,j);Panax Notoginseng - End the End + End A End theCresponse =zeros (h,w,dirnum); + forJJ =0: (dirnum-1) -Ker = Imrotate (Kerref, jj* the/dirnum,'bilinear','Crop'); $ $Cresponse (:,:, jj+1) = Conv2 (C (:,:, jj+1), Ker,'same'); - End -s=0.079*cresponse (:,:,1)+0.079*cresponse (:,:,2)+0.079*cresponse (:,:,3)+0.079*cresponse (:,:,4)+0.079*cresponse (:,:,5)+0.079*cresponse (:,:,6)+0.079*cresponse (:,:,7)+0.079*cresponse (:,:,8); theFigure,imshow (1-S); -A=0:255;WuyiP1 =1/9*exp (-(255-a)/9); thep3=1/SQRT (2*pi* One) * EXP (-(-) -). * (A- -) / (2.0* One* One)); -P2=0:255; WuP2 (:) =1/(225- the); -P2 (1: -)=0; AboutP2 (225: the)=0; $p =0.76* P1 +0.22* P2 +0.02*P3; - Figure,plot (a,p); -Hgram=round (p*h*W); - Ainew=Histeq (Uint8 (I), hgram); +H=fspecial ('Gaussian', -,2); theInew = IMFilter (Inew,h,'Replicate'); -inew=Double(Inew); $sn=1-Mapminmax (S); the out=inew.*sn*0.55; theFigure,imshow (Uint8 ( out));
Need to be reminded that this code does not implement texture rendering steps, so the effect and the article still have a certain gap.
Pencil Special Effect algorithm