官术网_书友最值得收藏!

Creating a black-and-white pencil sketch

In order to obtain a pencil sketch (that is, a black-and-white drawing) of the camera frame, we will make use of two image-blending techniques, known as dodging and burning. These terms refer to techniques employed during the printing process in traditional photography; here, photographers would manipulate the exposure time of a certain area of a darkroom print in order to lighten or darken it. Dodging lightens an image, whereas burning darkens it. Areas that were not supposed to undergo changes were protected with a mask.

Today, modern image editing programs, such as Photoshop and Gimp, offer ways to mimic these effects in digital images. For example, masks are still used to mimic the effect of changing the exposure time of an image, wherein areas of a mask with relatively intense values will expose the image more, thus lightening the image. OpenCV does not offer a native function to implement these techniques; however, with a little insight and a few tricks, we will arrive at our own efficient implementation that can be used to produce a beautiful pencil sketch effect.

If you search on the internet, you might stumble upon the following common procedure to achieve a pencil sketch from an RGB (red, green, and blue) color image:

  1. First, convert the color image to grayscale.
  2. Then, invert the grayscale image to get a negative.
  3. Apply a Gaussian blur to the negative from step 2.
  4. Blend the grayscale image (from step 1) with the blurred negative (from step 3) by using color dodge.

Whereas steps 1 to 3 are straightforward, step 4 can be a little tricky. Let's get that one out of the way first.

OpenCV 3 came with a pencil sketch effect right out of the box. The cv2.pencilSketch function uses a domain filter introduced in the 2011 paper, Domain Transform for Edge-Aware Image and Video Processing, by Eduardo Gastal and Manuel Oliveira. However, for the purposes of this book, we will develop our own filter.

The next section shows you how to implement dodging and burning in OpenCV.

主站蜘蛛池模板: 曲阜市| 石楼县| 读书| 钦州市| 临漳县| 英山县| 静海县| 乌拉特中旗| 宝鸡市| 山东省| 五寨县| 任丘市| 资中县| 宁乡县| 聊城市| 天气| 蓬安县| 新建县| 关岭| 新建县| 屯昌县| 临猗县| 金华市| 孙吴县| 绥江县| 裕民县| 兖州市| 隆子县| 定兴县| 南开区| 邳州市| 福建省| 峡江县| 望城县| 长宁区| 大同县| 邓州市| 阿拉善左旗| 嘉义县| 龙州县| 区。|