当前位置:网站首页>SimpleITK使用——4. 奇怪的問題
SimpleITK使用——4. 奇怪的問題
2022-07-02 22:32: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
边栏推荐
- 《乔布斯传》英文原著重点词汇笔记(九)【 chapter seven】
- 《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
- Socket套接字C/S端流程
- 记录一下微信、QQ、微博分享web网页功能
- 【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
- SQL必需掌握的100个重要知识点:使用游标
- Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
- [001] [arm-cortex-m3/4] internal register
- Pointer array parameter passing, pointer parameter passing
- U++ 学习笔记 堆
猜你喜欢

Perceptron model and Application

Socket套接字C/S端流程

Sql service intercepts string

The failure rate is as high as 80%. What should we do about digital transformation?

UE4 游戏架构 学习笔记

C语言,实现三子棋小游戏

《Just because》阅读感受

Kubernetes resource object introduction and common commands (4)

Reading experience of just because

20220702-程序员如何构建知识体系?
随机推荐
Try to get property'num for PHP database data reading_ rows' of non-object?
540. Single element in ordered array
Phpcms realizes the direct Alipay payment function of orders
VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
C语言,实现三子棋小游戏
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
U++ 学习笔记 ----松弛
U++ 原始内存 学习笔记
U++ 学习笔记 堆
Technological Entrepreneurship: failure is not success, but reflection is
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
kubernetes资源对象介绍及常用命令(四)
UE4 游戏架构 学习笔记
Market Research - current situation and future development trend of sickle cell therapy Market
《乔布斯传》英文原著重点词汇笔记(十)【 chapter eight】
Market Research - current situation and future development trend of marine clutch Market
An overview of the development of affective computing and understanding research
: last child does not take effect
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
ArrayList分析2 :Itr、ListIterator以及SubList中的坑