我为我的夏季项目下载了BraTS数据集。
数据集由nii.gz文件组成,我可以使用Python中的nibabel库打开这些文件。 我使用了以下代码:
import os
import numpy as np
import nibabel as nib
import matplotlib.pyplot as plat
examplefile=os.path.join("mydatapath","BraTS19_2013_5_1_flair.nii.gz")
img=nib.load(examplefile)
print(img)
这给了我以下输出:
<class 'nibabel.nifti1.Nifti1Image'>
data shape (240, 240, 155)
affine:
[[ -1. 0. 0. -0.]
[ 0. -1. 0. 239.]
[ 0. 0. 1. 0.]
[ 0. 0. 0. 1.]]
metadata:
<class 'nibabel.nifti1.Nifti1Header'> object, endian='<'
sizeof_hdr : 348
data_type : b''
db_name : b''
extents : 0
session_error : 0
regular : b'r'
dim_info : 0
dim : [ 3 240 240 155 1 1 1 1]
intent_p1 : 0.0
intent_p2 : 0.0
intent_p3 : 0.0
intent_code : none
datatype : int16
bitpix : 16
slice_start : 0
pixdim : [1. 1. 1. 1. 0. 0. 0. 0.]
vox_offset : 0.0
scl_slope : nan
scl_inter : nan
slice_end : 0
slice_code : unknown
xyzt_units : 2
cal_max : 0.0
cal_min : 0.0
slice_duration : 0.0
toffset : 0.0
glmax : 0
glmin : 0
descrip : b''
aux_file : b''
qform_code : aligned
sform_code : scanner
quatern_b : 0.0
quatern_c : 0.0
quatern_d : 1.0
qoffset_x : -0.0
qoffset_y : 239.0
qoffset_z : 0.0
srow_x : [-1. 0. 0. -0.]
srow_y : [ 0. -1. 0. 239.]
srow_z : [0. 0. 1. 0.]
intent_name : b''
magic : b'n+1'
有人可以引导我完成这个过程吗? 我知道,如果有人能告诉我如何从这些数据中获取图像,这将是很多数据。
谢谢。
答案 0 :(得分:1)
您是否看过nibabel的文档?非常好,可以回答您的问题。 https://nipy.org/nibabel/gettingstarted.html
在您的问题中,您正在查看Nifti文件的标题。使用以下命令以numpy数组的形式获取图像数据。
import nibabel as nib
img = nib.load("image.nii.gz")
data = img.get_fdata()