Detect clusters of 3d points?
Hi folks!
I have a set of data that keeps on changing. The data is composed of 3000 points in 3d space with xyz coordinates (from 0. to 1.) and I want to extract all the clusters of data. Meaning in the end I should have about 1 to 5 xyz coordinates that would pinpoint to where the clusters are. I know they form clusters. All in real-time.
I thinking of an algorithm or maybe applying machine learning. I never used ml.*, I will check it asap. https://www.benjamindaysmith.com/ml-machine-learning-toolkit-in-max
Any other suggestions on how to approach this?
If by "pinpoint to where the clusters are" you mean get the mean position of each cluster (or kind of the center point of each cluster), then I am thinking about 2 ways to do that.
First, [xray.jit.kmeans] from the Xray package does exactly what you want, with the downside of requiring to tell it how many clusters it need to find first. But if you work with up to 5 clusters, you could quite easily do some math to check if 2 or more clusters are close enough to in fact represent one cluster.
Second, not sure about this one, but here is it. create a texture of, say, 1000x1000. draw a pixel for each point in the following way: for each point (x, y, z), set the (x, y) pixel with colors (r=x, g=y, b=z, a=whatever). For example, point (0.2, 0.6, 0.4) would result in pixel (200, 400) set to color (0.2, 0.6, 0.4, 1.).
Then, apply gaussian blur to your texture, then apply some smoothstep or color threshold, then use [cv.jit.blobs.centroids] from cv.jit package to get the x and y coordinates of your clusters. Then with some image masking and matrix computation you can get the mean value of blue for each cluster which gives you the z coordinate.
EDIT: Basically, what you want to achieve is K-means clustering. It's a complex problem with lots of literature and algorithms about it. Some can run very fast on the gpu through tensorflow (accessible in node js), but most are cpu based.