Python-based Image repair program (watermark removal)

Source: Internet
Author: User
This article mainly introduces the Python picture repair program related data, can be used to achieve the image watermark removal, the main use of OPENCV this framework to achieve, the text through the sample code introduced in very detailed, the need for friends can refer to, let's see together

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.

OpenCV

At present, OpenCV gradually becomes a general basic research and product development platform. OpenCV This name contains the meaning of both open and computer vision. In fact, open refers to open source (open source, which is the opensource), and computer vision refers to computer vision. The development of OPENCV has important influence on software development. To learn more, you can refer to this article: http://www.jb51.net/article/127911.htm

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# Image Repair import Cv2import numpy as Nppath = "Img/inpaint.png" img = cv2.imread (path) hight, width, depth = Img.shap E[0:3] #图片二值化处理, change the color of [240, 240, 240]~[255, 255, 255] to 0thresh = Cv2.inrange (img, Np.array ([+], [+]), 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 ()

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.