当前位置:网站首页>SimpleITK使用——4. 奇怪的问题
SimpleITK使用——4. 奇怪的问题
2022-07-02 22:01:00 【吨吨不打野】
1. 数据dtype类型问题
1.1 确定原因
现象描述
- windows下使用numpy处理Nifti图像并保存,
- 得到的图像是49KB
- ITK-Snap可以打开
- linux下使用相同代码用numpy处理Nifti图像并保存
- 得到图像时85KB
- ITK-Snap打开报错:
itk::ERROR: NiftiImageIO(000001CB27E1CD80): Unknown component type: 0
- 但是3D Slicer可以打开
寻找原因
- 由于代码相同,测试过保存的numpy数据也相同,但是最终文件大小不同。
- 因此考虑数据类型,dtype的问题
实验
由于代码中有一句是:
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对常量默认的数据类型
- linux环境下:numpy-1.19.2、simpleitk-2.1.1.2
test =np.array([1]) test.dtype > dtype('int64') - windows环境:numpy-1.19.2、simpleitk-2.1.1.2
test =np.array([1]) test.dtype > dtype('int32')
1.2 numpy中默认dtype类型
在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)
因此在自己的机器上进行测试:
- windows上:

- linux上:

- 因此可以知道,当我使用下面的代码,引入整数后
skull_striper_array = np.where(pred_label_array - skull_mask_array == 1, 1, 0) - windows默认这个整数(int)是int32位,而linux默认这个整数(int)是int64位
StackOverflow上也有个类似的问题阐述,详见Specifying default dtype for np.array(1.)
1.3 itk-snap打开int64格式的问题
在上面阐述了现象:
- 64位的图像使用ITK-Snap打开报错:
itk::ERROR: NiftiImageIO(000001CB27E1CD80): Unknown component type: 0
- 但是3D Slicer可以打开
因此考虑是否ITK-Snap不支持int64位的图像。暂时没有找到有效的相关内容。
TBD
边栏推荐
- [Jianzhi offer] 56 - ii Number of occurrences of numbers in the array II
- The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
- UE4 游戏架构 学习笔记
- 20220702 how do programmers build knowledge systems?
- 在beforeDestroy中销毁localStorage中的值无效
- Market Research - current market situation and future development trend of genome editing mutation detection kit
- [leetcode] sword finger offer 11 Rotate the minimum number of the array
- [C question set] of V
- 情感计算与理解研究发展概述
- LxC terminal login method
猜你喜欢

A specially designed loss is used to deal with data sets with unbalanced categories

From personal heroes to versatile developers, the era of programmer 3.0 is coming

540. Single element in ordered array

Daily book -- analyze the pain points of software automation from simple to deep

20220702 how do programmers build knowledge systems?

pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform

Five message formats of OSPF

Landingsite eband B1 smoke test case

Pointer and string

《Just because》阅读感受
随机推荐
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
An overview of the development of affective computing and understanding research
Using emqx cloud to realize one machine one secret verification of IOT devices
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
Unity发布WebGL播放声音的一种方法
Introduction to victoriametrics
GEE:(二)对影像进行重采样
Service visibility and observability
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
Pointer - function pointer
情感计算与理解研究发展概述
Etcd raft protocol
Market Research - current market situation and future development trend of total nutrition products
[leetcode] sword finger offer 04 Search in two-dimensional array
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
SQL必需掌握的100个重要知识点:使用游标
Learn computer knowledge from scratch
LxC terminal login method
2019 Nanchang (relive the classic)
U++ 学习笔记 堆