Ben Banks
Ben Banks

Reputation: 129

Python OpenCV inpainting method produces strange artefacts

I tried to use the inpainting method proposed by OpenCV on a project, but the results were a bit surprising, in particular with the NS method. I created strange lines at the middle of the masked zones.

Looking at this paper, the method is described as follows:

After the user selects the unknown region, the algorithm first travels along the edges from known regions to unknown regions, and automatically transports information into the inpainting region. The algorithm makes use of isophotes (a line in a diagram connecting points where the intensity of light or brightness is the same). The fill-in is done is such a way that the isophote lines arriving at the unknown region’s boundary are completed inside, which allows the smooth continuation of information towards the center of the unknown region.

To easily reproduce the artefacts I produced an image consisting in an array of rotated gradient circle and rotated masking bar, as follows:

testing array

enter image description here

I then computed the inpainting result using the following code:

import numpy as np
import cv2 as cv2
image = cv2.imread('testing_array.png', cv2.IMREAD_GRAYSCALE)
mask = cv2.imread('testing_mask.png', cv2.IMREAD_GRAYSCALE)
dst = cv2.inpaint(image,mask,2,cv2.INPAINT_NS)
cv2.imwrite("testing_output.png",dst)

As we see below, the result is surprising: the quality of the result is great when gradients are vertical, but fails very quickly when it is not the case. When reading the description, it seems that the method should be able to handle gradients that are not strictly vertical.

output

I'm wondering if this is the expected result of the method, or if I should go digging for an implementation issue.

Version:

Upvotes: 0

Views: 53

Answers (0)

Related Questions