Image Inpainting
Image inpainting is the process of restoring damaged or missing parts such as noise and any other damage in an image using interpolation techniques. We can use inpainting algorithms like Fast Marching Method and Navier-Stokes Equations to fill the missing pixels in an image. These algorithms take the surrounding pixels into account while inpainting the damaged region and gives a resultant image.
Fast marching method - In OpenCV, the Fast Marching Method can be used for image inpainting by treating the missing or damaged pixels as the "unknown" region and the known pixels as the "known" region. The FMM is used to propagate information from the known pixels to the unknown pixels, filling in the missing parts of the image.
Navier-Stokes Equations - the Navier-Stokes equations is an algorithm used for image inpainting in OpenCV. The equations is used to propagate information from known parts of the image to the missing or damaged pixels, filling in the missing parts of the image.
In this tutorial, we will learn about how to do image inpainting using OpenCV.
Example using Navier-Stokes equations :
Input 1
Input 2
Code:
import cv2
img = cv2.imread('demo.png')
img1 = cv2.imread('img66.png',0)
image = cv2.inpaint(img, img1, 3, cv2.INPAINT_NS)
cv2.imshow('final', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here, first, we imported cv2 and used cv2.imread to read both the images. Then, we used cv2.inpaint with Navier-Stokes equations. At last, we used cv2.imshow to display the final result.
Result:
Example using Fast marching method:
Input 1
Input 2
Code:
import cv2
img = cv2.imread('demo.png')
img1 = cv2.imread('img66.png',0)
image = cv2.inpaint(img, img1, 3, cv2.INPAINT_TELEA)
cv2.imshow('final', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here, first, we imported cv2 and used cv2.imread to read both the images. Then, we used cv2.inpaint with Fast marching method.
Result: