Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I modified your codes and it worked!

Hope my codes will help you.

import cv2
import numpy as np

if __name__ == "__main__":
    s_img_src = 'source.jpg'
    s_img_mask = 'mask.png'

    img_src = cv2.imread(s_img_src)
    img_src_lab = cv2.cvtColor(img_src, cv2.COLOR_BGR2Lab)

    img_mask = cv2.imread(s_img_mask, cv2.IMREAD_GRAYSCALE)
    img_mask_inv = np.invert(img_mask.astype(np.bool)).astype(np.uint8)

    img_dst = np.zeros_like(img_src)
    cv2.xphoto.inpaint(img_src_lab, img_mask_inv, img_dst,
                       cv2.xphoto.INPAINT_SHIFTMAP)
    img_dst = cv2.cvtColor(img_dst, cv2.COLOR_Lab2BGR)

    cv2.imshow('temp', img_dst)
    cv2.waitKey(0)

source mask

result

I modified your codes and it worked!

Hope my codes will help you.

import cv2
import numpy as np

if __name__ == "__main__":
    s_img_src = 'source.jpg'
    s_img_mask = 'mask.png'

    img_src = cv2.imread(s_img_src)
    img_src_lab = cv2.cvtColor(img_src, cv2.COLOR_BGR2Lab)

    img_mask = cv2.imread(s_img_mask, cv2.IMREAD_GRAYSCALE)
    img_mask_inv = np.invert(img_mask.astype(np.bool)).astype(np.uint8)
cv2.bitwise_not(img_mask)

    img_dst = np.zeros_like(img_src)
    cv2.xphoto.inpaint(img_src_lab, img_mask_inv, img_dst,
                       cv2.xphoto.INPAINT_SHIFTMAP)
    img_dst = cv2.cvtColor(img_dst, cv2.COLOR_Lab2BGR)

    cv2.imshow('temp', img_dst)
    cv2.waitKey(0)

source mask

result