# Spectral Clustering X SLIC Superpixels Standard

Previously we talked about Spectral Clusterings  , which basically performs K-Means on eigenvectors of Laplacian matrix from a graph. While we could perform segmentation using normal K-Means by applying the algorithm on an image, the same thing cannot be said about Spectral Clusterings.

This is because spectral clustering (at least from what I know) requires the creation of Laplacian matrix first. For a m x n image with 3 channels, we need to create a (m x n x 3) x (m x n x 3) Laplacian matrix, and subsequently perform eigendecomposition and k-means on the eigenvectors. This can be very taxing and slow.

However, by leveraging our knowledge on superpixels , we can actually reduce the search space drastically. Rather than using all the pixels, we could first create, say 400 superpixels, and then create a Laplacian matrix (400 x 400) out of it, thus Spectral Clustering is much more feasible. In this case we’re viewing the superpixels as gross approximation of the more detailed image pixels.

The implementation goes like this:

• After performing SLIC superpixels, we create a laplacian matrix using the SLIC superpixels cluster centers as the vertex for our graph. The important part here is to modify so that the distance measure of adjacency matrix utilizes the CIELab + X-Y space used in SLIC.
• Apply eigendecomposition, and get the k-smallest eigenvectors
• Perform k-means on the eigenvectors and get the corresponding clusters

Here’s the result:

The result of the segmentation depends on the superpixels, and sigma for the gaussian distance used in creating adjacency matrix. Higher number of superpixels means that spectral clustering part will be much slower too, and might be harder to segment the image too.

You can get the codes here: https://github.com/subokita/Sandbox/tree/master/SLICSuperpixelsAndSpectralCluster

## 2 thoughts on “Spectral Clustering X SLIC Superpixels”

1. jsroizz

Nice post! 🙂 What OpenCV version are you using?

• sub

Sadly I can’t remember precisely. Probably 2.4.8 or somewhere around that.