今天首次尝试了使用Inpaint去除图片的logo,测试效果源于mask的选取,切割的是否标准。废话少说,上代码:
一共测试了8张图片,图像尺寸各一
import numpy as np
import cv2
import os
os.chdir("E:\pytest\Inpainting-master")
paths = [("t"+str(x)) for x in list(range(1,9))]
for i in paths:
img = cv2.imread(i+".jpg")
#判断像素
if img.shape[0] == 610 and img.shape[1] == 810:
mask = cv2.imread('810x610.jpg',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
elif img.shape[0] == 700 and img.shape[1] == 700:
mask = cv2.imread('700x700.jpg',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
elif img.shape[0] == 525 and img.shape[1] == 700:
mask = cv2.imread('700x525.jpg',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
elif img.shape[0] == 480 and img.shape[1] == 640:
mask = cv2.imread('640x480.jpg',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
elif img.shape[0] == 700 and img.shape[1] == 525:
mask = cv2.imread('525x700.jpg',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
cv2.imwrite("e:/result/"+i+"_result.jpg",dst)
print("已处理完图片"+i+"!")
网友评论