0

I downloaded the BraTS dataset for my summer project.

The dataset consisted of nii.gz files which I was able to open using nibabel library in Python. I used the following code:

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)

this gave me the following output:

<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'

Can someone please walk me through this. I know it's a lot of data if someone could just tell me how to get the image from this data it would be wonderful.

Thank You.

Naman Bansal
  • 191
  • 2
  • 13

1 Answers1

2

Have you looked at nibabel's documentation? It's excellent and has the answer to your question. https://nipy.org/nibabel/gettingstarted.html

In your question, you are looking at the header of the Nifti file. Use the following to get the image data as a numpy array.

import nibabel as nib
img = nib.load("image.nii.gz")
data = img.get_fdata()
jkr
  • 17,119
  • 2
  • 42
  • 68
  • yes, I was able to generate the images. My doubt now is the image data is of 255x255x155 pixels. I don't know what 155 is. Do you have knowledge of BraTS dataset? – Naman Bansal May 30 '20 at 16:31
  • These are volumes, so they are 3D. You can use an MRI viewer (http://ric.uthscsa.edu/mango/papaya/index.html or ITK-SNAP) to see that it is 3D. – jkr May 30 '20 at 16:35
  • So if I have to train a CNN over this image, I am supposed to feed only on slice of the 3d image? – Naman Bansal May 30 '20 at 16:36
  • That's one option, or you can use 3D convolutional layers. I made a framework for training CNNs on magnetic resonance image that might help https://github.com/neuronets/nobrainer – jkr May 30 '20 at 16:38
  • Thanks a lot man. Also, I cannot find image labels in the BraTS 2019 dataset. Any idea where the labels for each patient are stored – Naman Bansal May 30 '20 at 16:40