square = np.zeros((32,32))
square[10:20, 10:20] = 1
x,y =(32*np.random.random((2,15))).astype(np.int)
# 指的是维数,,15是每个数组里面元素的个数,数组的范围是0-1.并且把数值的类型设置为整数
square[x, y ] = 1 #把相应位置的元素,设置为1
x,y = (32 * np.random.random((2, 15))).astype(np.int)
square[x, y] = 0
plt.imshow(square)
plt.title('original image')
plt.show()
erosion = ndimage.binary_erosion(square) # erosion 腐蚀!
plt.imshow(erosion)
plt.title('eroded image')
plt.show()
···
dilation = ndimage.binary_dilation(square) # 膨胀操作
plt.imshow(dilation)
plt.title('dilation image')
plt.show()
opens = ndimage.binary_openning(square) #开操作,先腐蚀再膨胀!!
plt.imshow(opens)
plt.title('open image')
plt.show()
closed = ndimage.binary_closing(square) #closing 先膨胀再腐蚀
plt.imshow(closed)
plt.title('closing image')
plt.show()