Python数学形态学实例分析
作者:cakincqm 时间:2022-11-22 22:32:50
本文实例讲述了Python数学形态学。分享给大家供大家参考,具体如下:
一 原始随机图像
1、代码
import numpy as np
import matplotlib.pyplot as plt
square = np.zeros((32,32))#全0数组
square[10:20,10:20]=1#把其中一部分设置为1
x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
square[x,y]=1#把随机位置设置为1
plt.imshow(square)#原始随机图像
plt.show()
2、运行结果
二 开运算
1、代码
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0数组
square[10:20,10:20]=1#把其中一部分设置为1
x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
square[x,y]=1#把随机位置设置为1
open_square = ndimage.binary_opening(square)#开运算
plt.imshow(open_square)
plt.show()
2、运行结果
三 膨胀运算
1、代码
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0数组
square[10:20,10:20]=1#把其中一部分设置为1
x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
square[x,y]=1#把随机位置设置为1
eroded_square = ndimage.binary_erosion(square)#膨胀运算
plt.imshow(eroded_square)
plt.show()
2、运行结果
四 闭运算
1、代码
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0数组
square[10:20,10:20]=1#把其中一部分设置为1
x, y =(32*np.random.random((2,15))).astype(np.int)#随机位置
square[x,y]=1#把随机位置设置为1
closed_square = ndimage.binary_closing(square)#闭运算
plt.imshow(closed_square)
plt.show()
2、运行结果
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/chengqiuming/article/details/78601456
标签:Python,数学形态学
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Golang Gin局部和全局中间件使用详解
2023-07-10 03:03:00
![](https://img.aspxhome.com/file/2023/7/86297_0s.jpg)
透明数据加密(TDE)库的备份和还原
2024-01-14 04:51:57
![](https://img.aspxhome.com/file/2023/7/94427_0s.png)
FrontPage XP设计教程4——Css样式表的应用
2008-10-11 12:25:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017123534164s.jpg)
总结用Pdb库调试Python的方式及常用的命令
2023-03-11 02:09:53
使用sqlplus连接Oracle数据库问题
2024-01-13 09:25:16
试试把xml和javascript写到同一个文件里面
2009-10-02 16:53:00
利用GAE&Google Gears做了一个简单的AJAX代理
2009-04-29 12:42:00
PyTorch模型转换为ONNX格式实现过程详解
2022-03-18 00:54:18
将Pytorch模型从CPU转换成GPU的实现方法
2023-07-07 00:11:00
python方差检验的含义及用法
2022-08-09 15:53:56
Python函数返回值实例分析
2022-06-23 06:59:07
mysql 数据库备份的多种实现方式总结
2024-01-18 23:03:25
详解JavaScript中的作用域链与闭包
2024-04-22 13:07:00
![](https://img.aspxhome.com/file/2023/6/135796_0s.jpg)
javascript封装的下拉导航菜单渐显效果
2007-08-04 20:11:00
透明度设置
2009-12-12 18:51:00
MySql树形结构(多级菜单)查询设计方案
2024-01-18 15:35:42
![](https://img.aspxhome.com/file/2023/4/116794_0s.png)
pandas选择或添加列生成新的DataFrame操作示例
2023-03-02 00:41:51
golang 字符串比较是否相等的方法示例
2024-02-05 14:45:07
js 分栏效果实现代码
2024-05-03 11:10:47
PHP register_shutdown_function()函数的使用示例
2023-10-07 08:06:27