GMMs are a cool versatile technique to manipulate, generate, cluster, filter and what not. The possibilities are endless and the good thing about them is that they are very easy to use and train. In this post we will see a simple fun application of GMMs.

We start with a base image, it could be anything, as long it looks good to you. I started with the following image and manipulated it to remove the midtones (i.e. the gray areas). Then I converted it to points rather than a bitmap 2D array.

Then it is easy to train a GMM to the points we have extracted. For this image, it might need 30 seconds to do so. We can make it faster because most points are just location of individual pixels which fill up the area. However, it is simple and fast enough for now.

1
2
gmm = GMM(n_components=30, covariance_type='full', n_init=10)
gmm_fitted = gmm.fit(points)

As you can see, we got a silhouette of the logo by using simple 2D multivariate gaussian distributions. The interesting thing about them, is that we can label each cluster and we can shape it however we want it to be. In the 3rd photo on the right, you can see the image is sharper, that is due to multiplication of the \(cov * 0.6\). That lowers dispersion, making the image look sharper.

Conclusion

We saw how can we use GMM to mimic images and manipulate it by accessing the means_ and covariances_ attributes. These models are very powerful, and are being used in the industry in various different problems, as it just needs 2 lines of code to make a prototype.