K-means clustering operator freezes

Hi everyone. I am performing a K-means classification in SNAP by using two images of Sentinel1 GRD(VV, VH), and two images of Sentinel 2(bands 2-12). I’ve used a tutorial from ESA called “Synergetic use of radar and optical data” to make sure I am going through the right steps:

Sentinel 1:

  1. Subset
  2. Radiometric Calibration
  3. Speckle Filtering
  4. Range Doppler Terrain Correction ( I used an external DEM)

Sentinel 2:

  1. S2 Resampling ( to 10m)
  2. Subset

Merge:

  1. Collocation Operator

Classification:

  1. k-means clustering (I used all bands and one ROI)

However, it seems the k-means classification operator is not well supported by SNAP as it freezes all the time, and the same happens in QGIS. I can not get any output. Did anyone have a similar experience and solve this problem afterwards? Any advice/help will be very useful. Many thanks.

were you able to create an RGB color composite of radar and optical bands? Just to make sure that the stack contains valid bands of both products?

If both SNAP and QGIS freeze, you might not have sufficient memory to process the size of the dataset. You could test on a very small subset if the process finishes.

Hi ABraun, thanks for your quick reply.

Yes, I can create a RGB color composite from the stack image (image below)

As you suggested, I have selected a very small ROI-mask as parameter. I’ve also reduced the number of cluster to only 3, but it keeps freezing. I have also tried with the EM cluster classification, but the same happens.

all stored as BEAM DIMAP?

It should work with a small subset…

Hi ABraun,

I just solved it.
Yes, the images were used as BEAM DIMAP. Basically I changed everything (nº clusters,subset size, ROI_mask size, nº of bands, nº of images, storage location) to look for the parameter that was causing this error, and I found out that it was the size of original subset. Now I need to see if the storage location is also affecting the final output as I am downloading everything at the internal hardrive, but ideally I’d like to store everything at the external hardrive.

Also, when running the classification I got an error: "The combination of the ROI and valid pixel mask contain 0 pixel. These are too few to…" but I solved it by removing the “Valid-Pixel Expression” of every band. However, is there anything that I can do to avoid this? Many thanks

1 Like

good to hear, thank you for reporting.

Were the valid pixel expressions produced by earlier processing steps?

Yes, they were.

can you give an example?

They are in the original S2_L1C products, but not in the S1 ones, I don’t understand why. I am not so familiar with this concept.

there are some expressions to exclude non-valid pixels, but I guess the only option is to remove all valid pixel expressions.

1 Like

Right, ok. Well, it is good to know that the problem is solved. Thanks a lot for your support Andreas!Appreciate that a lot.

María

1 Like

Hello Andreas, am working with S1 data - used texture analysis and using just one band (from textures) trying to get K-means. But, don’t understand what’s getting it wrong. It just doesn’t produce the output.
I have tried the same pattern earlier - it worked.
Now just the size of the image is large, the rest of the procedure is all that worked before - that doesn’t work anymore.

To assume size to be an issue, I work on office cluster that’s supposedly got TBs of space.
So what could be the issue?
Would be great to solve it,.

The k-means doesn’t freeze in my case, whereas , the resultant is blank.

So it gets stuck during the processing or the output is empty?

output is empty

thanks for being literally prompt

Could it be that the different textures have different value ranges? K-means can have problems if the input features are not of the same range (e.g. 0-1).

Oh, But it did work before.
Initially, I used just a single band from Texture Analysis
Later, after going through discussions here, I added a few more bands (Assuming one and wont be the right choice).
What’s up with the valid pixel expression?
I don’t understand it well.
Does it apply to Texture results too?

It defines in the band properties if certain values are ignored. You can check all bands and disable it before running the clustering.

1 Like

Hi,

I’m having issues running a K-means cluster analysis on Sentinel-1 pre-processed dB, with the attached message. From this thread, it appears that I need to disable the valid pixel expression. I now know where this is in each band, but unsure as to what it means and how to disable?