当前位置:网站首页>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
边栏推荐
- Market Research - current market situation and future development trend of third-party data platform
- Socket套接字C/S端流程
- [sword finger offer] 56 - I. the number of numbers in the array
- Pointer and string
- [shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
- [leetcode] sword finger offer 11 Rotate the minimum number of the array
- LightGBM原理及天文数据中的应用
- U++ 学习笔记 ----松弛
- APP页面分享口令Rails实现
- Kubernetes resource object introduction and common commands (4)
猜你喜欢

"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba

The difference between include < > and include ""

C language, to achieve three chess games

What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

Share how to make professional hand drawn electronic maps

PIP audit: a powerful security vulnerability scanning tool

Landingsite eband B1 smoke test case

如何访问kubernetes API?

About test cases
随机推荐
Une semaine de vie
Unity3D学习笔记4——创建Mesh高级接口
pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
Sql service intercepts string
A specially designed loss is used to deal with data sets with unbalanced categories
The failure rate is as high as 80%. What should we do about digital transformation?
100 important knowledge points that SQL must master: management transaction processing
Share how to make professional hand drawn electronic maps
U++ 学习笔记 堆
LandingSite eBand B1冒烟测试用例
加了定位的文字如何水平垂直居中
一周生活
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Evolution of messaging and streaming systems under the native tide of open source cloud
Leetcode theme [array] -169- most elements
Micro service gateway selection, please accept my knees!
[QT] QT multithreading development - four methods to realize multithreading design
Introduction to the principle of geographical detector