一 原始随机图像

1、代码
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. square = np.zeros((32,32))#全0数组
  4. square[10:20,10:20]=1#把其中一部分设置为1
  5. x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
  6. square[x,y]=1#把随机位置设置为1
  7. plt.imshow(square)#原始随机图像
  8. plt.show()
2、运行结果

数学形态学
 
 
二 开运算
1、代码
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy import ndimage
  4. square = np.zeros((32,32))#全0数组
  5. square[10:20,10:20]=1#把其中一部分设置为1
  6. x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
  7. square[x,y]=1#把随机位置设置为1
  8. open_square = ndimage.binary_opening(square)#开运算
  9. plt.imshow(open_square)
  10. plt.show()
2、运行结果

数学形态学
 
 
三 膨胀运算
1、代码
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy import ndimage
  4. square = np.zeros((32,32))#全0数组
  5. square[10:20,10:20]=1#把其中一部分设置为1
  6. x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
  7. square[x,y]=1#把随机位置设置为1
  8. eroded_square = ndimage.binary_erosion(square)#膨胀运算
  9. plt.imshow(eroded_square)
  10. plt.show()
2、运行结果

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

数学形态学
 

相关文章:

  • 2021-12-19
  • 2021-11-07
  • 2021-04-27
  • 2021-11-18
  • 2021-06-17
  • 2021-10-21
猜你喜欢
  • 2021-12-17
  • 2021-08-18
  • 2021-11-03
  • 2021-04-13
  • 2021-04-17
  • 2021-06-25
  • 2021-06-25
相关资源
相似解决方案