python实现根据给定坐标点生成多边形mask的例子
作者:Selieyo 时间:2022-03-22 14:40:15
处理数据集的过程中用到了mask 但是源数据集中只给了mask顶点的坐标值,那么在python中怎么实现生成只有0、1表示的mask区域呢?
主要借鉴cv2中的方法:
(我使用的数据情况是将顶点坐标分别存储在roi.mat中的x和y元素)
matfn = 'roi.mat'
data = sio.loadmat(matfn)
x_cor = data['x']
y_cor = data['y']
im = np.zeros(图像对应尺寸, dtype="uint8")
cor_xy = np.hstack((x_cor, y_cor))
cv2.polylines(im, np.int32([cor_xy]), 1, 1)
cv2.fillPoly(im, np.int32([cor_xy]), 1)
mask_array = im
这样就可以得到mask啦,注意:首先坐标对是数组形式,我们需要用‘[ ]' 转换为列表形式,然后用np.int32转化格式,这两步都放在上述标红代码中完成了。不然很容易报错。
来源:https://blog.csdn.net/sinat_22147265/article/details/88624675
标签:python,坐标点,多边形,mask
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python基础之模块相关知识总结
2021-09-06 21:39:39
![](https://img.aspxhome.com/file/2023/1/70251_0s.png)
php获取qq用户昵称和在线状态(实例分析)
2023-11-14 11:19:22
python中的global关键字的使用方法
2023-07-15 13:26:50
[关注细节的最佳方案]有效期时间格式的展现
2009-10-30 18:51:00
![](https://img.aspxhome.com/file/UploadPic/200910/30/validity1-63s.gif)
[设计]DREAMWEAVER 问题集锦
2010-09-02 12:31:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113121103s.jpg)
SQL Server索引管理的六大铁律
2009-03-25 14:05:00
Sql Server 2012 转换函数的比较(Cast、Convert和Parse)
2012-08-21 10:21:40
微信小程序之多文件下载的简单封装示例
2023-10-19 21:10:06
python爬取哈尔滨天气信息
2023-12-10 22:28:05
IE7下 filter:Alpha(opacity=xx) 的小问题
2008-12-02 16:24:00
XML文件的显示——CSS和XSL
2007-10-15 18:48:00
![](https://img.aspxhome.com/file/UploadPic/200710/15/20071015185959969s.jpg)
Python随机函数库random的使用方法详解
2021-06-07 16:16:23
![](https://img.aspxhome.com/file/2023/6/70106_0s.png)
如何获知文件被改动的情况?
2009-11-24 20:42:00
微信小程序request请求后台接口php的实例详解
2023-11-11 14:24:04
最强大最好最全的javascript 验证表单的例子
2010-03-14 11:26:00
Python使用微信接入图灵机器人过程解析
2022-05-29 04:03:14
![](https://img.aspxhome.com/file/2023/1/64711_0s.jpg)
Oracle 10g client 安装图解教程
2023-07-13 20:40:10
![](https://img.aspxhome.com/file/2023/2/64462_0s.png)
PS中执行N遍选定动作的脚本
2008-02-22 21:33:00
![](https://img.aspxhome.com/file/UploadPic/20082/22/2008222213917983s.gif)
如何提升JavaScript的运行速度(DOM篇)[译]
2009-02-25 12:24:00
mysql慢查询的分析方法
2010-08-03 14:51:00