Segmentation of 3D images using the Hidden Markov Random Field Model (HMRF) and Expectation-Maximization Algorithm (EM)

A MATLAB implementation of the HMRF as described in "Segmentation of Brain MR Images Through a Hidden Markov Random Field Model and the Expectation-Maximization Algorithm" (Zhang et al., 2001). The HMRF is applied to segment images from the cross-sectional OASIS-brains dataset but the code provided can be modified for any 3D image segmentation.

On this page, I give a quick read about the HMRF model, what my code does and what this code can be used for. If you're interested in a more detailed explanation of the underlying math as well as how I applied this model to brain tissue segmentation, read this paper I wrote about it.

HMRF 101

Why should I care about this HMRF?

Great question! Before we talk about HMRF's, we need to take a few steps back and talk about Markov Random Fields (MRF's). MRFs are a powerful statistical tool that are exploited in image segmentation applications to provide spatial context into generative models. Work prior to Zhang et al. in 2001 used MRFs as priors in finite mixture models that model tissue intensities (ie. GMM's) or in non-parametric models (ie. Parzen Windows). However, the simplifications made in these models come from mathematical convenience, as opposed to a statistical foundation. Using a HMRF to explicitly model the tissue intensities avoids these assumptions since the spatial relationships are built into the model. The paper (Zhang et al., 2001) is a landmark in the field of brain tissue segmentation, but the model can be extended across any domain where capturing local spatial relationships is important to the segmentation task.

What can I test this algorithm on?

Short answer - any 3D image. I validated the model using the OASIS- Cross-sectional dataset. This dataset consists of 416 normal and early onset Alzheimer Disease subjects from ages 18-96. Ground truth labels are provided in the dataset - which come from the FAST-FSL implementation of the HMRF described in the Zhang et al. paper.

What does my code do?

  1. Obtain an initial estimate of the HMRF parameters from an initial segmentation (Otsu or Kmeans).
  2. Calculate likelihood distribution of the intensity data given the bias field and the initial tissue classification.
  3. Obtain tissue class estimates using MRF-MAP criteria (using the ICM algorithm).
  4. Calculate the conditional probability distribution of each class given the intensity values of that class.
  5. Update the HMRF parameters for each class.
  6. Repeat steps 2-5 until convergence.

What did I do with it?

If you're interested in my own exploration with the HMRF model, check out this paper I wrote that introduces the model in the context of brain tissue segmentation. It introduces the challenge of tissue segmentation and classification in medical imaging, describes the high level segmentation pipeline, mathematical modelling of the HMRF, the optimization through EM, and a discussion of the results I obtained through this implementation of the model when applied to applied to white matter, grey matter, and cerebrospinal fluid (CSF) segmentation in the OASIS cross-sectional brains dataset..

Authors and Contributors

Tanya Nair (@tanyanair)