kmeans or Jenks clustering

Hey guys, I saw that you have kmeans clustering in your firmware, but it doesn’t seem to be exposed on the python side (or used elsewhere in the github repo?).

Is there any chance you could expose this function in python, so that it could be called on an image?

I’m trying segment ~450x40 pix grayscale images into three colors, without predefining/hardcoding the thresholds, as they’re subject to change

Otsu / get_threshold() works great if the number of colors is two

I tried to use this Jenks Natural Breaks clustering (jenks-python/ at master · llimllib/jenks-python · GitHub), but ran out of memory (what I wouldn’t give for an H7 Plus :smiley:)

Anyway, kmeans or Jenks would be super useful to have available, even if they run slow

Technically the cartoon method was implemented to do this. It works poorly however as kmeans/jenks would be much better for this.

Um, anyway, me and Ibrahim are really maxed out on the things we have to do and our time to do it. Can you submit C for for what you want? Then it can get in the firmware quickly. I have a large backlog to do otherwise and it will take months to get to this…

Note, on the H7 Plus only the frame buffer is in SDRAM, the MicroPython heap is still small. But, you basically have unlimited C memory for algorithms.

Question, can I implement these algorithms on histograms? Or do they need to be on all pixels? I assume it needs to be on all pixels at once…