Image Reconstruction : Inpainting (Interpolation) - Fast Marching Method
Inpainting is an image interpolation. Digital inpainting algorithms have broad applications in image interpolation, photo restoration, zooming and super-resolution, etc.
"Inpainting (also known as image interpolation or video interpolation) refers to the application of sophisticated algorithms to replace lost or corrupted parts of the image data (mainly small regions or to remove small defects)." - wiki - Inpainting
Picture source: wiki
Here is a degraded picture (it has several horizontal scratches) sample for this chapter.
Let's see how does our OpevCV self-clean work!
This method is to solve the boundary value problems of the Eikonal equation:$$F(x)|\nabla T(x)|=1.$$
Where $F(x)$ is a speed function in the normal direction at a point $x$ on the boundary curve. $T$ is the time at which the contour crosses a point $x$ which is obtained by solving the equation.
The picture is from http://math.berkeley.edu, and the site has a good description on FMM.
In this section, we'll use cv2.inpaint() function with a parameter cv2.INPAINT_TELEA. The name "telea" is from the author (Alexandru Telea) of the paper âAn Image Inpainting Technique Based on the Fast Marching Methodâ
cv.Inpaint(src, inpaintMask, dst, inpaintRadius, flags)
The parameters are:
- src : Input 8-bit 1-channel or 3-channel image.
- inpaintMask : Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that needs to be inpainted.
- dst : Output image with the same size and type as src .
- inpaintRadius : Radius of a circular neighborhood of each point inpainted that is considered by the algorithm.
- flags :
- INPAINT_NS Navier-Stokes based method
- INPAINT_TELEA Method by Alexandru Telea
Here is the code to upgrade the degraded image using the Fast Marching Method:
import numpy as np from matplotlib import pyplot as plt import cv2 img = cv2.imread('OpenCV_Logo_B.png') # input mask = cv2.imread('OpenCV_Logo_C.png',0) # mask dst_TELEA = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA) dst_NS = cv2.inpaint(img,mask,3,cv2.INPAINT_NS) plt.subplot(221), plt.imshow(img) plt.title('degraded image') plt.subplot(222), plt.imshow(mask, 'gray') plt.title('mask image') plt.subplot(223), plt.imshow(dst_TELEA) plt.title('TELEA') plt.subplot(224), plt.imshow(dst_NS) plt.title('NS') plt.tight_layout() plt.show()
Here is the output. The 1st one is the degraded OpenCV logo, the 2nd picture is the mask that was needed to run FMM. The last two pictures are the results from the inpainting. Not sure but I do not see any difference between the two methods of inpainting, at least for current input.
Here is the mask file OpenCV_Logo_C.png.
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization