@@ -17,8 +17,7 @@ def extract_b0(in_file, b0_ixs, out_path=None):
17
17
hdr = img .header .copy ()
18
18
hdr .set_data_shape (b0 .shape )
19
19
hdr .set_xyzt_units ('mm' )
20
- hdr .set_data_dtype (np .float32 )
21
- nb .Nifti1Image (b0 , img .affine , hdr ).to_filename (out_path )
20
+ nb .Nifti1Image (b0 .astype (hdr .get_data_dtype ()), img .affine , hdr ).to_filename (out_path )
22
21
return out_path
23
22
24
23
@@ -32,14 +31,14 @@ def rescale_b0(in_file, mask_file, out_path=None):
32
31
if img .dataobj .ndim == 3 :
33
32
return in_file
34
33
35
- data = img .get_fdata (dtype = 'float32' )
34
+ data = img .get_fdata ()
36
35
mask_img = nb .load (mask_file )
37
- mask_data = mask_img .get_fdata (dtype = 'float32' )
36
+ mask_data = mask_img .get_fdata ()
38
37
39
38
median_signal = np .median (data [mask_data > 0 , ...], axis = 0 )
40
39
rescaled_data = 1000 * data / median_signal
41
40
hdr = img .header .copy ()
42
- nb .Nifti1Image (rescaled_data , img .affine , hdr ).to_filename (out_path )
41
+ nb .Nifti1Image (rescaled_data . astype ( hdr . get_data_dtype ()) , img .affine , hdr ).to_filename (out_path )
43
42
return out_path
44
43
45
44
@@ -63,5 +62,7 @@ def median(in_file, dtype=None, out_path=None):
63
62
hdr .set_xyzt_units ('mm' )
64
63
if dtype is not None :
65
64
hdr .set_data_dtype (dtype )
66
- nb .Nifti1Image (median_data , img .affine , hdr ).to_filename (out_path )
65
+ else :
66
+ dtype = hdr .get_data_dtype ()
67
+ nb .Nifti1Image (median_data .astype (dtype ), img .affine , hdr ).to_filename (out_path )
67
68
return out_path
0 commit comments