我想用python检测并删除图像中的水印。我试过opencv,但做不到。下面是示例图像。这里时间是所有图像的水印。 Image attached here
随附样本代码
#coding:utf-8
import os
import os.path
#import Image
def hasBlackAround(x, y, distance, img):
w, h = img.size
startX = 0 if x - distance < 0 else x - distance
startY = 0 if y - distance < 0 else y - distance
endX = w - 1 if x + distance > w - 1 else x + distance
endY = h - 1 if y + distance > h - 1 else y + distance
hasBlackAround = False
for j in range(startX, endX):
for k in range(startY, endY):
r, g, b = img.getpixel((j, k))
#if r < 130 and g < 130 and b < 130:
if r >= 255 and g >= 255 and b >= 255:
return True
return False
from PIL import Image
img = Image.open("E:/Projects/Analysis/unnamed.png")
w, h = img.size
rgb_im = img.convert('RGB')
for x in range(0, w - 1):
for y in range(0, h - 1):
if not hasBlackAround(x, y, 1, rgb_im):
rgb_im.putpixel((x, y), (255,255,255))
rgb_im.save("E:/Projects/Analysis/1_output_v1.jpg")
有关图像的其他信息: 1它总是在左下角 2它是透明的 三。颜色总是一样的
修复技术通过填充图像中的任何空白来重建图像。在
请尝试opencv中的修复方法:
http://docs.opencv.org/3.0-beta/modules/photo/doc/inpainting.html
相关问题 更多 >
编程相关推荐