1010 _dim_scale_factors ,
1111 _get_block ,
1212 _spatial_dims ,
13+ _spatial_dims_last ,
1314)
1415
1516_image_dims : Tuple [str , str , str , str ] = ("x" , "y" , "z" , "t" )
@@ -89,13 +90,14 @@ def _downsample_itkwasm_bin_shrink(
8990 dim_factors = _dim_scale_factors (dims , scale_factor , previous_dim_factors )
9091 previous_dim_factors = dim_factors
9192 previous_image = _align_chunks (previous_image , default_chunks , dim_factors )
93+ previous_image = _spatial_dims_last (previous_image )
9294
9395 shrink_factors = [dim_factors [sd ] for sd in spatial_dims ]
9496
9597 block_0 = _get_block (previous_image , 0 )
9698
9799 # For consistency for now, do not utilize direction until there is standardized support for
98- # direction cosines / orientation in OME-NGFF
100+ # direction cosines / orientation in OME-NGFF (v0.6)
99101 # block_0.attrs.pop("direction", None)
100102 block_input = itkwasm .image_from_array (np .ones_like (block_0 ))
101103 spacing = [previous_image .scale [d ] for d in spatial_dims ]
@@ -166,6 +168,7 @@ def _downsample_itkwasm(
166168 dim_factors = _dim_scale_factors (dims , scale_factor , previous_dim_factors )
167169 previous_dim_factors = dim_factors
168170 previous_image = _align_chunks (previous_image , default_chunks , dim_factors )
171+ previous_image = _spatial_dims_last (previous_image )
169172
170173 shrink_factors = [dim_factors [sd ] for sd in spatial_dims ]
171174
@@ -177,7 +180,10 @@ def _downsample_itkwasm(
177180 block_neg1_input = _get_block (previous_image , - 1 )
178181
179182 # Compute overlap for Gaussian blurring for all blocks
180- block_0_image = itkwasm .image_from_array (np .ones_like (block_0_input ))
183+ is_vector = previous_image .dims [- 1 ] == "c"
184+ block_0_image = itkwasm .image_from_array (
185+ np .ones_like (block_0_input ), is_vector = is_vector
186+ )
181187 input_spacing = [previous_image .scale [d ] for d in spatial_dims ]
182188 block_0_image .spacing = input_spacing
183189 input_origin = [previous_image .translation [d ] for d in spatial_dims ]
@@ -208,17 +214,25 @@ def _downsample_itkwasm(
208214 block_output .size [dim ] == computed_size [dim ]
209215 for dim in range (block_output .data .ndim )
210216 )
217+ breakpoint ()
211218 output_chunks = list (previous_image .data .chunks )
212- if "t" in previous_image .dims :
213- dims = list (previous_image .dims )
214- t_index = dims .index ("t" )
215- output_chunks .pop (t_index )
219+ dims = list (previous_image .dims )
220+ output_chunks_start = 0
221+ while dims [output_chunks_start ] not in _spatial_dims :
222+ output_chunks_start += 1
223+ output_chunks = output_chunks [output_chunks_start :]
224+ # if "t" in previous_image.dims:
225+ # dims = list(previous_image.dims)
226+ # t_index = dims.index("t")
227+ # output_chunks.pop(t_index)
216228 for i , c in enumerate (output_chunks ):
217229 output_chunks [i ] = [
218230 block_output .data .shape [i ],
219231 ] * len (c )
220232 # Compute output size for block N-1
221- block_neg1_image = itkwasm .image_from_array (np .ones_like (block_neg1_input ))
233+ block_neg1_image = itkwasm .image_from_array (
234+ np .ones_like (block_neg1_input ), is_vector = is_vector
235+ )
222236 block_neg1_image .spacing = input_spacing
223237 block_neg1_image .origin = input_origin
224238 block_output = downsample_bin_shrink (
0 commit comments