-2
我想用python检测和删除图像中的水印。我尝试过opencv,但无法完成。以下是示例图片。这里的时间是所有图像上的水印。 Image attached here使用python删除图像中的水印
示例代码附
#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.它是透明 3.颜色总是相同
添加自己的代码后。 – zindarod
这太宽泛了,问题显示出一些缺乏工作。一些可能的问题:总是位于左下方?看起来不透明,对吧?颜色总是一样的?你想做美学还是不让别人看到日期(对技术有巨大影响)?等等......如果美学+ intransparent + color + fixed-pos:搜索这种固定颜色;掩盖它们,使用修补(例如使用scikit-image)。 – sascha
@Zissouu这是我的学术和研究项目 – user3153140