-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebias.py
28 lines (19 loc) · 927 Bytes
/
debias.py
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
import numpy as np
import nibabel as nib
def main(fdata, fNs, fsigmas, fcorr_data, fnan_map, fnan_mean):
data_img = nib.load(fdata)
data = data_img.get_data()
Ns = nib.load(fNs).get_data()
sigmas = nib.load(fsigmas).get_data()
corr_data = np.sqrt(data**2 - 2*Ns[...,None]*(sigmas[...,None]**2))
nan_map = np.zeros_like(corr_data, dtype=np.bool)
nan_idx = np.where(np.isnan(corr_data))
nan_map[nan_idx] = True
corr_data[nan_idx] = 0
nib.Nifti1Image(corr_data, data_img.affine, data_img.header).to_filename(fcorr_data)
nib.Nifti1Image(nan_map, data_img.affine, data_img.header).to_filename(fnan_map)
nib.Nifti1Image(nan_map.mean(3), data_img.affine, data_img.header).to_filename(fnan_mean)
if __name__ == "__main__":
import sys
print('usage: python debias.py input_data input_Ns input_sigmas output_corr_data output_nan_map nana_mean_map')
main(*sys.argv[1:])