Introduction: MRI Images of Healthy Brains Ages 19-72
Fun stuff with MATLAB!!
In the video you saw the succession of many slices of MRI scans of a participant. The image is an example of laying out all of the slices in the video side-by-side. The following steps of code will explain how we extract the area of the brain by isolating it from the skull and the other extraneous fluids.
Step 1: Step 1: Loading the MRI Slices
Make sure you write all of your code in the Script.
In order to get started on analyzing the area of the brain we need images to work with. MRI images give us some of the clearest images to analyze. Since we have a large amount of files to upload we want to use something called batch processing so it does the tedious uploading for us. The MRI files are 'mha' files which is just a special type of file specifically for MRI images. A for loop is used to upload all the files in the 'skull' folder. The rest of the code puts the files into a format that MATLAB can understand so you can use them later.
Step 2: Step 2: Visualizing
If you want to see the videos for all of the brains that you upload include this in your code. Remember if there is a % sign in front of the code then it is usually just a comment. In this case (excluding the first line which is a comment you want to keep), you would need to remove the rest of the % in order to MATLAB to complete the action.
Step 3: Step 3: Another Way to Visualize
This is the code you want to use if you want to display all of the slices side-by-side as seen in the beginning. It orders them based on the size of the shape so you get to cool progression of each of the slides. The 'montage' function is what allows all of the images to be put together. The last line of code bounds the image and sets up the axes.
Step 4: Step 4: Choosing the Best Slices
By using the for loop in this case we are only working with slices 70-90 of each file. We chose these slices because that's the part of the brain that is the biggest. Now grayscale images, entitled figure2, of the MRI slices will pop up.
Step 5: Step 5: Heightening the Contrast
In order to make the whites, grays, and blacks more distinct we used 'imadjust' to heighten the contrast of the image. This is very important because we need a clear image, fuzzy pictures just won't do.
Step 6: Step 6: Binary Image
MATLAB requires a specific type of image in order to be able to find the area of a shape; it is called a binary image. A binary image is all black and white. Each one of the black pixels is represented as a 0 and the white pixels are represented as a 1. In order to get it to be black and white we have to decide what type of gray we want to be white and what type of gray we want to be black. We set the number 13000 as our threshold. All grays less than that are now black and the ones above are white. Thresholds are found by testing out different numbers. Feel free to change it around and see what you get!
Step 7: Step 7: Testing the Threshold
In the previous code we created a threshold on the contrasted image. In order to make sure that we didn't lose anything important, like the edges of the brain, we are now taking the threshold of the original images, so that MATLAB can compare. As you can see when we threshold this image it looks messier than the previous one. This really helps show the importance of clear images.
Step 8: Step 8: Isolating the Brain
In the next few steps we will be working on eliminating the skull from the image. When we take the area of the image in following steps it will be counting the number of pixels that are white, and we do not want the white skull to mess up our data. In this image you can see that we also have small black spots in the brain. We don't want that either so it will be fixed later.
Step 9: Step 9: Fine Tuning
We are trying to get as exact as possible to only get the size of the brain.
Step 10: Step 10: Still Checking...
Now we are overlapping testBinaryImage and b to check the size again. You can never have too many checks. (That's probably not true all the time, but in this case we want to make extra sure).
Step 11: Step 11: This Is What We Want!
Now we have just the brain, and we are very certain that it is as close as we can get to the original size.
Step 12: Step 12: Finally the Area!
If you made it this far congratulations you can now take the area of the image! We are taking each file and calculating the areas of all of the slices individually. We want all those numbers to be saved so we save it as a vector. It is important that we get the biggest area for each of the file so we take the maximum (max) for all of those slices. We repeat the process and get another vector of all of the maximum areas of all the files.
Step 13: Step 13: Categorizing the Data
Now that we have all the data that we need, we need to make sure that it means something! Each of the files that we uploading in the beginning represented the brain scan of one person. In an excel file we wrote down that person's age and gender so that we could later plot it, and see if there are any trends in the data.
In order to get the excel file loaded into MATLAB you need to manually import it using the import button. under the home tab. When you import make sure you import it was a string array.
Step 14: Step 14: Brain Size V. Age
This code shows how you would make a graph to display the information of your findings. We need to smush all of the information together as a string array so that the images will be associated with the right gender and age. We decided to use a scatter plot because it helps show each one of the data points clearly. The red line going through the middle shows the line of best fit. The line of best fit is determined by the trend of the data. As you can see here our findings show that there is a significant drop in brain size over time. It also shows the progression is stable and at no point in life does your brain dramatically start shrinking.
Step 15: Step 15: Based on Gender
We next wanted to see if there was any difference between the rate of shrinking based on male and female brains. This code is not commented because all of the comments are basically the same as step 14. Our data suggests that males have a sharper decrease in their brain size. What does that mean? We don't know, it wasn't part of our project. Hope you enjoyed!!
We have a be nice policy.
Please be positive and constructive.
Make sure that in the beginning you download Read Medical Data 3-D as an add on in order to be able to view the mha files.