当前位置:网站首页>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
边栏推荐
- The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
- LightGBM原理及天文数据中的应用
- Infrastructure is code: a change is coming
- Market Research - current situation and future development trend of marine clutch Market
- Official announcement! The golden decade of new programmers and developers was officially released
- APP页面分享口令Rails实现
- Try to get property'num for PHP database data reading_ rows' of non-object?
- Market Research - current market situation and future development trend of marine wet exhaust hose
- Attack and defense world PWN question: Echo
- [sword finger offer] 56 - I. the number of numbers in the array
猜你喜欢
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
From personal heroes to versatile developers, the era of programmer 3.0 is coming
C语言,实现三子棋小游戏
[shutter] shutter application theme (themedata | dynamic modification theme)
Landingsite eband B1 smoke test case
Reading experience of just because
Promise optimized callback hell
How do I access the kubernetes API?
TinyMCE visual editor adds Baidu map plug-in
Daily book CSO advanced road first exposed
随机推荐
服务可见可观测性
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
Phpcms realizes the direct Alipay payment function of orders
TinyMCE visual editor adds Baidu map plug-in
图像基础概念与YUV/RGB深入理解
Pointer array parameter passing, pointer parameter passing
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
加了定位的文字如何水平垂直居中
[shutter] shutter gesture interaction (small ball following the movement of fingers)
PHP wechat red packet grabbing algorithm
How to center the positioned text horizontally and vertically
Learn computer knowledge from scratch
VIM command-t plugin error: unable to load the C extension - VIM command-t plugin error: could not load the C extension
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
情感计算与理解研究发展概述
Riding the wind of "cloud native" and stepping on the wave of "digitalization", new programmer 003 starts pre-sale
Daily book -- analyze the pain points of software automation from simple to deep
Servicemesh mainly solves three pain points
【leetcode】1380. Lucky number in matrix
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens