如何在分割图像中找到对象的质心

时间:2017-02-24 16:20:16

标签: matlab image-processing centroid

我有一个二进制图像,并将此图像分成多个块。例如a(60x60)图像分为4个块

(30x30) (30x30) (30x30) (30x30)

现在我想计算每个块的质心,我查找一个公式来做到这一点并最终得到

Centroid Formula

我如何使用matlab做到这一点,这个方法与regionprops(...,'Centroid')

之间有什么区别?

更新1: 这是我到目前为止所写的......

m = 2;
n = 2;
im = imread('C:\Users\Home\Desktop\Samples\0_1.bmp');
flippedIm = 1-im;
boundary = regionprops(flippedIm, 'BoundingBox');
boundedIm = vertcat(boundary(1).BoundingBox);
xmin = boundedIm(1);
ymin = boundedIm(2);
width = boundedIm(3);
height = boundedIm(4);
croppedIm = imcrop(flippedIm,[xmin ymin width height]);

%USE X TO TEST
x = reshape(1:9,3,3)';
x = myPadding(x,m,n);

%a contains cells (blocks)
a = mySplit(x,m,n);

measurements = regionprops(x,'Centroid');
display(measurements(1));

该代码的结果是......

measurements = 

9x1 struct array with fields:

Centroid

0 个答案:

没有答案