How do I find clusters in a 3D binary image?

I have a binary 3D image, meaning it only contains 0s and 1. Now I want to find all clusters from 1s (ie, voxel clusters containing only the value 1). Finally, for each cluster, I need to know the coordinates of the voxels that belong to that cluster.

How can I do that? Of course I can iterate over all the voxels, but the tricky part is finding the clusters and extracting all the voxels within the cluster.

I want to do this in Matlab.

+3


source to share


3 answers


Use regionprops

with attribute 'PixelIdxList'

. The default is 8-channel connected region. It also gets a linear index useful for computation.

Example:

A = false(4,4,3);
A(1,1,1) = true;
A(3,3,3) = true;
rp = regionprops(A,'PixelIdxList');

EDU>> A(rp(1).PixelIdxList)

ans =

     1

EDU>> A(rp(2).PixelIdxList)

ans =

     1

      



You can also use 'PixelList'

to get 3D coordinates:

EDU>> rp = regionprops(A,'PixelList');
EDU>> rp

rp = 

2x1 struct array with fields:
    PixelList

EDU>> rp(1)

ans = 

    PixelList: [1 1 1]

EDU>> rp(2)

ans = 

    PixelList: [3 3 3]

      

+3


source


This is called related component analysis.

A simple approach is to fill in the seeds: systematically scan the entire domain; when you meet "1", recursively visit all "1" neighbors and set them to "0" (so you don't visit them more times). The top-level visit lists all voxels in the cluster. Once the cluster has been cleared, continue looking for other "1" s.



Beware that this will be tricky for the stack, and it might be better to implement an explicit stack for this purpose.

0


source


It depends on the rules you want to use. And how your 3D is presented. It's a point cloud or 2D bitmap that uses colors to represent depth, or a 3D array, or whatever ...

You can try to combine them according to planes or small 3D clouds inside 3D space. If you first slice the 3D space in a plane and use the 2D clustering algorithm on them. You will then have clusters for each depth plane, if any. If second, change the 2D search clustering algorithm to use space cubes instead of plane squares as a frame. You can even use the 2D algorithm on the sliced ​​planes and then check the surrounding planes to see if the cluster goes further in 3D space. But that would be ineffective. I'm not a matlab expert, so I can't help you with the implementation, but maybe there is a toolbox to accomplish exactly what you want. And of course how you do it depends a lot onhow your image is represented in memory. You may need to change formats to retrieve clusters easily and efficiently. Let Google do something.

Edit: Just got an idea. Use the correct format and just sort the data. You should get a list of all contiguous points. Include coordinate information in the input. Sorting is often faster than joining.

0


source







All Articles