2
$\begingroup$

I did some clustering on an image (each pixel is an observation that has 5 variables associated with it), I get pretty detailed results but they are a little bit noisey... I think. I used K-means. Does anyone have a nice idea on how to reduce the noise a bit? anyone know some postprocessing for K-means. I would usually just apply a median filter to the image or something of the sort but I want to know if there is something a little nicer out there.

p.s. this was all done in python by the way, only brightly colored pixels were clustered.

enter image description here

$\endgroup$

2 Answers 2

4
$\begingroup$

When you did K-means, presumably you treated the attributes at each pixel as a $5$-tuple of real values and you clustered them based on Euclidean distance in $\mathbb{R}^5$. To achieve spatial contiguity in the clustering, include spatial coordinates among the attributes. If you include (say) the two Cartesian map coordinates, you will effectively be doing the K-means clustering in $\mathbb{R}^7 \approx \mathbb{R}^5 \times \mathbb{R}^2$. I have written this as a Cartesian product to emphasize that there is a tuning parameter available to you: the relative sizes of the last two (spatial) attributes compared to the first five attributes. By rescaling the spatial attributes you can vary the amount by which they influence the clustering. With only a little influence, the result will be noisy; with a lot of influence, you will be performing purely spatial clustering. Experiment to identify an optimal value.

(This is an approach I have used many times. It is not always as successful as I would like, but it works sufficiently often to be worth looking at in any case.)

$\endgroup$
4
  • $\begingroup$ I like this idea a lot. Sorry I had not read this I dont know why. Would finding this optimal weight for the coordinates variables be done only visually? Because I have a huge amount of images and I the main idea is to automatize the process as much as possible. I have also read about using region growing for the same purpose. Do you have any experience with this? @whuber $\endgroup$
    – JEquihua
    Commented Mar 31, 2013 at 17:45
  • $\begingroup$ One would hope that tuning the procedure on one or a small number of images would enable it to work satisfactorily on all similar images. The tuning doesn't have to be visual, but to automate it, you would need some way to quantify how well you think it's working. $\endgroup$
    – whuber
    Commented Mar 31, 2013 at 20:36
  • $\begingroup$ Do you have any idea on as to what kind of statistic to use to quantify this? I, intuitevely would like the clusters to be geographically homogeneous together i.e. maybe a lower bound on the number of adjacent pixels in the neighbourhood belonging to the same cluster could help? But that's just from the top of my head... $\endgroup$
    – JEquihua
    Commented Mar 31, 2013 at 22:58
  • $\begingroup$ Unfortunately, if you require the clusters to be as geographically homogeneous as possible, then the answer is to downweight the attributes to zero. You need to quantify the amount by which you are willing to trade off an decrease in geographic homogeneity for an increase in the homogeneity of the attributes within the clusters. $\endgroup$
    – whuber
    Commented Apr 1, 2013 at 13:31
1
$\begingroup$

A very simple-minded way to reduce the noise would be to apply a filter that creates a new image in which each pixel's ID is replaced by the most common ID found among its neighbours. (Don't do this calculation in-place, put the answers in a new matrix.)

However, it'd be much better to use a Conditional Random Field model rather than K-means, since it directly includes the idea of pixels' neighbourliness.

(Also have a look at this comparison of clustering methods implemented in scikit-learn.)

$\endgroup$
2
  • 1
    $\begingroup$ Welcome to our site, Dan! This recommendation is called a "majority filter"; as such, it is offered as a substitute for the median filter--but that's exactly the kind of approach the OP is trying to avoid. Your suggestion of a CRF is intriguing: would you care to expand on how it would be applied here? $\endgroup$
    – whuber
    Commented Feb 8, 2013 at 21:12
  • $\begingroup$ I actually started off using gaussaian mixtures - EM algorithm to find clusters in the images but they are quite big ( 5000 x 5000 x 5 bands) and this method apparently doesn't work well at all for data of this size. I would also be very interested in you expanding a bit on how to apply crf's here. $\endgroup$
    – JEquihua
    Commented Mar 31, 2013 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.