Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
nifti file header and image
def array_to_nii(array_3d, scan, output_path):
Same affine and same header
convert mask only contains 0 and 1, so convert data type to uint8
:param array_3d:
:param scan:
:param output_path:
data_type = np.uint8
array_3d = array_3d.astype(data_type)
nii_img = nib.Nifti1Image(array_3d, affine=scan.affine, header=scan.header)
nii_img.set_data_dtype(dtype=data_type), output_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment