forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanisotropic_scale.py
More file actions
57 lines (43 loc) · 1.53 KB
/
Copy pathanisotropic_scale.py
File metadata and controls
57 lines (43 loc) · 1.53 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Anisotropic data with scale
============================
Display a 3D image with anisotropic voxel spacing using the ``scale``
parameter so that the volume appears with correct proportions.
Microscopy data is often anisotropic: the voxel spacing differs across
axes. Without ``scale``, napari treats every voxel as a unit cube and
the volume appears with incorrect proportions.
Setting ``scale`` to the real voxel dimensions corrects this.
Toggle the visibility of each layer to compare the difference.
.. tags:: visualization-nD, layers
"""
from skimage import data
import napari
# cells3d has voxel spacing approximately (0.29, 0.26, 0.26) in (z, y, x).
# We subsample z by 4 and x by 2 to simulate more strongly anisotropic data.
# After subsampling, the effective voxel spacing becomes (1.16, 0.26, 0.52).
# The ratio is approximately (4.5, 1, 2), which we pass to ``scale``.
cells = data.cells3d()
nuclei = cells[::4, 1, :, ::2]
scale = (4.5, 1, 2)
viewer = napari.Viewer(ndisplay=3)
viewer.add_image(
nuclei,
name='no scale',
blending='additive',
colormap='magenta',
)
viewer.add_image(
nuclei,
name='with scale',
blending='additive',
colormap='green',
scale=scale,
)
viewer.layers['no scale'].bounding_box.line_color = 'magenta'
viewer.layers['no scale'].bounding_box.visible = True
viewer.layers['with scale'].bounding_box.line_color = 'green'
viewer.layers['with scale'].bounding_box.visible = True
viewer.camera.angles = (-45, 0, -60)
viewer.fit_to_view()
if __name__ == '__main__':
napari.run()