How can I extract each connected object in a 3D array?

1 view (last 30 days)
I have a 3D array (attached as Y.mat) and I find the connected components using bwconncomp. I used the following coding to extract each component but X is a zero array with the same size as Y. Please, help me to solve this problem.
Thanks
May
CC = bwconncomp(Y, 26); % Y is the 3D array
L = labelmatrix(CC);
for i=1:length(CC.PixelIdxList)
X = (L==i);
imshow3D(a); % use existing function to show 3D
end

Accepted Answer

Image Analyst
Image Analyst on 1 Mar 2017
Use ismember
oneBlobOnly = ismember(L, i);
  2 Comments
May
May on 2 Mar 2017
Thanks Image Analyst,I tried it but the result is not change. Please kindly help me , where I made wrong. Thank you so much again.
load Y;
CC = bwconncomp(Y, 26); % Y is the 3D array
L = labelmatrix(CC);
oneBlobOnly = ismember(L,2);
map = hsv(90);
XR = oneBlobOnly; %%If I show "Y", it can show.
Ds = smooth3(XR);
hiso = patch(isosurface(Ds,5),'FaceColor','blue','EdgeColor','none');
hcap = patch(isocaps(XR,5),'FaceColor','interp','EdgeColor','none');
colormap(map)
daspect(gca,[1,1,.4])
lightangle(305,30);
fig = gcf;
fig.Renderer = 'zbuffer';
lighting phong
isonormals(Ds,hiso)
hcap.AmbientStrength = .6;
hiso.SpecularColorReflectance = 0;
hiso.SpecularExponent = 50;
ax = gca;
ax.View = [215,30];
ax.Box = 'On';
axis tight
title('One Blob');

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!