Get values inside connected components?

1 view (last 30 days)
Mikhail  Kandel
Mikhail Kandel on 11 Jul 2014
Answered: Image Analyst on 12 Jul 2014
me=zeros(5,5,5);
me(1:2,1:2,1:2)=rand(2,2,2);
me((end-1):end,(end-1):end,(end-1):end)=rand(2,2,2);
CC = bwconncomp(me);
STATS=regionprops(CC,me,'Image');
% Returns a binary mask,
% but I want the values inside `me`
% without needing to use the old bwlabeln interface
I want to eventually process each segment as a slice along the Z axis, and using a whole array for this is computationally expensive.
I have tried to use a bounding box but the box often has overlapping segments in 3d.

Answers (1)

Image Analyst
Image Analyst on 12 Jul 2014
I'm not sure how to answer because I don't know what you want. Both bwconncomp() and regionprops() gives you the linear index of each labeled component - so just use it. If you want to get just one slice from the object, then use
cc = bwconncomp(binaryImage); % Do connected components analysis.
labeledImage = labelMatrix(cc); % Get the labeled image.
oneSlice = labeledImage(:,:,zValue); % Extract just one slice of it.
statsForOneSlice = regionprops(oneSlice, me, 'all'); % Measure the single slice.
Or something like that. Be more specific if you want better help.

Community Treasure Hunt

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

Start Hunting!