filling gaps on an image using numpy and scipy

Viewed 11204

The image (test.tif) is attached. The np.nan values are the whitest region. How to fill those whitest region using some gap filling algorithms that uses values from the neighbours?

enter image description here

import scipy.ndimage

data = ndimage.imread('test.tif')
4 Answers

OpenCV has some image in-painting algorithms that you could use. You just need to provide a binary mask which indicates which pixels should be in-painted.

import cv2
import numpy as np
import scipy.ndimage

data = ndimage.imread("test.tif")
mask = np.isnan(data)
inpainted_img = cv2.inpaint(img, mask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
Related