[GIS] Removing a specific band from an image composite with hundreds of bands in Google Earth Engine

google-earth-engine

In Google Earth Engine, the function glcmTexture() outputs 18 types of texture bands. Out of these, one band (suffixed as _maxcorr) is actually not computed by the servers but still exists in the output as a GLCM band with all zero pixel values.

This _maxcorr band creates a problem when band-wise normalization of the image composite is attempted by the unitScale() function as this function requires min value to be less than the max value.

How to tackle this issue?

I thought of two possibilities:

Prevent glcmTexture() from generating the "_maxcorr" band
OR
Remove "_maxcorr" band before input to unitScale() function

How to remove a specific band from an image in GEE?
Trying reverse by using .select() function is not feasible as there are hundreds of other bands in the composite that need to be selected.

Best Answer

In order to remove particular bands from an image, you can take the image's bandNames, filter that list to only the bands you want, and select those bands from the image:

function removeMaxCorr(glcmImage) {
  return glcmImage.select(
    glcmImage.bandNames().filter(
      ee.Filter.stringEndsWith('item', '_maxcorr').not()));
}

Map.addLayer(removeMaxCorr(myImage.glcmTexture()));

(The pseudo-property name 'item' is the name used to refer to the value of a List item that isn't a feature with its own properties — here, a string.).

Related Question