March 2020
Intermediate to advanced
366 pages
9h 8m
English
A strong bilateral filter is ideally suitable for converting an RGB image into a color painting or a cartoon, because it smoothens the flat regions while keeping the edges sharp. The only drawback of this filter is its computational cost—it is orders of magnitude slower than other smoothing operations, such as a Gaussian blur.
The first measure to take when we need to reduce the computational cost is to perform an operation on an image of low resolution. In order to downscale an RGB image (imgRGB) to a quarter of its size (that is, reduce the width and height to half), we could use cv2.resize:
img_small = cv2.resize(img_rgb, (0, 0), fx=0.5, fy=0.5)
A pixel value in the resized image will ...