ffledgling
ffledgling

Reputation: 12140

Finding elongated clusters using MATLAB

Let me explain what I'm trying to do. I have plot of an Image's points/pixels in the RGB space. What I am trying to do is find elongated clusters in this space. I'm fairly new to clustering techniques and maybe I'm not doing things correctly, I'm trying to cluster using MATLAB's inbuilt k-means clustering but it appears as if that is not the best approach in this case.

What I need to do is find "color clusters".

This is what I get after applying K-means on an image. enter image description here

This is how it should look like:

enter image description here

for an image like this:

enter image description here

Can someone tell me where I'm going wrong, and what I can to do improve my results?


Note: Sorry for the low-res images, these are the best I have.

Upvotes: 3

Views: 1202

Answers (3)

Don Reba
Don Reba

Reputation: 14031

Take a look at density-based clustering algorithms, such as DBSCAN and MeanShift. If you are doing this for segmentation, you might want to add pixel coordinates to your vectors.

Upvotes: 1

Raff.Edward
Raff.Edward

Reputation: 6514

Are you trying to replicate the results of this paper? I would say just do what they did.

However, I will add since there are some issues with the current answers.

1) Yes, your clusters are not spherical- which is an assumption k-means makes. DBSCAN and MeanShift are two more common methods for handling such data, as they can handle non spherical data. However, your data appears to have one large central clump that spreads outwards in a few finite directions.

For DBSCAN, this means it will put everything into one cluster, or everything is its own cluster. As DBSCAN has the assumption of uniform density and requires that clusters be separated by some margin.

MeanShift will likely have difficulty because everything seems to be coming from one central lump - so that will be the area of highest density that the points will shift toward, and converge to one large cluster.

My advice would be to change color spaces. RGB has issues, and it the assumptions most algorithms make will probably not hold up well under it. What clustering algorithm you should be using will then likely change in the different feature space, but hopefully it will make the problem easier to handle.

Upvotes: 2

Shai
Shai

Reputation: 114796

k-means basically assumes clusters are approximately spherical. In your case they are definitely NOT. Try fit a Gaussian to each cluster with non-spherical covariance matrix. Basically, you will be following the same expectation-maximization (EM) steps as in k-means with the only exception that you will be modeling and fitting the covariance matrix as well.

Here's an outline for the algorithm

  1. init: assign each point at random to one of k clusters.
  2. For each cluster estimate mean and covariance
  3. For each point estimate its likelihood to belong to each cluster
    note that this likelihood is based not only on the distance to the center (mean) but also on the shape of the cluster as it is encoded by the covariance matrix
  4. repeat stages 2 and 3 until convergence or until exceeded pre-defined number of iterations

Upvotes: 1

Related Questions