An expectation maximization is an iterative method to find maximum likelihood of parameters in statistical models. The EM algorithm is very similar to that of K-Means but uses a probability value instead of a hard cutoff. Today I will be showing on how to use EM algorithm to initialize a Mixture of Gaussian (MoG) . Specifically I would be using the EM algorithm to categorize the histogram of an Image as a MoG. For simplicity assume that the image histogram can be approximated by two Gaussian distributions.
For Instance consider the following figure. The histogram of this image is plotted below
The histogram shows a peak for the background as well as a peak for the skin color near 200. These two distributions can be approximated as a Gaussian and EM algorithm can be used to calculate the means and the variances of these distributions.
Once the means and the variances are computed those values can be used to threshold a particular color alone . Closed contours can also be used to extract face alone from the thresholded region. An implementation of EM algorithm from OpenCV's ml module was used directly and the resulting means were found at 0 and 136. The resulting standard deviation was found to be 0 and 83. This abnormal value of standard deviation indicate that the distribution cannot be modeled properly a Mixture of Gaussian with two modes.
So an attempt was made to model the distribution with three modes.The means were obtained at 200,46 and 0 with a Standard Deviation of 22.4,0 and 46.55 . This is a much more better fit for the histogram and hence 3 modes where taken.
Now lets try thresholding the image by a threshold given by mean-S.D=200-22=178
The white region corresponds to the skin color in the initial image.
Typically we would not be using EM algorithms for solving these problems since the number of points are quite large. Still this example illustrates the power of EM algorithm
The associated code can be found here
For Instance consider the following figure. The histogram of this image is plotted below
The histogram shows a peak for the background as well as a peak for the skin color near 200. These two distributions can be approximated as a Gaussian and EM algorithm can be used to calculate the means and the variances of these distributions.
Once the means and the variances are computed those values can be used to threshold a particular color alone . Closed contours can also be used to extract face alone from the thresholded region. An implementation of EM algorithm from OpenCV's ml module was used directly and the resulting means were found at 0 and 136. The resulting standard deviation was found to be 0 and 83. This abnormal value of standard deviation indicate that the distribution cannot be modeled properly a Mixture of Gaussian with two modes.
So an attempt was made to model the distribution with three modes.The means were obtained at 200,46 and 0 with a Standard Deviation of 22.4,0 and 46.55 . This is a much more better fit for the histogram and hence 3 modes where taken.
Now lets try thresholding the image by a threshold given by mean-S.D=200-22=178
The white region corresponds to the skin color in the initial image.
Typically we would not be using EM algorithms for solving these problems since the number of points are quite large. Still this example illustrates the power of EM algorithm
The associated code can be found here
No comments:
Post a Comment