CLIJx K-means Clustering

Hi @haesleinhuepf

I noticed that a K-means clustering command was added to CLIJx recently. I’m very curious in this, as I am doing some of this using the Cluster Image function of the Beat plugin in Fiji. However, I’m unsure of how to use the CLIJx version, as some of the options are not clear to me. Perhaps you, or someone else, could provide some help? I’ve uploaded a sample image that I have performed the Beat>Cluster Image function on, its result, and I’ve included the code from the macro recorder and a screenshot of the original image and result.

Here is the command for the K-means clustering in CLIJx:
Ext.CLIJx_kMeansLabelClusterer(Image_input, Image_label_map, Image_destination, String_features, String_modelfilename, Number_number_of_classes, Number_neighbor_radius, Boolean_train);

I have bolded the options that I’m not sure about.

Here is the readout from the macro recorder from running Beat>Cluster Image:

run("Cluster Image", "clustering=K-means provide=none additional=[] mask=[] factor elki=[-algorithm clustering.kmeans.KMeansLloyd -kmeans.k 7 -projhistogram.curves -parallel.clusteroutline.straight] path=[] captures=[] plot=[] sort=s weights=[] number=5 maximum=100 random=0 fuzziness=2 kernel=50.0000 normalization=1.00000000 error=0.000000001 initialize=50 total=0.0000 single=0.0000 minimal=0 maximally=100.0000 digits=-1 text1=");

Any help would be greatly appreciated!

k-means #5, max=100, limitmindifftot=0.0, limitmindiffmax=0.0, limitclustpix=0, limitratsurf=1.0.tif (2.3 MB) Calcite-1_OriginalImage_16bits-U_895x898x1516_45.26um0000.tif (1.5 MB)

1 Like

Hey @Nik ,

happy to see you’re interested in this function. However, I think you are expecting something completely different. It is a label-classifier. Hence, it needs a label image to operate on. If you for example threshold and label blobs.gif, you can then cluster the objects for PIXEL_COUNT:

I haven’t written documentation yet, but the Weka-Label-Classifier works similarily:

The major difference is that K-means-clustering doesn’t need ground-truth annotations. You basically control what it does by selecting the right features.

Let me know what you think.


1 Like


Ah, I see. I had a sneaking suspicion that it wasn’t, as you said, what I thought it would be :slight_smile:

Thanks for clarifying this for me, though. I have started to use K-means and Fuzzy C methods for multiphase segmentation of tomograms, and the Beat plugin is quite slow for large tiff stacks, so I thought I would see what the CLIJx version was about. Thanks for clarifying!

Any thoughts about including this kind of function in the wish list? :smiley:

1 Like

I’ve just added it. It’s always good to have some challenges for the next master student approaching :wink:

Thanks for the idea! I keep you posted in case something comes up :slightly_smiling_face:

1 Like

Awesome, thanks! This would be a great project for a student (for any students out there, hint hint) :smiley:

1 Like

Hi @Nik,

Apologies for replying to your question directed at @haesleinhuepf, but given his reply and the nature of your request I thought I may be allowed to offer an alternative approach. This is actually the 2nd time I have interjected in the past week in this manner, so please don’t hate me all.

I ported an awesome clustering library to ImageJ in the past year or so:

Which extracts XY values from a ‘Plot Values’ table to perform one of several clustering techniques on (including K-means, DBSCAN, and HDBSCAN).

In its current implementation I haven’t set it up to work directly on images, but, given your query, I found a cool way to apply it in that way with only a little pre-processing. I believe that the following method may work quite well on your image:

  • Use ‘Image>Transform>Flip Vertically’ on your image
  • Use find maxima/minima command to generate a list of objects ‘Process>Find Maxima…’
    • Set the ‘Light Background’ toggle to identify dark objects
    • Change output type to ‘Lists’
  • Rename the Results table to ‘Plot Values’
  • Run the ‘Cluster My Data’ plugin

Using the above workflow on the following example colony plate:

and by apply HDBSCAN, I was able to generate this topographically related and clustered plot:

(the missing central regions of the large clusters are related to my crude and quick find-maxima method for this example)

I hadn’t really thought to do this before seeing your post, so direct image processing was not included in the original plugin. When I can find some time I will add this function, so that the above pre-processing will not be necessary.

Again, apologies if this is not actually related to your requirements. Sorry also for replying when not asked to.

Kind regards.

1 Like

Hi @antinos! Thank you for your response, your plugin looks very interesting! I appreciate you interjecting, that is the great thing about this forum. We know what we know, and we don’t know what we don’t know, so when someone shows us something new it can really help with future image processing/analysis problems.

I’ll be interested if or when you develop the plugin for direct image processing, these types of methods for advanced/multiphase image segmentation can give some really nice results!