Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何使用矩阵或二进制图像绘制多边形以使用图像处理功能?

我正在开发一个使用多边形(凹面或凸面)的matlab程序。我需要在多边形上使用像imdilate或imerode等的图像处理功能。为此,我应该将多边形转换为图像。我想知道是否有一种方法可以直接在二进制矩阵中绘制多边形(1表示前景,0表示背景)?

当前,我使用“ getframe”,然后使用“ frame2im”,然后使用“ im2bw”功能。但是它的缺点是我无法控制最终图像的大小(=矩阵)(即,将帧转换为图像时图像的大小以像素为单位),原因是matlab不会以像素显示其图(?)。因此,每当有人在绘图上进行“放大”或“缩小”时,结果矩阵(= image)都会不同。

我的代码:

Polygon = [ 15 45 33 30 40 23 ; 9 9 24 15 13 13]'; figure(1); clf; patch(Polygon(:,1),Polygon(:,2),'black'); axis off %convert the plot to binary image frame = getframe(gca); im =frame2im(frame); level = graythresh(im); bw = ~im2bw(im,level); %draw the resulting image imtool(bw) %dilate the image SE = strel('square',5); bw2 = imdilate(bw,SE); %draw the dilated image imtool(bw2)
回答:
也许您可以使用poly2mask来计算感兴趣的区域,而不是像脚本中那样使用patch对其进行绘制。例如

Polygon = [ 15 45 33 30 40 23 ; 9 9 24 15 13 13]'; ImageWidth = 100; ImageHeight = 50; bw = poly2mask(Polygon(:,1),Polygon(:,2),ImageHeight,ImageWidth); imshow(bw) 上面代码的结果bw是此图像。





更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 03:10


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.