How to perform regionprops to specifically get object's centroid

17 ビュー (過去 30 日間)
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019 年 1 月 27 日
i have a vector row like this :
A = [1;1;1;0;0;0;0;0;1;1;0;0;1;1;1;1;0;0;0;0;1;1;1];
And use regionprops function to retrieve the centroid of 0's values.
props = regionprops(A==0, 'Centroid');
xyCentroids = [props.Centroid];
Now xyCenroids variable has indices of all 0's centroids.
How to retrieve the indices of 0's Centroids that only have length more than 2 ? So that the smallest 0's area (like A(11:12,1)) won't pass the process.
Thanks before

採用された回答

Image Analyst
Image Analyst 2019 年 1 月 27 日
That's not a row vector. It's a column vector. Anyway, try using bwareafilt():
A = [1;1;1;0;0;0;0;0;1;1;0;0;1;1;1;1;0;0;0;0;1;1;1]
% Extract blobs only of length 3 or longer.
blobs = bwareafilt(A == 0, [3, inf])
% Measure centroids
props = regionprops(blobs, 'Centroid');
xyCentroids = vertcat(props.Centroid)
yCentroids = xyCentroids(:, 2)
You'll get
yCentroids =
6
18.5
  2 件のコメント
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019 年 1 月 31 日
@ Image Analyst : Thank you so much sir. Always
Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019 年 1 月 31 日
@ Image Analyst : sorry sir i was mistake, yes it's collumn vector.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by