-
Hi to everyone, I'm trying to save my predictions as .nii.gz of data type uint8. I'm using: but even if I put output_dtype=np.uint8 my predictions are still saved as np.float32. As a double check, I try to do the opposite and see if I load an image using I've also tried writing torch.uint8, and "uint8". But it is not working. Thanks in advance for the answer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
What version of MONAI are you using? Please run import torch
import numpy as np
import nibabel as nib
from monai.utils import ImageMetaKey
from monai.data import MetaTensor
from monai.transforms import SaveImage
m=MetaTensor(torch.zeros(16,16,dtype=torch.uint8))
m.meta[ImageMetaKey.FILENAME_OR_OBJ]="test"
s=SaveImage(output_dtype=np.uint8, output_dir="/tmp", output_ext=".nii.gz", output_postfix="", separate_folder=False, resample=False)
s(m)
d=nib.load("/tmp/test.nii.gz")
print(d.dataobj.dtype) # prints uint8 The nifti file here appears to be saving uint8 data correctly, the transform isn't dictionary based like yours but it should be equivalent code. |
Beta Was this translation helpful? Give feedback.
What version of MONAI are you using? Please run
monai.config.print_config()
to print out the config information. I'm using the current dev version of MONAI which is based off 1.1 and am getting these results:The nifti file he…