How to do it...

  1. Import the modules:
import cv2
import numpy as np
import matplotlib.pyplot as plt
  1. Draw a test imageā€”a black circle (without filling) on a white background:
image = np.full((480, 640), 255, np.uint8)
cv2.circle(image, (320, 240), 100, 0)
  1. Compute the distance from every point to the circle:
distmap = cv2.distanceTransform(image, cv2.DIST_L2, cv2.DIST_MASK_PRECISE)
  1. Visualize the results:
plt.figure()
plt.imshow(distmap, cmap='gray')
plt.show()