当前位置:网站首页>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
边栏推荐
- Web侧防御指南
- Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
- VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
- 建立自己的网站(22)
- The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
- Ransack组合条件搜索实现
- PIP audit: a powerful security vulnerability scanning tool
- [QT] QT multithreading development - four methods to realize multithreading design
- Record the functions of sharing web pages on wechat, QQ and Weibo
- New feature of go1.18: introduce new netip Network Library
猜你喜欢
Five message formats of OSPF
[shutter] shutter application theme (themedata | dynamic modification theme)
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
Lightgbm principle and its application in astronomical data
20220702-程序员如何构建知识体系?
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
#include errors detected. Please update your includePath.
[shutter] shutter custom fonts (download TTF fonts | pubspec.yaml configure font resources | synchronize resources | globally apply fonts | locally apply fonts)
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Official announcement! The golden decade of new programmers and developers was officially released
随机推荐
《Just because》阅读感受
[shutter] shutter resource file use (import resource pictures | use image resources)
Market Research - current situation and future development trend of carob chocolate market
phpcms实现订单直接支付宝支付功能
UE4 UI自适应屏幕
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
App page sharing password rails implementation
Market Research - current situation and future development trend of herringbone gear Market
PHP wechat red packet grabbing algorithm
ArrayList分析2 :Itr、ListIterator以及SubList中的坑
ServiceMesh主要解决的三大痛点
A specially designed loss is used to deal with data sets with unbalanced categories
建立自己的网站(22)
服务可见可观测性
[QT] QT multithreading development - reentrancy and thread safety
Pointer - function pointer
U++ 原始内存 学习笔记
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
It's not easy to say I love you | use the minimum web API to upload files (swagger support) # yyds dry inventory #
Pointer array parameter passing, pointer parameter passing