How to remove a modality from MRI image - Python Nibabel
Asked Answered
A

2

0

I am trying to use MRI brain imaging data for deep learning model. Currently my image has 4 dimensions as shown below but I would like to retain only the T1c modality of the MRI image because my model input should only be 1 channel 3D MRIs (T1c).

I did try to make use of the Nibabel package as shown below

import nibabel as nib 
ff = glob.glob('imagesTr\*')
a = nib.load(ff[0])
a.shape

This returns the below output

enter image description here

I am also pasting the header info of 'a'

enter image description here

From this, which of the dimension is used to identify the MRI modality like (T1,T2, T1c, FLAIR etc)? and How can I retain only T1c?. Can you please help?

Asiatic answered 21/6, 2019 at 6:36 Comment(8)
What do you want to remove? The 4th dimensions ? What do you need to keep? if you have T1,T2,T1c, FLAIR then these are stored as [240,240,155] arrays in the 4th dimension of aPerishable
How do I know whether my MRI image is of type T1, T2, or T1c?Asiatic
Currently, I have a DL model which doesn't accept my mri image as input. The model only accepts T1c modality MRI images. So how to make my image suitable for the model (MRI image with T1c modality)Asiatic
I understand that 240, 240 indicate the height and width, 150 represents the no of slices, but what does 4 represent here?Asiatic
4 here should be T1,T2, T1c, FLAIR. So if you take for example a[:,:,:,0] this would give you the T1 or T2 or T1c or FLAIR based on how you have stored the data initially. Do you know the right order?Perishable
No, I do not know how the data was stored. Is there anyway to find out?Asiatic
yes. probably from the header of a. try print(a.header)Perishable
Let us continue this discussion in chat.Asiatic
P
2

First you need to identify the order of the images stores in the 4th dimensions.

Probably the header will help:

print(a.header)

Next, to keep only 1 modality you can use this:

data = a.get_fdata()
modality_1 = data[:,:,:,0]

EDIT 1:

Based on the website of the challenge:

All BraTS multimodal scans are available as NIfTI files (.nii.gz) and describe a) native (T1) and b) post-contrast T1-weighted (T1Gd), c) T2-weighted (T2), and d) T2 Fluid Attenuated Inversion Recovery (FLAIR) volumes, and were acquired with different clinical protocols and various scanners from multiple (n=19) institutions, mentioned as data contributors here.

and

The provided data are distributed after their pre-processing, i.e. co-registered to the same anatomical template, interpolated to the same resolution (1 mm^3) and skull-stripped.

So the header will not help in this case (equal dimensions for all modalities due to preprocessing).

If you are looking for the post-contrast T1-weighted (T1Gd) images then it's the 2nd dimension so use:

data = a.get_fdata()
modality_1 = data[:,:,:,1]

Additionally, we can visualize the each 3D volume (data[:,:,:,0], data[:,:,:,1],data[:,:,:,2], data[:,:,:,3]) and verify my statement.

See here: https://gofile.io/?c=fhoZTu

Perishable answered 21/6, 2019 at 8:23 Comment(0)
C
1

It's not possible to identify the type of MRI from the Nifti header. You would need the original DICOM images to derive this type of information.

You can, however, visually check your images and compare the contrast/colour of the white matter, grey matter and ventricles to figure out if your image is T1, T2, FLAIR, etc. For instance in a T1-image you would expect darker grey matter, lighter white matter and black CSF. In a T2 image you would expect lighter grey matter, darker white matter and white CSF. A FLAIR is the same as T2 but with 'inverted' CSF. See some example brain images here: https://casemed.case.edu/clerkships/neurology/Web%20Neurorad/t1t2flairbrain.jpg

That being said, you seem to have a 4-dimensional image, which suggests some sort of time series, so I would assume your data is DTI or fMRI or something like it.

It's also not possible to transform one type of MRI into another, so if your data set is not already T1, then there is no way to use it in a model that expects clean T1 data.

I would strongly encourage you to learn more about MRI and the type of data you are working with. Otherwise it will be impossible to interpret your results.

Cubit answered 4/11, 2019 at 11:6 Comment(1)
Thanks, I've been using it passively for a while but came across your question on medium.com and wanted to help. Did you find a solution in the meantime? I hadn't realised it was quite a while ago...Cubit

© 2022 - 2024 — McMap. All rights reserved.