NIfTI writer does not store cal_min and cal_max
See original GitHub issueDescribe the bug
I’m storing NIfTI images with SaveImaged
but when viewed in MRIcroGL I’m seeing this:
This is due to wrong intensity values:
These are read from the NIfTI attributes cal_min
and cal_max
.
I did add a transform to make sure these are set:
class FixMinMax(MapTransform):
def __init__(
self,
keys: KeysCollection,
allow_missing_keys: bool = False,
) -> None:
super().__init__(keys, allow_missing_keys)
def __call__(self, data: Mapping[Hashable, NdarrayTensor]) -> Dict[Hashable, NdarrayTensor]:
d = dict(data)
for key in self.key_iterator(d):
img: torch.Tensor
img, *_ = convert_data_type(d[key], torch.Tensor) # type: ignore
meta_key = f"{key}_meta_dict"
print(d[meta_key])
d[meta_key]['cal_min'] = torch.min(img).item()
d[meta_key]['cal_max'] = torch.max(img).item()
print(d[meta_key])
return d
Nonetheless, it still does not work.
I did output the NIfTI header:
nifti = nib.load(path / 'hippo.nii.gz')
header = {a: nifti.header[a] for a in nifti.header}
And it contains:
'cal_max': array(0., dtype=float32),
'cal_min': array(0., dtype=float32)
In fact, the monai.data.nifti_writer.write_nifti
function does not expect nor set these two attributes.
Environment
Click to view the environment
Printing MONAI config…
MONAI version: 0.7.0 Numpy version: 1.19.2 Pytorch version: 1.8.1+cu111 MONAI flags: HAS_EXT = False, USE_COMPILED = False MONAI rev id: bfa054b9c3064628a21f4c35bbe3132964e91f43
Optional dependencies: Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION. Nibabel version: 3.1.1 scikit-image version: 0.18.0 Pillow version: 8.3.2 Tensorboard version: 2.7.0 gdown version: NOT INSTALLED or UNKNOWN VERSION. TorchVision version: NOT INSTALLED or UNKNOWN VERSION. tqdm version: 4.62.3 lmdb version: NOT INSTALLED or UNKNOWN VERSION. psutil version: NOT INSTALLED or UNKNOWN VERSION. pandas version: 1.2.4 einops version: NOT INSTALLED or UNKNOWN VERSION. transformers version: NOT INSTALLED or UNKNOWN VERSION.
For details about installing the optional dependencies, please visit: https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
Printing system config…
System: Windows Win32 version: (‘10’, ‘10.0.19041’, ‘SP0’, ‘’) Platform: Windows-10-10.0.19041-SP0 Processor: Intel64 Family 6 Model 63 Stepping 2, GenuineIntel Machine: AMD64 Python version: 3.7.7 Process name: python.exe Command: [‘C:\Users\SebastianPenhouet\AppData\Local\Programs\Python\Python37\python.exe’, ‘-c’, ‘import monai; monai.config.print_debug_info()’] Open files: [popenfile(path=‘C:\Windows\System32\de-DE\KernelBase.dll.mui’, fd=-1), popenfile(path=‘C:\Windows\System32\de-DE\kernel32.dll.mui’, fd=-1)] Num physical CPUs: 6 Num logical CPUs: 12 Num usable CPUs: 12 CPU usage (%): [16.3, 11.8, 26.1, 20.3, 12.4, 7.2, 17.6, 16.3, 15.0, 9.2, 12.4, 58.2] CPU freq. (MHz): 3501 Load avg. in last 1, 5, 15 mins (%): [0.0, 0.0, 0.0] Disk usage (%): 97.8 Avg. sensor temp. (Celsius): UNKNOWN for given OS Total physical memory (GB): 31.9 Available memory (GB): 18.6 Used memory (GB): 13.3
Printing GPU config…
Num GPUs: 1 Has CUDA: True CUDA version: 11.1 cuDNN enabled: True cuDNN version: 8005 Current device: 0 Library compiled for CUDA architectures: [‘sm_37’, ‘sm_50’, ‘sm_60’, ‘sm_61’, ‘sm_70’, ‘sm_75’, ‘sm_80’, ‘sm_86’, ‘compute_37’] GPU 0 Name: Quadro K2200 GPU 0 Is integrated: False GPU 0 Is multi GPU board: False GPU 0 Multi processor count: 5 GPU 0 Total memory (GB): 4.0 GPU 0 CUDA capability (maj.min): 5.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)
Top GitHub Comments
I opened an issue on MRIcroGL: https://www.nitrc.org/tracker/index.php?func=detail&aid=9982&group_id=889&atid=3371
Or perhaps you’re saying that in the general case,
cal_min
andcal_max
might not be zero, in which case we need to take it into account?