当前位置:网站首页>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
边栏推荐
- [shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
- Pointer array parameter passing, pointer parameter passing
- Five message formats of OSPF
- Bridge emqx cloud data to AWS IOT through the public network
- pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform
- Evolution of messaging and streaming systems under the native tide of open source cloud
- "New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
- It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
- Market Research - current situation and future development trend of cell-based seafood market
- Daily book -- analyze the pain points of software automation from simple to deep
猜你喜欢
Kubernetes resource object introduction and common commands (4)
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
Hanoi Tower problem
tinymce可视化编辑器增加百度地图插件
From "bronze" to "King", there are three secrets of enterprise digitalization
What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
kubernetes资源对象介绍及常用命令(四)
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
Gee: (II) resampling the image
随机推荐
: last child does not take effect
《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
Socket套接字C/S端流程
Unity3d learning notes 4 - create mesh advanced interface
How do I access the kubernetes API?
PIP audit: a powerful security vulnerability scanning tool
Pointer - function pointer
Servicemesh mainly solves three pain points
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
[QT] QT multithreading development - four methods to realize multithreading design
UE4 UI自适应屏幕
New feature of go1.18: introduce new netip Network Library
技术人创业:失败不是成功,但反思是
Sql service intercepts string
图像基础概念与YUV/RGB深入理解
Introduction to the principle of geographical detector
Les trois principaux points de douleur traités par servicemesh
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
【C 题集】of Ⅴ