In this recipe, you will learn how to compute the distance to the closest non-zero pixels from each image pixel. This functionality can be used to perform image processing in an adaptive way, for instance, for blurring an image with different strengths, depending on the distance to the closest edge.
Computing distance maps
Getting ready
Install the OpenCV 3.x Python API package and the matplotlib package.
How to do it...
- Import the modules:
import cv2
import numpy as np
import matplotlib.pyplot as plt
- Draw a test image—a black circle (without filling) on a white...