0

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?

Gil
  • 143
  • 2
  • 9

1 Answers1

0

It would help if you elaborate on what about kmeans() is not working for you. I suspect that you are trying to preserve the image dimensions (m x n pixels) in your call to kmeans.

If you collapse across rows/cols, kmeans should be able to classify each pixel by its spectral-band vector.

[m,n,sps] size(data); %pixel row, pixel col, spectral band
numGroups = 2;
[idx,centers] = kmeans(reshape(data,[m*n,sps]),numGroups);
Brendan Frick
  • 1,047
  • 6
  • 19