Skip to content

Wrong cv2.xphoto.inpaint documentation or bug #2098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Treiblesschorle opened this issue Apr 17, 2019 · 1 comment
Closed

Wrong cv2.xphoto.inpaint documentation or bug #2098

Treiblesschorle opened this issue Apr 17, 2019 · 1 comment

Comments

@Treiblesschorle
Copy link

Treiblesschorle commented Apr 17, 2019

  • OpenCV => pip opencv-contrib-python-4.1.0.25
  • Operating System / Platform => Windows 64 Bit
Detailed description

The following doc seems to be wrong or there is a bug in the cv2.xphoto.inpaint function.

The doc for the mask parameter states:

mask (CV_8UC1), where non-zero pixels indicate valid image area, while zero pixels indicate area to be inpainted

However, it seems that the mask must be 255 for the valid image area and not just non-zero. Either the doc is wrong or the there is a bug in the function.

Test Code
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
from scipy.misc import imread

img = imread('C:/lenna.png')
mask = 255 * np.ones((img.shape[0], img.shape[1]), np.uint8)
mask = cv.circle(mask, (256, 256), 50, 0, -1)
res = np.zeros(img.shape, np.uint8)
cv.xphoto.inpaint(img, mask, res, cv.xphoto.INPAINT_SHIFTMAP)

plt.imshow(res)
plt.show()

If you multiply the mask with something else than 255, the output is a black image.

Also, see this question on the opencv forum: http://answers.opencv.org/question/211657/how-to-use-cv2xphotoinpaint-in-python3/

@saskatchewancatch
Copy link
Contributor

saskatchewancatch commented Jul 18, 2019

The documentation is right. That's how a mask should behave. How the mask is used within the implementation is wrong however. I have a PR coming with a fix shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants