March 2020
Intermediate to advanced
366 pages
9h 8m
English
A Gaussian blur is basically a convolution with a Gaussian function. Well, one of the features of convolutions is their associative property. This means that it does not matter whether we first invert the image and then blur it, or first blur the image and then invert it.
If we start with a blurred image and pass its inverse to the dodge function, then within that function the image will be inverted again (the 255-mask part), essentially yielding the original image. If we get rid of these redundant operations, the optimized convert_to_pencil_sketch function will look like this:
def convert_to_pencil_sketch(rgb_image): gray_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2GRAY) blurred_image = cv2.GaussianBlur(gray_image, ...