python去掉图片上的文字水印_使用python删除图像中的水印

我想用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它是透明的

三。颜色总是一样的

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值