matrixworld

利用python去除红章

近期接的一个需求需要去除图片的红章,用到了PIL库。

from PIL import Image,ImageEnhance
import os
#f="5-12 - 0001.tif"

for rt, dirs, files in os.walk("D:\工作文件夹\OCR\pictest"):
for f in files:
fname = os.path.splitext(f)
newName = fname[0] + \'_nostamp\' + fname[1]
im=Image.open(os.path.join(rt,f))
im=ImageEnhance.Contrast (im).enhance(1.5)
im=ImageEnhance.Sharpness(im).enhance(1.5)
w,h=im.size
print("PicSize:w=%d,h=%d.Processing..." %(w,h))
pixels = im.load()
if w>=h:
p,q=w//3,h//3
else:
p,q=w//2,h//4

for x in range(p):
for y in range(q):
if pixels[x,y][0]>=150:
pixels[x,y]= (255,255,255)
im.save("D:\工作文件夹\OCR\picout\\"+newName)
#im.show()

发表于 2016-07-07 09:52  贝壳闪亮  阅读(468)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-03-29
  • 2021-12-10
  • 2021-07-16
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-07-16
猜你喜欢
  • 2022-01-21
  • 2021-12-25
  • 2021-12-10
  • 2022-12-23
  • 2022-01-19
  • 2021-10-29
  • 2022-01-09
相关资源
相似解决方案