我意识到这是一个旧线程,但我想建议一种解决此类问题的方法。
您可以尝试使用基于纹理的分割,因为草地背景与牛的纹理不同。
查看this link,其中图像的纹理能量特征是根据 Laws 的技术定义的。
这是 Python 中的法律技术的实现。它通过定义用于提取图像中不同特征的 2D 内核来工作,例如边缘、波纹、斑点及其组合。下面的函数返回9张图片,可以从中提取纹理特征。
def laws(array):
# Define the 1D kernels
L5 = np.array([1,4,6,4,1]) # level
E5 = np.array([-1,-2,0,2,1]) # edge
S5 = np.array([-1,0,2,0,-1]) # spot
R5 = np.array([1,-4,6,-4,1]) # ripples
# Generate 2D kernels
L5E5 = np.outer(L5,E5)
E5L5 = np.outer(E5,L5)
L5R5 = np.outer(L5,R5)
R5L5 = np.outer(R5,L5)
E5S5 = np.outer(E5,S5)
S5E5 = np.outer(S5,E5)
S5S5 = np.outer(S5,S5)
R5R5 = np.outer(R5,R5)
L5S5 = np.outer(L5,S5)
S5L5 = np.outer(S5,L5)
E5E5 = np.outer(E5,E5)
E5R5 = np.outer(E5,R5)
R5E5 = np.outer(R5,E5)
S5R5 = np.outer(S5,R5)
R5S5 = np.outer(R5,S5)
return (0.5*(correlate(array, L5E5) + correlate(array, E5L5)), \
0.5*(correlate(array, L5R5) + correlate(array, R5L5)), \
0.5*(correlate(array, E5S5) + correlate(array, S5E5)), \
correlate(array, S5S5), \
correlate(array, R5R5), \
0.5*(correlate(array, L5S5) + correlate(array, S5L5)), \
correlate(array, E5E5), \
0.5*(correlate(array, E5R5) + correlate(array, R5E5)), \
0.5*(correlate(array, R5S5) + correlate(array, S5R5)))