我正在使用nibabel
库从nii文件加载数据。我在http://nipy.org/nibabel/gettingstarted.html阅读了lib的文档,发现
This information is available without the need to load anything of the main image data into the memory. Of course there is also access to the image data as a NumPy array
这是我的代码来加载数据
import nibabel as nib
img = nib.load('example.nii')
data = img.get_data()
data = np.squeeze(data)
data = np.copy(data, order="C")
print data.shape
我得到了结果
128, 128, 64
数据形状的顺序是什么?是不是WidthxHeightxDepth
?我的输入必须按depth, height, width
排列。所以我会用input=data.transpose(2,0,1)
。对吗?谢谢大家
更新:我发现Numpy将按顺序读取图像Height x Width x Depth
作为引用http://www.python-course.eu/images/axis.jpeg
好吧,这是我的看法:
使用
scipy.ndimage.imread('img.jpg', mode='RGB')
,结果数组将始终具有以下顺序:(H, W, D)
,即(高度、宽度、深度),因为numpy使用ndarrays的术语(axis=0, axis=1, axis=2)
,或者类似的(Y, X, Z)
,如果您想在三维中可视化的话。如果你把img_形状看作一个元组
选择哪一个对你来说是一种方便的记忆方式。
PS:还应该注意,像tensorflow这样的库也(几乎)遵循与numpy相同的约定。
tf.image_decode_jpeg()返回:
相关问题 更多 >
编程相关推荐