一 原始随机图像
1、代码
import numpy as npimport matplotlib.pyplot as pltsquare = np.zeros((32,32))#全0数组square[10:20,10:20]=1#把其中一部分设置为1x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置square[x,y]=1#把随机位置设置为1plt.imshow(square)#原始随机图像plt.show()
2、运行结果
二 开运算
1、代码
import numpy as npimport matplotlib.pyplot as pltfrom scipy import ndimagesquare = np.zeros((32,32))#全0数组square[10:20,10:20]=1#把其中一部分设置为1x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置square[x,y]=1#把随机位置设置为1open_square = ndimage.binary_opening(square)#开运算plt.imshow(open_square)plt.show()
2、运行结果
三 膨胀运算
1、代码
import numpy as npimport matplotlib.pyplot as pltfrom scipy import ndimagesquare = np.zeros((32,32))#全0数组square[10:20,10:20]=1#把其中一部分设置为1x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置square[x,y]=1#把随机位置设置为1eroded_square = ndimage.binary_erosion(square)#膨胀运算plt.imshow(eroded_square)plt.show()
2、运行结果

四 闭运算
1、代码
import numpy as npimport matplotlib.pyplot as pltfrom scipy import ndimagesquare = np.zeros((32,32))#全0数组square[10:20,10:20]=1#把其中一部分设置为1x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置square[x,y]=1#把随机位置设置为1closed_square = ndimage.binary_closing(square)#闭运算plt.imshow(closed_square)plt.show()
2、运行结果
2146

被折叠的 条评论
为什么被折叠?



