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]#图片二值化处理, change the color outside of [240, 240, 240]~[255, 255, 255] to 0thresh = Cv2.inrange (IMG, NP).Array ([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 ( Span class= "hljs-string" > "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 ()     

Python-based picture fixes-available for watermark removal

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.