OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)

Color_Space 2021-11-25 10:54:29
其他 OpenCV 其它 计算机视觉 图像处理

 

视觉/图像重磅干货,第一时间送达!

导读

本文主要介绍使用OpenCV亮度/对比度变换来去除图片水印的实例。

背景介绍

OpenCV中去除水印最常用的方法是inpaint,通过图像修复的方法来去除水印,最终效果也要根据实际图像来看(时好时坏)。有些图像并不适用inpaint方法来去除水印,比如下面的这种包含文本的图像中的水印,即便提供了水印的mask图,修复后也会丢失文字信息,这并不是我们想要的。

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_OpenCV

那么问题来了,上面图像中的水印该如何去除?有没有一种通用方法,能很好去除这些水印?答案是:没有通用方法,只能具体问题具体分析!

实现步骤

仔细观察上面的图像并分析文本与水印的像素值不难发现,图中文本和水印的灰度值或者RGB值有明显差异:

【1】图案水印RGB值(取样值:239,236,253)

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_通用方法_02

【2】文字水印RGB值(取样值:215,215,215)

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_图像处理_03

【3】文本RGB值(取样值:114,112,125)

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_图像去水印_04

接下来对图像做对比度和亮度变换:

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

提高对比度*2时水印消失,然后降低亮度做补偿:

Python-OpenCV实现代码:

import cv2import numpy as np
img = cv2.imread("mark.jpg")alpha = 2.0beta = -165result= alpha * img + betaresult= np.clip(result, 0, 255).astype(np.uint8)cv2.imwrite("result.png", result)
  • 1.
  • 2.

C++ OpenCV实现代码:

#include <iostream>#include <opencv2/opencv.hpp>
using namespace std;using namespace cv;
int main(){ Mat src = imread("mark.jpg"); if (src.empty()) { cout << "src img load failed!" << endl; return 1; } imshow("src", src); Mat result = 2.0 * src - 165; imshow("result", result); waitKey(); imwrite("result.png", result); return 0;}
  • 1.
  • 2.
  • 3.

运行结果图:

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_OpenCV_05

原图与结果图对比:

OpenCV对比度亮度变换竟能用来去水印(附Python/C++源码)_通用方法_06

—THE END—

版权声明
本文为[Color_Space]所创,转载请带上原文链接,感谢
https://blog.51cto.com/stq054188/4683330

  1. Python basic syntax -- Boolean operation, break, continue, pass
  2. Python basic syntax -- loop
  3. Python first experience - efficient office, data analysis, crawler
  4. Modulenotfounderror: no module named 'Django summernote details
  5. Key points for Django to make personal blog website
  6. Path setting of templates in Django settings
  7. Leetcode 1611. Minimum one bit operations to make integers Zero (Python)
  8. Directory C: \ users \ a \ desktop \ Django_ The blog master is registered as the GIT root, but no git repository details are found there
  9. Django. Core. Exceptions. Improveconfigured: application labels aren't unique, duplicates: admin
  10. How to verify that Django has created the project details correctly
  11. How to create a database when using Django to construct a website
  12. The solution of using Django framework to create project in Windows system
  13. Running Python virtual environment on win10 system to execute ll_ Env \ scripts \ activate: unable to load file elaboration scheme
  14. Detailed explanation of constructing virtual environment with Django in Python 3
  15. Python implementation of affine cipher
  16. RC4 Python implementation
  17. Simple: Python_ Automatic body temperature clock
  18. 用python把两个csv中的日期的列提出年,做出新的一列,再把两个csv表格按照新做出的日期这列和ID号合并为一个表。
  19. python中类实例化后,其对象无法被其他模块调用方法
  20. [JSON] - Python creates JSON file format
  21. Utilisez Python pour proposer l'année de la colonne de date dans les deux CSV, faire une nouvelle colonne, puis combiner les deux tableaux CSV en un seul tableau avec la colonne de date et le numéro d'identification.
  22. 关于#python#的问题,请各位专家解答!
  23. ***
  24. ***
  25. 關於#python#的問題,請各比特專家解答!
  26. S'il vous plaît répondre aux questions de Python!
  27. About the import of Python class
  28. Magic Python property decorator: 1 line of code makes Python methods become properties in seconds
  29. Python 音频调整音量(附代码) | Python工具
  30. Python programming ideas [series of articles]
  31. Python crawler programming idea (67): modify nodes using pyquery
  32. Python crawler programming idea (66): using pyquery to obtain node information
  33. Python crawler programming idea (65): find nodes using pyquery
  34. Python crawler programming idea (64): using CSS selectors in pyquery
  35. Python crawler programming idea (63): basic knowledge of pyquery
  36. Python crawler programming idea (62): project practice: capturing cool dog online red song list
  37. Python crawler programming idea (61): project practice: capturing rental information
  38. Python crawler programming idea (60): get CSS selector code through browser
  39. Python爬虫编程思想(85):在Python中使用非关系型数据库
  40. Volume de réglage audio Python (avec Code) | outils Python
  41. Python crawler programming idea (59): get attribute value and text with beautiful soup CSS selector
  42. Python crawler programming idea (58): nested selection nodes with beautiful soup CSS selectors
  43. Python crawler programming idea (57): basic usage of CSS selector in beautiful soup
  44. Python crawler programming idea (56): find method of beautiful soup method selector
  45. Python crawler programming idea (55): find of beautiful soup method selector_ All method
  46. Python crawler programming idea (54): use beautiful soup to select sibling nodes
  47. Python crawler programming idea (53): use beautiful soup to select the parent node
  48. Django3.0 solves the problem of error reporting in reverse parsing
  49. Precautions for Python crawler
  50. Python 3 crawler series (1) -- climbing blind date websites
  51. Python到底是什么?为什么要学Python?
  52. #yyds干货盘点#Pandas数据清洗实用指南
  53. Python打包exe文件无法运行
  54. Two common ways to save files in Python
  55. #yyds幹貨盤點#Pandas數據清洗實用指南
  56. Yyds Dry Inventory pandas Data Cleaning Practical Guide
  57. PYTHON用LSTM长短期记忆神经网络的参数优化方法预测时间序列洗发水销售数据
  58. Python集成学习:自己编写构建AdaBoost分类模型可视化决策边界及sklearn包调用比较
  59. Python 3 makes a search software
  60. Python 3 simulated microblog login