如何斑点的重心值存储在一个阵列? [英] How to store the Centroid values of blobs in one Array?

查看:194
本文介绍了如何斑点的重心值存储在一个阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图片都有一定数量的斑点各种形状。我想这些的中心值存储在一个阵列供未来使用。所以,我想下面的code,但没有奏效。因此,谁能帮助我?

示例:

 对于i = 1:长度(STATS)
       心= STATS(我).Centroid;
       阵列=零(长度(STATS));
       阵列(ⅰ)=质心;
结束

我要像中心数据存储在一个阵列下面

  =数组145 145
14 235
145 544
14 69
74 55


解决方案

假设

  STATS(1).Centroid = [145 145];
STATS(2).Centroid = [14 235]; %等等...

尝试:

  =阵重塑([STATS.Centroid],2,大小(STATS,2))
阵列=   145 145
    14 235
   145 544
    14 69
    74 55

如何工作的:

[STATS.Centroid] [STATS(1).Centroid,STATS(2).Centroid,... STATS短版(N).Centroid] 。这会给你的值作为载体。 重塑 是然后用它做成你想要的大小。

My picture has a certain number of various shapes of blobs. I want to store those centroid values in one array for the future use. So I tried the following code, but it did not work. So can anyone help me?

Sample:

for i = 1:length(STATS)
       centroid = STATS(i).Centroid;
       array = zeros(length(STATS));
       array(i) = centroid;
end

I want to store the centroid data in one array like below

array=

145 145
14  235 
145 544
14  69
74  55

解决方案

Assuming

STATS(1).Centroid = [145 145];
STATS(2).Centroid = [14 235];   % Etc...

Try:

array = reshape([STATS.Centroid],2,size(STATS,2))' 
array =

   145   145
    14   235
   145   544
    14    69
    74    55

How this works:

[STATS.Centroid] is a short version of [STATS(1).Centroid, STATS(2).Centroid, .. STATS(n).Centroid]. This will give you the values as a vector. reshape is then used to make it into your desired size.

这篇关于如何斑点的重心值存储在一个阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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