Connectivity in binary 3D matrix
이전 댓글 표시
I am using bwconncomp to find the largest connected component in a 3D binary matrix (volume). However, it doesn't work the way I want. Specifically, the code is
conncomp = bwconncomp(volume, 6);
% Identify the largest component using cellfun.
[~, maxcell] = max(cellfun(@numel, conncomp.PixelIdxList));
% Zero the image and assign to it the largest component.
volume = zeros(size(volume));
volume(conncomp.PixelIdxList{1, maxcell}) = 1;
Take a look at the figure below. Imagine that these are just profiles of the "slices" in the 3rd dimension. At the top is the original volume, at the center is what I get using this code, and at the bottom is what I want. bwconncomp skips a part of the large 3D object by cutting it in the slice where it is first split in two (slice 7 from left). I want to preserve that part because it is part of the object, as shown at the bottom. Changing connectivity doesn't help.
The person who solves this is my hero! Any suggestions? Many thanks.

Edit: it seems that when I try this on small 3x3x3 matrices it works fine, but not on my large images. So I also attached an example TIFF stack and the analysed one to see what I mean. For example, slices 10 and 12 in the analysed image should but do not include some connected areas.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Region and Image Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!