def save_3D_nparray_nifti(np_matrix_3d, output_image, fname_atlas):
    # Save 3d numpy matrix to niftii image
    # np_matrix_3d is a 3D numpy ndarray
    # output_image is the name of the niftii image created, ex: '3D_matrix.nii.gz'
    img = nib.Nifti1Image(np_matrix_3d, np.eye(4))
    affine = img.get_affine()
    np_matrix_3d_nii = nib.Nifti1Image(np_matrix_3d,affine)
    nib.save(np_matrix_3d_nii, output_image)
    # copy geometric information
    sct.run('fslcpgeom '+fname_atlas+' '+output_image, verbose=0)
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/atlas/create_atlas/create_masks_csf_and_gm.py/save_3D_nparray_nifti/original