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

问题描述

我有一个坐标文本文件,希望将其读入regionprop.我希望使用regionprop进行像Centroid这样的少量分析.我该怎么办?

I have a coordinate text file and I wish to read it into a regionprop. I wish to use the regionprop for few analysis like Centroid. How can I do it?

代码:

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

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

stats = regionprops(C,'Centroid')

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

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
89  10
88  10

推荐答案

您为什么不只使用2017b中引入的centroid?

Why don't you just use centroid, which was introduced in 2017b?

[x,y] = centroid(C);

如果坚持使用regionprops(比直接对多边形进行操作要慢,并且准确性不高),那么您会误解regionprops的工作原理.区域道具在图像上起作用.您需要先创建图像,然后将图像传递到区域道具.

If you are insistent on regionprops (which is slower, and less accurate than operating on the polygon directly) then you are misunderstanding how region props works. Region props works on images. You need to first create an image, then pass the image to region props.

bw = roipoly(zeros(120), C(:,1), C(:,2));
stats = regionprops(bw);

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

10-22 22:48