
Introduction
Recently, I took an introductory psychology course in my first year of university where among other basic principles of psychology, we were taught about the brain, the ways we can visualize the brain using different kinds of scans, and how doctors use these scans to detect and monitor diseases. It got me wondering- is there a simple way I can visualize and analyze the brain?
A good amount of research led me to the course ‘Introduction to Neurohacking in R’ on Coursera. This course helped me gather the background information and the building blocks needed to visualize the brain using just two things: open-source MRI scans and R. Given Python is generally considered the go-to language for deep learning and image analysis, I wanted to challenge myself to use R and solve the questions I had.
Dataset
I tested my knowledge on a dataset I found on Kaggle called ‘Brain Tumor Progression’. It consists of the MRI scans of 20 patients suffering from Glioblastoma. There are two MRI exams included for each patient taken 90 days apart to monitor the progression of the tumor.
Questions I Answered
Question 1: How do I convert the scans into a format suitable for analysis?
Most hospitals store MRI scan data in a two-dimensional DICOM format where each axial slice of the brain is one DICOM file. This is done to protect health information. To make these images suitable for analysis by R, the first step is to convert DICOM into NifTI format, which combines all the DICOM files into a folder to come up with a 3D image of the brain (the NifTI format!). So say we wanted to take a look at the 11th axial slice of Patient 1’s brain, we get this.


Question 2: Is there a way to visualize certain tissues/parts of the brain using intensity values?
When I told R to highlight regions of the 11th slice of the brain with intensity values between 300 and 400 (excluding boundary values), it colored all those regions in red like this.


The first image is an axial view and the second image represents the coronal, sagittal, and axial views. When comparing the highlighted regions to existing literature, the red parts represent the white matter of the brain and few areas of the skull. From this, we can conclude that all white matter of the brain and a few regions of the skull have intensities between 301 and 399.
We can use this technique to highlight different parts/tissues of the brain having a particular range of intensities, compare them to literature, and gain a better understanding of the entire structure of the brain.
Question 3: Is there a way to subtract two scans taken some time apart from the same patient to monitor changes in the brain?
In the dataset, there are two MRI exams included for each patient taken 90 days apart to monitor the progression of the tumor. Instead of manually comparing the two scans for each patient, is there a way to ‘subtract’ the scans so that we know exactly which changes have occurred in the brain over the past 90 days? Luckily, we can achieve this with the help of R. The advantage of this function is that now we no longer have to make approximations of the changes. We know exactly how the tumor has progressed in the brain for each patient.
In this study, I decided to compare the changes in the brains of 2 patients – Patient 2 and Patient 20. On ‘subtracting’ the initial scan from the follow-up scan, my result for each patient was as follows.


We see that although the changes in the brain for both patients have been in different areas, the amount of tissue growth has been fairly similar. Hence, we can possibly conclude that the disease has progressed similarly for all the patients in the dataset.
Question 4: How can we make certain features of the brain more prominent?
There are two ways we can make particular regions of the brain pop out more and appear brighter or darker (depending upon what we want).
Option 1: Backmapping
Each MRI scan is a grayscale image with most of the image being a black background (intensity=0). In the backmapping technique, we tell R to only consider intensities greater or lesser than a threshold value to help us see the image better. For example, for a very dark image, we will tell R to plot all intensities greater than 50. This will help us get rid of the unnecessarily dark areas and make the overall image brighter. On the other hand, an image containing a point with intensity 1300 will make a point of intensity 200 very hard to see. In this case, we tell R to only consider intensities less than say 900 to make the essential features of the image easier to see.
Option 2: Transformations and Smoothing
We can transform images to make features of the brain more clearly visible. In this study, I used a linear transfer function and linear spline transformation. These are monotonic transfer functions, which means that shades of grey just become other shades of grey, white stays white, and dark stays dark- only their relative intensities change. The pictures below show both the original and transformed images. It is evident that the transformed image does a much better job of showing features of the brain.


If a picture has too much noise, smoothing can help to reduce some of it and make the image appear more clear. In this case, I used Gaussian smoothing. The results are shown below.


On comparing the original image with the smooth image, there does not seem to be much of a difference. This is probably because the data is very clean. In real-world data, the scans are not so clear and have a lot of noise in them. Smoothing will do a better job in that case. It is important to note that too much smoothing can lead to important features being lost, so the kernel size should be appropriate.
Future Research
This study helped me to develop a better understanding of the structure of the brain using R. Those who would like to replicate the results of this study can find the codes here.
There are two key ways we can proceed from here. One, to explore the brain further by analyzing brain MRI scans having other abnormalities. Second, to extend this study to other organs as well, depending on the availability of open-source data.
References
- Coursera course- ‘Introduction to Neurohacking in R’ by Johns Hopkins University: https://www.coursera.org/learn/neurohacking
- ‘Brain Tumor Progression’ Dataset from Kaggle: https://www.kaggle.com/andrewmvd/brain-tumor-progression
Original source of Dataset: Schmainda KM, Prah M (2018). Data from Brain-Tumor-Progression. The Cancer Imaging Archive. http://doi.org/10.7937/K9/TCIA.2018.15quzvnb