I want to remove a watermark from a image and result looks blurry on the watermarks. I need help to fix this.
I have used the inpaint function from opencv. My code looks like this.
import cv2
import matplotlib.pyplot as plt
import numpy as np
import time
start = time.time()
IMAGE = "images/img.jpg"
MASK = "images/mask.png"
image = cv2.imread(IMAGE)
mask = cv2.imread(MASK, 0)
img = cv2.inpaint(image, mask, 0, cv2.INPAINT_NS)
cv2.imwrite("output.jpg", img)
print(time.time()-start)



There are some artifacts that the in-painting algorithm produces; it's difficult to completely get rid of them. This is my take trying to minimize the artifacts. It basically involves converting the
BGRimage toLAB, splitting theLchannel, in-painting only this channel, merging the components and then converting back toBGR:It appears that your mask is a little bit bigger than your input image. Let’s
resizeit because the in-painting algorithm needs exactly the same sizes for both images:Let’s apply a little bit of morphology. Looks like a basic
dilationhelps mitigating the artifacts:Now, let’s in-paint the
Lchannel, merge it with the rest of the original components and convert back toBGR:This is the result:
Observation: Save your images using a lossless format such as
png, your original image isjpegand you can see some compression artifacts already before performing any processing.