我不熟悉opencv。我有多张照片。左上角显示的示例图像之一。基本上,我想分离背景和前景,这样边缘是清晰的,我可以适当地检测轮廓。在
我尝试过很多过滤器,当然还有使用各种参数的阈值。在
最后,当我在photoshop filters gallery上查看时,我注意到了一个名为Stamp的过滤器,它给了我想要的结果(右上角)。它使边缘清晰,我想使用一些模糊的软角。在
我不确定如何使用pythoncv2获得和photoshop的stamp过滤器相同的操作?在
任何帮助或建议将不胜感激。在
原始原始图像
尝试1:--代码
import cv2
import numpy as np
from matplotlib import pyplot as plt
input_img = cv2.imread('images/Tas/t3.bmp')
desired_img = cv2.imread('images/stamp.jpg')
# gray scale
gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
kernel = np.ones((3,3),np.uint8)
thresh1 = cv2.threshold(input_img,80,255,cv2.THRESH_BINARY)[1]
erosion1 = cv2.erode(thresh1,kernel,iterations = 1)
dilation1 = cv2.dilate(erosion1,kernel,iterations = 1)
thresh2 = cv2.threshold(input_img,120,255,cv2.THRESH_BINARY)[1]
erosion2 = cv2.erode(thresh2,kernel,iterations = 1)
dilation2 = cv2.dilate(erosion2,kernel,iterations = 1)
titles = ['Original', 'Desired','thresh1', 'erosion1','dilation1','thresh2','erosion2','dilation2']
images = [input_img, desired_img, thresh1, erosion1,dilation1, thresh2,erosion2, dilation2]
for i in xrange(8):
plt.subplot(2,4,i+1),plt.imshow(images[i])
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
输出:
这可能会有助于为自己添加一些用于高斯模糊和阈值过滤的滑块,您可以获得相当不错的结果:
下面是我用来生成它的基本片段:
随意添加其他过滤器到混合和实验滑块。在
相关问题 更多 >
编程相关推荐