forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels3d.py
44 lines (33 loc) · 984 Bytes
/
labels3d.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Labels 3D
=========
View 3D labels.
.. tags:: visualization-nD
"""
import numpy as np
from scipy import ndimage as ndi
from skimage import data, filters, morphology
import napari
cells3d = data.cells3d()
viewer = napari.view_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)
if __name__ == '__main__':
napari.run()