2017-09-06 37 views
-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.顏色總是相同

+2

添加自己的代碼後。 – zindarod

+2

這太寬泛了,問題顯示出一些缺乏工作。一些可能的問題:總是位於左下方?看起來不透明,對吧?顏色總是一樣的?你想做美學還是不讓別人看到日期(對技術有巨大影響)?等等......如果美學+ intransparent + color + fixed-pos:搜索這種固定顏色;掩蓋它們,使用修補(例如使用scikit-image)。 – sascha

+0

@Zissouu這是我的學術和研究項目 – user3153140

回答