Why is my centroid giving only 1 element per blob using region props?

조회 수: 5 (최근 30일)
they should be 2 per blob x and y elements
  댓글 수: 2
Guillaume
Guillaume 2017년 7월 21일
Without seeing some code or example to replicate your issue, it's difficult for us to say what you're doing wrong.
Elias Unk
Elias Unk 2017년 7월 22일
Iregion=regionprops(bw2,'centroid');
bw2 being a binary image of objects.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2017년 7월 22일
It's not clear exactly what you're calling an "element". I'll use more precise terminology. If your Iregion structure array is just one structure, then you have just one blob. The Centroid field of that structure will be a 1-by-2 array with the x and y locations of the centroid of that blob.
If you have multiple blobs, then you need to add an index after the structure variable name to get just one of the blobs, try this:
props = regionprops(bw2,'centroid');
hold on;
for k = 1 : length(props)
% Get x and y centroid of the k'th blob.
xCentroid = props(k).Centroid(1);
yCentroid = props(k).Centroid(2);
plot(xCentroid, yCentroid, 'r+', 'MarkerSize', 40, 'LineWidth', 2);
% Let user know what they are
message = sprintf('The largest blob has area %d and a centroid at (x,y) = (%f, %f)',...
props.Area, xCentroid, yCentroid)
uiwait(msgbox(message));
end
You can also get all the x and y centroids into arrays doing this:
centroids = [props.Centroid];
xCentroids = centroids(1:2:end);
yCentroids = centroids(2:2:end);
  댓글 수: 10
Elias Unk
Elias Unk 2017년 7월 22일
Can you explain why numObjects was 56 running the following
[label,numObjects]=bwlabel(bw2,4);
like was it counting every shape before and now it excludes none blob like shapes?
Image Analyst
Image Analyst 2017년 7월 23일
It is not 56. I doubt it ever was with the image that you supplied me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by