GMM for Image Segmentation

The tool box contains 2 functions:

  1. fn_imgSegmentationGMM2: The main function that extracts pixel-level features from the original images and eventually output the segmentation results.
    1. [I_segm, I_posterior, I_max_posterior, ll] = fn_imgSegmentationGMM2(imagename, imageext, C, max_iteration, Rep, display_option)
    2. % INPUT
    3. % imagename: the filename of the image discarding the extension
    4. % imageext: the extension of the image, e.g., '.jpg', '.bmp', etc.
    5. % C: the desired number of class labels
    6. % max_iteration: the maximum number of iteration for EM algorithm
    7. % Rep: the number of repetitions for EM to run
    8. % display_option: display the segmentation results if equals to 'yes', and not displaying otherwise.
    9. %
    10. % OUTPUT
    11. % I_segm: Nrow by Ncol matrix each element is the MAP class label
    12. % I_posterior: Nrow by Ncol by C cube matrix represent the posterior for each class for each label
    13. % I_max_posterior: Nrow by Ncol matrix each element is the maximum posterior value corresponding to I_segm
    14. % ll: the log-likelihood of the results
    15. The feature included in the function is, for instance, generalized RGB (gRGB), standardized CIELuv (sLuv), generalized-standardized CIELab (gsLab), standardized gray-scale, standardized x-y location of each pixel. The user can add any feature to the function directly. Once all the feature vectors are collected and reorganized as a cube matrix Nrow x Ncol x D, where D is the number of features, the function will call function fn_GMMSegforImg which performs GMM on the cube matrix.
  2. fn_GMMSegforImg: Using GMM to cluster/segment the data
    1. [I_segm, I_posterior, I_max_posterior, ll] = fn_GMMSegforImg(img_feature_array, C, max_iteration, Rep)
    2. % Note that Nrow x Ncol is the dimension of the input image
    3. % INPUT
    4. % img_feature_array: The Nrow x Ncol x D matrix, each layer d = 1 to D
    5. % represent one feature type. So, this is like stacking feature images
    6. % together.
    7. % data: NrowxNcol by D matrix obtained from rearranging img_feature_array
    8. % C: the desired number of class labels
    9. % max_iteration: the maximum number of iteration for EM algorithm
    10. % Rep: the number of repetitions for EM to run
    11. % OUTPUT
    12. % I_segm: Nrow by Ncol matrix each element is the MAP class label
    13. % I_posterior: Nrow by Ncol by C cube matrix represent the posterior for each class for each label
    14. % I_max_posterior: Nrow by Ncol matrix each element is the maximum posterior value corresponding to I_segm
    15. % ll: the log-likelihood of the results

How to use the toolbox

  1. Download the GMM image segmentation toolbox here
  2. Since this toolbox involves using color space, so you might want to install the color space toolbox.
  3. Run the function fn_imgSegmentationGMM2 -- that is it!

Preliminary Results

Top-left: The original image from Microsoft Research Lab Database

Top-right: The segmentation result using the toolbox

Bottom-left: The posterior distribution at each pixel

Bottom-right: The maximum value of the posterior distribution at each node