Saturday, July 25, 2015

Progress Report

Hi all,

During this last three weeks I have been mainly designing, implementing, debugging and running tests for the brain tissue classification code. It is tough because you have to think of all possible options, input arguments, noise models that the end user may end up trying. I have learned a lot during this period, mainly because I have never tested any code so thoroughly and it has also come to my attention the importance of this kind of practice. You realize how “fragile” your code can be and how easy it is to make it fail. This has been a true experience of how to develop really robust software.

Although my mentors and I decided to not move forward to the validation phase until having finished the testing phase, we decided to refactor the code (in part to make it also more robust as I was saying before) and to cythonize some loops that were causing the code to be slow. This has also been a interesting learning experience because I am practically new to cython and the idea of writing python-like code at the speed of C seems fascinating to me.

I am planning to post more detailed information about the testing throughout this weekend. I will be working on finalizing this phase of the project the next couple of days and jump directly to the validation step.


Keep it up and stay tuned!

Thursday, July 2, 2015


Midterm Summary

So, the first part of GSoC is over and the first midterm is due today. Here is a summary of this period. 

The main goal of the project is to implement a segmentation program that is able to estimate the Partial Volume (PV) between the three main tissue types of the brain (i.e. white matter, cerebrospinal fluid (CSF) and grey matter). The input to the algorithm is a T1-weighted Magnetic Resonance Image (MRI) of the brain.  
I checked back on what I have worked on so far and these are my two big accomplishments:

- The Iterated Conditional Modes (ICM) for the Maximum a Posteriori - Markov Random Field (MAP-MRF) Segmentation. This part of the algorithm is at the core of the segmentation as it minimizes the posterior energy of each voxel given its neighborhood, which is equivalent to estimating the MAP. 
- The Expectation Maximization (EM) algorithm in order to update the tissue/label parameters (mean and variance of each label). This technique is used because this is an “incomplete” problem, since we know the probability distribution of the tissue intensities but don’t know how each one contributes to it. 

By combining these two powerful algorithms I was able to obtain 1) the segmented brain into three classes and 2) the PV estimates (PVE) for each tissue type. The images below show an example coronal slice of a normal brain and its corresponding outputs. 

What comes next? Tests, tests, tests…. Since I have the segmentation algorithm already up and running I have to do many tests for input parameters such as the number of iterations to update the parameters with the EM algorithm, the beta value, which determines the importance of the neighborhood voxels, and the size of the neighborhood. Validation scripts must be implemented as well to compare the resulting segmentation with publicly available programs. These validation scripts will initially compute measures such as Dice and Jaccard coefficients to verify how close my method’s results are to the others.  

For an updated version of the code and all its development since my first pull request please go to:

https://github.com/nipy/dipy/pull/670#partial-pull-merging

T1 original image
Segmented image. Red: white matter, Yellow: grey matter,
Light Blue: corticospinal fluid
Corticospinal fluid PVE
Grey matter PVE

White matter PVE