tags:

views:

123

answers:

2

Hi, I have some data points which I have devided into them into some clusters with some clustering algorithms as the picture below:(it might takes some time for the image to appear) alt text

Each color represents different cluster. I have to draw polygons around each cluster. I use convhull for this reason. But as you can see the polygon for the red cluster is very big and covers a lot of areas, which is not the one I am looking for. I need to draw lines(ploygons) exactly around my data sets. For example in the picture above I want a polygon that is drawn exactly the same(and around) as the red cluster with the 3 branches. In other words, in this case I need a polygon with 3 branches to cover my red clusters not that big polygon that covers the whole area. Can anyone help me with this? Please Note that the solution should be general, because the clusters will change in each run of the algorithm, so it needs to be in a way that is general.

+3  A: 

I am not sure this is a fully specified question. I see this variants on this question come up quite often.

Why this can not really be answered here: Imagine six points, three in an equilateral triangle with another three in an equilateral triangle inside it in the same orientation.

What is the correct hull around this? Is it just the convex hull? Is it the inner triangle with three line spurs coming out from it? Does it matter what the relative sizes of the triangles are? Should you have to specify that parameter then?

MatlabDoug
A: 

If your clusters are very compact, you could try the following:

  1. Create a grid, say with a spacing of 0.1.
  2. Set every pixel in the grid to 1 if there's at least one data point covering it, set the pixel to 0 if there is no data point covering the pixel.
  3. You may need to run imclose on your mask in order to fill little holes inside that have not been colored due to sheer bad luck.
  4. Extract the border pixels using, e.g. bwperim. This is the outline of the polygon you're looking for.
Jonas

related questions