I have a 3-D matrix representing a hyper-spectral image: 2 dimensions represent different pixels, and 1 dimension represents different spectral bands.
I need to segment this image in the following way: 1. divide the image, pixel-wise, into 2 segments. 2. Calculate the average spectral value for each of the 2 segments. 3. Set all pixels in each of the 2 segments to be equal to said average.
In the end, I need the image divided into 2 segments, with all pixels in the same segment equal to that segment's spectral average.
I've tried using kmeans, but with no success so far.
Does anyone have any idea how to do it?