Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize Fast de-watermarking with Python

Shulou Source: shulou.com Published: 2022-06-01 19:54:25 09月17日 Update

This article introduces the knowledge of "how to quickly de-watermark Python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Principle of image de-watermarking

1. Calibrate the characteristics of the noise. Use cv2.inRange binarization marking noise to binarize the image. Specific code: cv2.inRange (img, np.array ([200,200,240]), np.array ([255,255,255])). The colors other than [200,200,200] ~ [255,255,255] are processed to 0.

2. Use the dilate method of OpenCV to expand the area of features and optimize the effect of image processing.

3. Using inpaint method, taking the mask of noise as a parameter, reasoning and repairing the image.

Remove the watermark in the lower right corner

1. Capture the lower right corner from the original picture and save it as a new picture.

2. Identify the watermark. The color value is: [200,200,200] ~ [255,255,255]

3. Remove the watermark and restore the picture

4. Overlap and merge the original image and the new one without watermark.

The code implements import cv2import numpy as npfrom PIL import Imageimport osdir = os.getcwd () path = "1.jpg" newPath = "new.jpg" img=cv2.imread (path,1) hight,width,depth=img.shape [0:3] # intercept cropped = img [int (hight*0.8): hight, int (width*0.7): width] # crop coordinates as [y0:y1, x0:x1] cv2.imwrite (newPath, cropped) imgSY = cv2.imread (newPath,1) # Image binarization processing Change colors other than [200200200]-[250250250] to 0thresh = cv2.inRange (imgSY,np.array ([200200200]), np.array ([250250250250])) # create structural elements of shape and size kernel = np.ones ((3d3), np.uint8) # extend the area to be repaired hi_mask = cv2.dilate (thresh,kernel,iterations=10) specular = cv2.inpaint (imgSY,hi_mask,5,flags=cv2.INPAINT_TELEA) cv2.imwrite (newPath) Specular) # overlay image imgSY = Image.open (newPath) img = Image.open (path) img.paste (imgSY, (int (width*0.7), int (hight*0.8), width,hight)) img.save (newPath) "how to get rid of watermarks quickly by Python" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Pictures watermarks processing noise color code content regions methods more features knowledge practicality learning and then elements principles parameters dilemmas coordinates Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple MySQL Huawei Microsoft