Note
Go to the end to download the full example as a Python script or as a Jupyter notebook..
Labels 3D#
View 3D labels.

/home/runner/work/docs/docs/napari/examples/labels3d.py:27: FutureWarning: Parameter `area_threshold` is deprecated since version 0.26.0 and will be removed in 2.0.0 (or later). To avoid this warning, please use the parameter `max_size` instead. For more details, see the documentation of `remove_small_holes`. Note that the new threshold removes objects smaller than **or equal to** its value, while the previous parameter only removed smaller ones.
morphology.remove_small_holes(thresholded, 20**3),
/home/runner/work/docs/docs/napari/examples/labels3d.py:26: FutureWarning: Parameter `min_size` is deprecated since version 0.26.0 and will be removed in 2.0.0 (or later). To avoid this warning, please use the parameter `max_size` instead. For more details, see the documentation of `remove_small_objects`. Note that the new threshold removes objects smaller than **or equal to** its value, while the previous parameter only removed smaller ones.
cleaned = morphology.remove_small_objects(
import numpy as np
from scipy import ndimage as ndi
from skimage import data, filters, morphology
import napari
cells3d = data.cells3d()
viewer = napari.Viewer()
membranes_layer, nuclei_layer = viewer.add_image(
cells3d, channel_axis=1, name=['membranes', 'nuclei']
)
membrane, nuclei = cells3d.transpose((1, 0, 2, 3)) / np.max(cells3d)
edges = filters.scharr(nuclei)
denoised = ndi.median_filter(nuclei, size=3)
thresholded = denoised > filters.threshold_li(denoised)
cleaned = morphology.remove_small_objects(
morphology.remove_small_holes(thresholded, 20**3),
20**3,
)
segmented = ndi.label(cleaned)[0]
# maxima = ndi.label(morphology.local_maxima(filters.gaussian(nuclei, sigma=10)))[0]
# markers_big = morphology.dilation(maxima, morphology.ball(5))
# segmented = segmentation.watershed(
# edges,
# markers_big,
# mask=cleaned,
# )
labels_layer = viewer.add_labels(segmented)
viewer.dims.ndisplay = 3
if __name__ == '__main__':
napari.run()