How it works

To inpaint images in OpenCV, you need to use the cv2.inpaint function. It accepts four arguments:

  • Image with defects: It has to be an 8-bit colorful or grayscale one
  • Mask for defects: It has to be an 8-bit single channel one and be the same size as the image in the first argument
  • Neighborhood radius: The size of the area around a damaged pixel, which should be used in computing its color
  • Inpainting mode: Type of the algorithm of inpainting

Mask for defects should contain non-zero values for pixels on the original image, which need to be recovered. Neighborhood radius is a range of pixels around the algorithm that it considers during inpainting; it should have a small value to prevent dramatic blurring effects. Inpainting mode ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.