现象描述
itk::ERROR: NiftiImageIO(000001CB27E1CD80): Unknown component type: 0
寻找原因
实验
由于代码中有一句是:
skull_striper_array = np.where(pred_label_array - skull_mask_array == 1, 1, 0)
因此逐个查看数据类型,发现
pred_label_array.dtype
> dtype('uint8')
skull_mask_array.dtype
> dtype('uint8')
skull_striper_array.dtype
> dtype('int64')
因此考虑是由于在numpy中引入了常量,导致数据类型发生变化。
skull_mask_path = "./skull_striper_mask.nii.gz"
skull_mask_image = sitk.ReadImage(skull_mask_path)
print(skull_mask_image.GetPixelIDTypeAsString())
> 64-bit signed integer
查看linux下图像的数据类型,确实是int64,转为int32之后,itk-snap就可以打开处理后的图像了。
考虑不同环境下numpy对常量默认的数据类型
test =np.array([1])
test.dtype
> dtype('int64')
test =np.array([1])
test.dtype
> dtype('int32')
在numpy文档-Data types中,有以下描述:
NumPy提供numpy.iinfo和numpy.finfo来确认Numpy中整数和浮点数的最值。
np.iinfo(int) # Bounds of the default integer on this system.
iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64)
np.iinfo(np.int32) # Bounds of a 32-bit integer
iinfo(min=-2147483648, max=2147483647, dtype=int32)
np.iinfo(np.int64) # Bounds of a 64-bit integer
iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64)
因此在自己的机器上进行测试:


skull_striper_array = np.where(pred_label_array - skull_mask_array == 1, 1, 0)
StackOverflow上也有个类似的问题阐述,详见Specifying default dtype for np.array(1.)
在上面阐述了现象:
itk::ERROR: NiftiImageIO(000001CB27E1CD80): Unknown component type: 0
因此考虑是否ITK-Snap不支持int64位的图像。暂时没有找到有效的相关内容。
TBD