4

I want to convert an image to a color pencil sketch using OpenCV. And I have read the page I want to convert an image into pencil sketch in OpenCV .The effect which I seek is like http://www.showandtell-graphics.com/photosketch.html I used the color dodge by code

b_d = (b_2==255? 255: min(255, b_1*255 /(255- b_2)));        
g_d = (g_2==255? 255: min(255, g_1 *255/(255- g_2)));             
r_d = (r_2 ==255? 255: min(255, r_1 *255/(255- r_2)));  

It seems work not very well. PLS help.

Community
  • 1
  • 1
Yang
  • 41
  • 1
  • 2

1 Answers1

8

The overall procedure is detailed in the link you gave us, so you need 3 images to achieve this effect.

Make a copy of the original image and convert it to grayscale.

Make a copy of the grayscale image and invert this image.

At this point, image #1 is the original, image #2 is grayscale, and image #3 is the inverted image.

Then, apply the color dodge to image #3 (making it white) and execute the blur. This alone will give you the pencil sketch effect in grayscale.

If you want the final result to be colored, you will have to blend image #3 with image #1.

Looking for information on blending? Check this, this and this.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • You mean: 1.cvCvtColor(source_img, gray_img, CV_BGR2GRAY);2.cvNot(gray_img, imgtemp); 3.execute dodge like color_dodge(dst_img, gray_img, imgtemp); 4.cvSmooth(dst_img, result_img, CV_GAUSSIAN)????? How to solve the channel problem among those image? I mean the channel of gray is 1 – Yang May 15 '12 at 13:23
  • @karlphillip : what is this dodge operation, mathematically (for grayscale image and color image) – Abid Rahman K May 20 '12 at 12:02
  • @karlphillip - I am not using openCV but can above applied to regular java code? I am confused by color dodge. Which two images you use for color dodge? Is it image#2 and image #3? If i use those i get all white no image? – NoviceMe Dec 05 '13 at 03:43
  • @NoviceMe The Color Dodge blend mode divides the bottom layer by the inverted top layer](http://en.wikipedia.org/wiki/Blend_modes#Dodge_and_burn). According to the [original link](http://www.showandtell-graphics.com/photosketch.html), those are: the colored image and the inverted. – karlphillip Dec 05 '13 at 12:44
  • This become not as good as display in https://play.google.com/store/apps/details?id=com.dumplingsandwich.pencilsketch. I want this type of sketch exactly. so please help me – Denny Sharma Feb 10 '14 at 13:25
  • If anyone ends up putting together the complete code, post it please – scottmrogowski Jul 27 '15 at 18:29