Connectivity in binary 3D matrix
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Region and Image Properties finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!