Quantitative-Big-Imaging-2019 icon indicating copy to clipboard operation
Quantitative-Big-Imaging-2019 copied to clipboard

K-means on images / 3D data

Open kmader opened this issue 6 years ago • 1 comments

I'd like to cluster my vector maps with k-means in time. My number of samples are thus my number of timesteps and the featurevector are the u and v vectors for all pixels. Like this, I cannot use the information that u and v are a couple at each point in space, I just stack them behind each other. sklearn.Kmeans doesn't allow for a third dimension.

kmader avatar Jul 27 '19 08:07 kmader

you have to reshape or flatten the array to use it with K-means. It (and most scikit-learn functions) take only 2D input. The first dimension is the number of observations and the second is the feature. In this example: https://www.kaggle.com/kmader/k-means-clustering-on-neurons

We reshape the 2D+time (WHT) image into (W*H, T) meaning each pixel is an observation and the feature is the time series.

In some of the examples in the lecture (advanced segmentation), we added the x and y position of the pixel as a feature so it could group regions together (ultimately leading to super pixels) You probably want to use U and V as the feature and possibly add x and y if it makes sense.

kmader avatar Jul 27 '19 08:07 kmader