4
4
import itkwasm
5
5
import numpy as np
6
6
import zarr
7
- from multiscale_spatial_image import MultiscaleSpatialImage , to_multiscale , itk_image_to_multiscale
7
+ from multiscale_spatial_image import MultiscaleSpatialImage , to_multiscale , itk_image_to_multiscale , Methods
8
8
from spatial_image import to_spatial_image , is_spatial_image
9
9
10
10
import dask
@@ -42,8 +42,12 @@ def _make_multiscale_store(multiscale):
42
42
multiscale .to_zarr (store , compute = True )
43
43
return store
44
44
45
- def _get_viewer_image (image ):
45
+ def _get_viewer_image (image , label = False ):
46
46
min_length = 64
47
+ if label :
48
+ method = Methods .DASK_IMAGE_NEAREST
49
+ else :
50
+ method = Methods .DASK_IMAGE_GAUSSIAN
47
51
if isinstance (image , MultiscaleSpatialImage ):
48
52
return _make_multiscale_store (image )
49
53
@@ -68,27 +72,27 @@ def _get_viewer_image(image):
68
72
previous = scale_factor
69
73
scale_factors .append (scale_factor )
70
74
71
- multiscale = itk_image_to_multiscale (image , scale_factors = scale_factors )
75
+ multiscale = itk_image_to_multiscale (image , scale_factors = scale_factors , method = method )
72
76
return _make_multiscale_store (multiscale )
73
77
74
78
if HAVE_VTK :
75
79
import vtk
76
80
if isinstance (image , vtk .vtkImageData ):
77
81
spatial_image = vtk_image_to_spatial_image (image )
78
82
scale_factors = _spatial_image_scale_factors (spatial_image , min_length )
79
- multiscale = to_multiscale (spatial_image , scale_factors )
83
+ multiscale = to_multiscale (spatial_image , scale_factors , method = method )
80
84
return _make_multiscale_store (multiscale )
81
85
82
86
if isinstance (image , dask .array .core .Array ):
83
87
spatial_image = to_spatial_image (image )
84
88
scale_factors = _spatial_image_scale_factors (spatial_image , min_length )
85
- multiscale = to_multiscale (spatial_image , scale_factors )
89
+ multiscale = to_multiscale (spatial_image , scale_factors , method = method )
86
90
return _make_multiscale_store (multiscale )
87
91
88
92
if isinstance (image , zarr .Array ):
89
93
spatial_image = to_spatial_image (image )
90
94
scale_factors = _spatial_image_scale_factors (spatial_image , min_length )
91
- multiscale = to_multiscale (spatial_image , scale_factors )
95
+ multiscale = to_multiscale (spatial_image , scale_factors , method = method )
92
96
return _make_multiscale_store (multiscale )
93
97
94
98
# NGFF Zarr
@@ -100,30 +104,30 @@ def _get_viewer_image(image):
100
104
if isinstance (image , torch .Tensor ):
101
105
spatial_image = to_spatial_image (image .numpy ())
102
106
scale_factors = _spatial_image_scale_factors (spatial_image , min_length )
103
- multiscale = to_multiscale (spatial_image , scale_factors )
107
+ multiscale = to_multiscale (spatial_image , scale_factors , method = method )
104
108
return _make_multiscale_store (multiscale )
105
109
106
110
# Todo: preserve dask Array, if present, check if dims are NGFF -> use dims, coords
107
111
# Check if coords are uniform, if not, resample
108
112
if isinstance (image , xr .DataArray ):
109
113
if is_spatial_image (image ):
110
114
scale_factors = _spatial_image_scale_factors (image , min_length )
111
- multiscale = to_multiscale (image , scale_factors )
115
+ multiscale = to_multiscale (image , scale_factors , method = method )
112
116
return _make_multiscale_store (multiscale )
113
117
114
118
return xarray_data_array_to_numpy (image )
115
119
if isinstance (image , xr .Dataset ):
116
120
da = image [next (iter (image .variables .keys ()))]
117
121
if is_spatial_image (da ):
118
122
scale_factors = _spatial_image_scale_factors (da , min_length )
119
- multiscale = to_multiscale (da , scale_factors )
123
+ multiscale = to_multiscale (da , scale_factors , method = method )
120
124
return _make_multiscale_store (multiscale )
121
125
return xarray_data_set_to_numpy (image )
122
126
123
127
if isinstance (image , np .ndarray ):
124
128
spatial_image = to_spatial_image (image )
125
129
scale_factors = _spatial_image_scale_factors (spatial_image , min_length )
126
- multiscale = to_multiscale (spatial_image , scale_factors )
130
+ multiscale = to_multiscale (spatial_image , scale_factors , method = method )
127
131
return _make_multiscale_store (multiscale )
128
132
raise RuntimeError ("Could not process the viewer image" )
129
133
0 commit comments