绘制坐标文本文件以供regionprop使用-Matlab [英] plot coordinate text file for regionprop usage - Matlab

查看:58
本文介绍了绘制坐标文本文件以供regionprop使用-Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于上一个问题(读取坐标文本文件以供regionprop使用-Matlab )我希望绘制具有扩展边界(零点+ 10)的对象,但是它不起作用.有什么原因吗?

Based on a previous question (read coordinate text file for regionprop usage - Matlab) I wish to plot the object with an extended boundaries (zeros+10) but it does not work. Any reason why?

代码:

clc;
clear;

filename = fullfile('E:/outline.txt');

fileID = fopen(filename);
C = textscan(fileID,'%d %d');
fclose(fileID);

xMax = double(max(C{1})-10)
yMax = double(max(C{2})+10)

bw=roipoly(zeros(xMax ,yMax ),C{1},C{2});
imshow(bw);
stats = regionprops(bw);

坐标文本文件的内容如下:

coordinate text file content is as follow:

88  10
87  11
87  12
88  13
88  14
92  21
93  22
93  23
94  24
95  25
100 33
101 34
102 34
103 34
103 33
103 32
103 31
103 30
103 29
103 28
103 27
102 26
102 25
101 24
101 23
100 22
100 21
100 20
99  19
99  18
94  12
93  12
92  12
91  11
90  11

推荐答案

xMax = double(max(C{1})-10)

应该是+10.这样,您可以使图像小于多边形.

That should probably be +10. This way you make the image smaller than your polygon.

如果您还想在左侧扩展图像,请向多边形坐标添加一个偏移量:

If you want to extend the image on the left side also, add an offset to your polygon coordinates:

bw = roipoly(zeros(yMax, xMax), C{1}+5, C{2}+5);

还请注意,我从您的代码中交换了xMaxyMax,这可能是您遇到的另一个问题.矩阵尺寸指定为(高度,宽度),矩阵的索引也指定为.但是某些功能(例如roipoly)的坐标首先是x,其次是y.这是MATLAB语法的常见陷阱.

Note also that I swapped xMax and yMax from your code, this might be another issue you're seeing. Matrix dimensions are specified as (height, width), as are indices into the matrix. But some functions such as roipoly take coordinates with x first and y second. This is a common pitfall with MATLAB syntax.

我刚刚了解到以上内容与

I just learned that the above is the same as

bw = roipoly(yMax, xMax, C{1}+5, C{2}+5);

这篇关于绘制坐标文本文件以供regionprop使用-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆