// Extract and Combine all b0s collected
print("Extracting b0\"s...")
cmds = []
b0s_bbr = []
for b0 in b0s:
print(b0)
b0_bbr = "{}/{}_b0.nii.gz".format(namer_dir, str(b0))
cmds.append("fslroi {} {} {} 1".format(dwi_file, b0_bbr, str(b0), " 1"))
b0s_bbr.append(b0_bbr)
for cmd in cmds:
os.system(cmd)
// Get mean b0
mean_b0 = mean_img(b0s_bbr)
nib.save(mean_b0, B0)
// Get mean b0 brain mask
After Change
dwi_data = dwi_img.get_data()
for b0 in b0s:
print(b0)
b0_vols.append(dwi_data[:, :, :, b0])
// Save mean B0
mean_B0_img = mean_img([nib.Nifti1Image(B0, affine=dwi_img.affine) for B0 in b0_vols])