Created
October 23, 2018 13:07
-
-
Save mingrui/550a7657444e39ffd408ec8b5935c753 to your computer and use it in GitHub Desktop.
nifti file header and image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://bic-berkeley.github.io/psych-214-fall-2016/saving_images.html | |
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: | |
:return: | |
''' | |
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) | |
nib.save(nii_img, output_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment