当前位置:网站首页>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
边栏推荐
- VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
- Attack and defense world PWN question: Echo
- Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
- Market Research - current market situation and future development trend of aircraft front wheel steering system
- [staff] Sibelius 7.5.1 score software installation (software download | software installation)
- U++ 学习笔记 堆
- Market Research - current market situation and future development trend of handheld wound imaging equipment
- From personal heroes to versatile developers, the era of programmer 3.0 is coming
- LightGBM原理及天文数据中的应用
- 建立自己的网站(22)
猜你喜欢
![[shutter] shutter resource file use (import resource pictures | use image resources)](/img/e9/94ae2e3ee315f490eb3cf14bcf2e49.jpg)
[shutter] shutter resource file use (import resource pictures | use image resources)
![[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)](/img/f7/cb41d159e5c5ef3f4f1b9468d52ccc.jpg)
[shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)

What is it that makes you tremble? Those without fans can learn

Introduction to the principle of geographical detector

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文

Gee: (II) resampling the image

Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file

Ransack combined condition search implementation

《Just because》阅读感受
随机推荐
Try to get property'num for PHP database data reading_ rows' of non-object?
Promise optimized callback hell
《Just because》阅读感受
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
Market Research - current situation and future development trend of preclinical medical device testing service market
Sql service intercepts string
PHP wechat red packet grabbing algorithm
Ransack组合条件搜索实现
About test cases
PIP audit: a powerful security vulnerability scanning tool
Lightgbm principle and its application in astronomical data
Unity3D学习笔记4——创建Mesh高级接口
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
关于PHP-数据库的 数据读取,Trying to get property 'num_rows' of non-object?
U++ 学习笔记 堆
Share how to make professional hand drawn electronic maps
phpcms实现订单直接支付宝支付功能
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
Image segmentation using pixellib
Market Research - current market situation and future development trend of night vision goggles for pilots