Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use contrast Luminance transform to remove Watermark in OpenCV

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

OpenCV how to use contrast luminance transformation to achieve watermark removal, in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Guide reading

This paper mainly introduces an example of using OpenCV luminance / contrast transform to remove image watermark.

Background introduction

The most commonly used method to remove the watermark in OpenCV is inpaint, which removes the watermark by image restoration, and the final effect depends on the actual image (sometimes good or bad). Some images do not apply the inpaint method to remove the watermark, such as the watermark in the image containing text below. Even if the mask image of the watermark is provided, the text information will be lost after repair, which is not what we want.

So the question is, how to remove the watermark in the above image? Is there a general way to remove these watermarks? The answer is: there is no general method, only specific analysis of specific problems!

Implementation steps

Looking carefully at the above image and analyzing the pixel values of the text and the watermark, it is not difficult to find that there is a significant difference in the grayscale value or RGB value between the text and the watermark:

[1] RGB value of pattern watermark (sample value: 239236253)

[2] RGB value of text watermark (sample value: 215215215)

[3] text RGB value (sample value: 114112125)

Next, change the contrast and brightness of the image:

Result = alpha * src-beta (alpha = 2.0, beta =-165)

When the contrast is increased * 2, the watermark disappears, and then the brightness is reduced to compensate:

Python-OpenCV implementation code:

Import cv2import numpy as npimg = cv2.imread ("mark.jpg") alpha = 2.0beta =-165 result = alpha * img + betaresult= np.clip (result, 0255) .astype (np.uint8) cv2.imwrite ("result.png", result)

C++ OpenCV implementation code:

# include # include using namespace std;using namespace cv;int main () {Mat src = imread ("mark.jpg"); if (src.empty ()) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report