简体   繁体   English

在图像中用白色替换黑色,用白色替换黑色

[英]replace black by white and white by black in images

I have black and white images (png) as follow : l want to replace the black background font color into white and the written character in white to black. 我有黑白图像(png),如下所示:l我想将黑色背景字体颜色替换为白色,并将书写字符从白色替换为黑色。 How to identify color and replace it ? 如何识别和更换颜色?

for that l have thousand of images. 因为我有成千上万的图像。 It s not possible to manually identify in which image the character is in black and the background is in white and vice versa. 手动识别黑色字符和背景白色字符是不可能的,反之亦然。 all what l need is for every image l check if the character is written in black if not change the character color to black and the background to white. 我需要的是每个图像l检查是否将字符写成黑色(如果没有),将字符颜色更改为黑色,将背景更改为白色。

here is a link to my sample of data : https://drive.google.com/open?id=0B-QJnh0Uw96lbFVHbVBPclhycFk 这是我的数据样本的链接: https : //drive.google.com/open?id=0B-QJnh0Uw96lbFVHbVBPclhycFk

在此处输入图片说明

在此处输入图片说明

如果白色内容的值为255(如果它是二进制掩码1),则从255中减去您的图像。在python中,如果您的图像为img

cv2.subtract(255, img) 

对于您提供的示例,如果图像尺寸>〜26像素宽,请反转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM