GMM for Image Segmentation
The tool box contains 2 functions:
- fn_imgSegmentationGMM2: The main function that extracts pixel-level features from the original images and eventually output the segmentation results.
- [I_segm, I_posterior, I_max_posterior, ll] = fn_imgSegmentationGMM2(imagename, imageext, C, max_iteration, Rep, display_option)
- % INPUT
- % imagename: the filename of the image discarding the extension
- % imageext: the extension of the image, e.g., '.jpg', '.bmp', etc.
- % C: the desired number of class labels
- % max_iteration: the maximum number of iteration for EM algorithm
- % Rep: the number of repetitions for EM to run
- % display_option: display the segmentation results if equals to 'yes', and not displaying otherwise.
- %
- % OUTPUT
- % I_segm: Nrow by Ncol matrix each element is the MAP class label
- % I_posterior: Nrow by Ncol by C cube matrix represent the posterior for each class for each label
- % I_max_posterior: Nrow by Ncol matrix each element is the maximum posterior value corresponding to I_segm
- % ll: the log-likelihood of the results
- 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.
- fn_GMMSegforImg: Using GMM to cluster/segment the data
- [I_segm, I_posterior, I_max_posterior, ll] = fn_GMMSegforImg(img_feature_array, C, max_iteration, Rep)
- % Note that Nrow x Ncol is the dimension of the input image
- % INPUT
- % img_feature_array: The Nrow x Ncol x D matrix, each layer d = 1 to D
- % represent one feature type. So, this is like stacking feature images
- % together.
- % data: NrowxNcol by D matrix obtained from rearranging img_feature_array
- % C: the desired number of class labels
- % max_iteration: the maximum number of iteration for EM algorithm
- % Rep: the number of repetitions for EM to run
- % OUTPUT
- % I_segm: Nrow by Ncol matrix each element is the MAP class label
- % I_posterior: Nrow by Ncol by C cube matrix represent the posterior for each class for each label
- % I_max_posterior: Nrow by Ncol matrix each element is the maximum posterior value corresponding to I_segm
- % ll: the log-likelihood of the results
How to use the toolbox
How to use the toolbox
- Download the GMM image segmentation toolbox here
- Since this toolbox involves using color space, so you might want to install the color space toolbox.
- Run the function fn_imgSegmentationGMM2 -- that is it!
Preliminary Results
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