3
3
from pathlib import Path
4
4
5
5
import brainglobe_space as bg
6
- import imio
7
6
import numpy as np
8
7
from bg_atlasapi import BrainGlobeAtlas
9
8
from brainglobe_utils .general .system import delete_directory_contents
10
9
from brainglobe_utils .image .scale import scale_and_convert_to_16_bits
10
+ from brainglobe_utils .image_io import load_any , to_tiff
11
11
12
12
from brainreg .core .backend .niftyreg .parameters import RegistrationParams
13
13
from brainreg .core .backend .niftyreg .paths import NiftyRegPaths
@@ -72,7 +72,7 @@ def run_niftyreg(
72
72
save_nii (reference , atlas .resolution , niftyreg_paths .brain_filtered )
73
73
save_nii (target_brain , atlas .resolution , niftyreg_paths .downsampled_brain )
74
74
75
- imio . to_tiff (
75
+ to_tiff (
76
76
scale_and_convert_to_16_bits (target_brain ),
77
77
paths .downsampled_brain_path ,
78
78
)
@@ -125,32 +125,30 @@ def run_niftyreg(
125
125
brain_reg .generate_deformation_field (niftyreg_paths .deformation_field )
126
126
127
127
logging .info ("Exporting images as tiff" )
128
- imio . to_tiff (
129
- imio . load_any (niftyreg_paths .registered_atlas_path ).astype (
128
+ to_tiff (
129
+ load_any (niftyreg_paths .registered_atlas_path ).astype (
130
130
np .uint32 , copy = False
131
131
),
132
132
paths .registered_atlas ,
133
133
)
134
134
135
135
if save_original_orientation :
136
- registered_atlas = imio . load_any (
136
+ registered_atlas = load_any (
137
137
niftyreg_paths .registered_atlas_path
138
138
).astype (np .uint32 , copy = False )
139
139
atlas_remapped = bg .map_stack_to (
140
140
ATLAS_ORIENTATION , DATA_ORIENTATION , registered_atlas
141
141
).astype (np .uint32 , copy = False )
142
- imio .to_tiff (
143
- atlas_remapped , paths .registered_atlas_original_orientation
144
- )
142
+ to_tiff (atlas_remapped , paths .registered_atlas_original_orientation )
145
143
146
- imio . to_tiff (
147
- imio . load_any (niftyreg_paths .registered_hemispheres_img_path ).astype (
144
+ to_tiff (
145
+ load_any (niftyreg_paths .registered_hemispheres_img_path ).astype (
148
146
np .uint8 , copy = False
149
147
),
150
148
paths .registered_hemispheres ,
151
149
)
152
- imio . to_tiff (
153
- imio . load_any (niftyreg_paths .downsampled_brain_standard_space ).astype (
150
+ to_tiff (
151
+ load_any (niftyreg_paths .downsampled_brain_standard_space ).astype (
154
152
np .uint16 , copy = False
155
153
),
156
154
paths .downsampled_brain_standard_space ,
@@ -159,16 +157,16 @@ def run_niftyreg(
159
157
del reference
160
158
del target_brain
161
159
162
- deformation_image = imio . load_any (niftyreg_paths .deformation_field )
163
- imio . to_tiff (
160
+ deformation_image = load_any (niftyreg_paths .deformation_field )
161
+ to_tiff (
164
162
deformation_image [..., 0 , 0 ].astype (np .float32 , copy = False ),
165
163
paths .deformation_field_0 ,
166
164
)
167
- imio . to_tiff (
165
+ to_tiff (
168
166
deformation_image [..., 0 , 1 ].astype (np .float32 , copy = False ),
169
167
paths .deformation_field_1 ,
170
168
)
171
- imio . to_tiff (
169
+ to_tiff (
172
170
deformation_image [..., 0 , 2 ].astype (np .float32 , copy = False ),
173
171
paths .deformation_field_2 ,
174
172
)
@@ -201,7 +199,7 @@ def run_niftyreg(
201
199
)
202
200
203
201
# do the tiff part at the beginning
204
- downsampled_brain = imio . load_any (
202
+ downsampled_brain = load_any (
205
203
filename ,
206
204
scaling [1 ],
207
205
scaling [2 ],
@@ -219,16 +217,16 @@ def run_niftyreg(
219
217
downsampled_brain , atlas .resolution , tmp_downsampled_brain_path
220
218
)
221
219
222
- imio . to_tiff (downsampled_brain , downsampled_brain_path )
220
+ to_tiff (downsampled_brain , downsampled_brain_path )
223
221
224
222
logging .info ("Transforming to standard space" )
225
223
226
224
brain_reg .transform_to_standard_space (
227
225
tmp_downsampled_brain_path , tmp_downsampled_brain_standard_path
228
226
)
229
227
230
- imio . to_tiff (
231
- imio . load_any (tmp_downsampled_brain_standard_path ).astype (
228
+ to_tiff (
229
+ load_any (tmp_downsampled_brain_standard_path ).astype (
232
230
np .uint16 , copy = False
233
231
),
234
232
downsampled_brain_standard_path ,
0 commit comments