Image Repair Program-can be used for watermark removal
In real life, we may encounter some beautiful or precious pictures are disturbed by noise, such as the folds of old photos, such as dust or stains on the lens, or some of the things we want to use for me but have a nasty watermark, then there is no way to eliminate these noise?
The answer is yes, it is still a good framework that we have used countless times opencv.
Effect Preview
Principle of image Restoration
That OpenCV is how to realize, simply is the developer to calibrate the characteristics of noise, in the use of noise around the color features to infer the color of the image should be repaired, so as to achieve the image repair.
Program Implementation Analysis
- The characteristics of the calibrated noise, using the Cv2.inrange two value identification noise to the image binary processing, the specific code: Cv2.inrange (IMG, Np.array ([255, 255, 255]), the [240, 240, 240]~[255, 255, 255] other than the color processing for 0;
- The Dilate method of OpenCV is used to extend the area of the feature to optimize the image processing effect.
- Using the Inpaint method, the mask of noise is used as the parameter to infer and fix the image.
Full code
#coding=utf-8#图片修复import cv2import numpy as nppath = "img/inpaint.png"img = cv2.imread(path)hight, width, depth = img.shape[0:3]#图片二值化处理,把[240, 240, 240]~[255, 255, 255]以外的颜色变成0thresh = cv2.inRange(img, np.array([240, 240, 240]), np.array([255, 255, 255]))#创建形状和尺寸的结构元素kernel = np.ones((3, 3), np.uint8)#扩张待修复区域hi_mask = cv2.dilate(thresh, kernel, iterations=1)specular = cv2.inpaint(img, hi_mask, 5, flags=cv2.INPAINT_TELEA)cv2.namedWindow("Image", 0)cv2.resizeWindow("Image", int(width / 2), int(hight / 2))cv2.imshow("Image", img)cv2.namedWindow("newImage", 0)cv2.resizeWindow("newImage", int(width / 2), int(hight / 2))cv2.imshow("newImage", specular)cv2.waitKey(0)cv2.destroyAllWindows()
Image expansion and corrosion more information: Http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_morphological_ Ops/py_morphological_ops.html
Python-based Image repair program-can be used for watermark removal