2017-08-09 154 views
2

我正在使用3D MR圖像數據。爲了計算直方圖,我將sitk.Image轉換爲3維的numpy arrray。雖然我能夠使用matplotlib顯示每個軸向切片,但numpy數組在所有三維中都是完全空的。 有人可以解釋發生了什麼事嗎?sitk.GetArrayFromImage返回空numpy數組?

import numpy as np 
import SimpleITK as sitk 
from myshow import myshow 

img = sitk.ReadImage("mri.hdr") 
nda = sitk.GetArrayFromImage(img) 
myshow(img) 
print nda 

輸出:

[[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]] 

[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]] 

[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]] 

..., 
[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]] 

[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]] 

[[ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    ..., 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.] 
    [ 0. 0. 0. ..., 0. 0. 0.]]] 

NOTES:

+0

您可以發表您的代碼樣本,以便我們可以按照您的邏輯 – DJK

+0

編輯!我相當新的編碼和計算器。如果我不清楚我的問題,請原諒。 – DottedGlass

回答

1

你很好。數據就在那裏,只是打印函數顯示數組從頭開始的數據(很大)。如果打印數據具有內容你會看到一個有效的值的特定像素:

print nda[200,56,87]

該指數被認爲是在有效範圍內。