seung-lab / connected-components-3d

Connected components on discrete and continuous multilabel 3D & 2D images. Handles 26, 18, and 6 connected variants; periodic boundaries (4, 8, & 6)
GNU Lesser General Public License v3.0
356 stars 42 forks source link

Applying dust to labels does not do anything #124

Closed Mohinta2892 closed 1 month ago

Mohinta2892 commented 3 months ago

Hello William,

I am trying to remove small objects via dust from a labelled ndarray (512^3) containing neuron segmentation instances. I have played around with the hyper-parameters of dust (threshold 100-1024, my objects are between 100 to 256); connectivity 6,18,26), however, none seems to be effective in removing small objects.

Have you seen anything like this happen before? Any suggestions will be really appreciated.

Best, Samia

william-silversmith commented 3 months ago

Hi! Would it be possible to get a sample to experiment with? If you can share the line where you are calling the function that would help as well.

Thanks!

Mohinta2892 commented 3 months ago

Sure, data is here.

I am running it as such:

n [1]: import cc3d
   ...: import numpy as np

In [2]: import zarr

In [3]: f = zarr.open("/media/samia/DATA/ark/connexion/data/MITO-HEMI/data_3d/merged/hemi_x11051_y20992_z21948_merged_ids_clahed.zarr")

In [4]: labels_in = f["volumes/labels/neuron_ids"][...]

In [5]: 

In [5]: labels_out = cc3d.dust(
   ...:   labels_in, threshold=100,
   ...:   connectivity=26, in_place=False
   ...: )
william-silversmith commented 3 months ago

Hi Samia,

Can you run the following code and let me know the result? I seem to be unable to reproduce your problem. There were issues with the dust function in the past, are you using the latest version of cc3d (currently version 3.16.0)?

import zarr
import cc3d
import numpy as np

zarray = zarr.open("hemi_x11051_y20992_z21948_merged_ids_clahed.zarr")
labels_in = zarray["volumes/labels/neuron_ids"][:]

labels_out = cc3d.dust(
 labels_in, threshold=100,
 connectivity=26, in_place=False
)

uniq, cts = np.unique(labels_out, return_counts=True)
cts = np.array([ x for x in cts if x > 0 ])
print(np.any(cts < 100))

Output:

False

Here's a photo of a 2d slice of removed segments:

image
import microviewer
microviewer.view(labels_out != labels_in)
Mohinta2892 commented 1 month ago

Hi William,

Many thanks! You were right about the version, I had to upgrade to the latest version (3.17) and then it seems to be working.

Closing the issue now.

Best, Samia