sitk.GetArrayFromImage returns 空 numpy 数组?
sitk.GetArrayFromImage returns empty numpy array?
我正在处理 3D MR 图像数据。为了计算直方图,我从 sitk.Image 转换为 3 维的 numpy 数组。虽然我能够使用 matplotlib 显示每个轴向切片,但 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.]]]
备注:
myshow.py (https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/myshow.py)
myshow.py 使用matplotlib
可视化一片img
MR 图像数据采用 hdr/img(分析)格式。
你很好。数据就在那里,只是打印函数显示了数组开头的数据(它很大)。如果您打印具有内容的特定像素的数据,您将看到一个有效值:
print nda[200,56,87]
假定索引在有效范围内。
我正在处理 3D MR 图像数据。为了计算直方图,我从 sitk.Image 转换为 3 维的 numpy 数组。虽然我能够使用 matplotlib 显示每个轴向切片,但 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.]]]
备注:
myshow.py (https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/myshow.py)
myshow.py 使用matplotlib
可视化一片img
MR 图像数据采用 hdr/img(分析)格式。
你很好。数据就在那里,只是打印函数显示了数组开头的数据(它很大)。如果您打印具有内容的特定像素的数据,您将看到一个有效值:
print nda[200,56,87]
假定索引在有效范围内。