Python-based Image repair program-can be used for watermark removal

Source: Internet
Author: User

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
    1. 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;
    2. The Dilate method of OpenCV is used to extend the area of the feature to optimize the image processing effect.
    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.