1

When I display my classification map, the colors don't line up with the variable that I want them to. For example, my forest category is represented as red (instead of my goal color-green), or my water category shows up as gray (instead of 'blue').

How do I order my color palette such that it corresponds with the classes appropriately?

This is my script so far in Google Earth Engine:

//Create a classification map. Classify the input imagery
var classified = composite.select(bands).classify(classifier);

//Define the palette for the land use classification

var palette = [
  '0000FF', // water (0)  -- blue
  'FFFF00', // cultivated (1)  -- yellow
  'DCDCDC', //  Settlement (2) -- gray
  'F0E68C', // Grasslands (3)--khaki
  '228B22', // forest  (4)-- forest green
  '000000', //clouds (5)-- black
  '808000', //intact veg (6)-- olive
  'FFA500', //impacted_veg (7)-- orange
  'DC143C', //mines (8)-- crimson
];

// Display the classification result and the input image.
Map.centerObject(K2C_aoi);
Map.addLayer(classified, {min: 0, max: 2, palette: palette}, 'Land Use Classification');

1 Answer 1

2

Earth Engine's visualization does not have a special case for integer or discrete values; the palette colors will be applied across the numerical range specified in the visualization parameters, with linear interpolation in between.

So, change max from 2 to palette.length - 1 (which will be the number of your last class, 8 in this case) to ensure the integer values in the image will line up with the palette entries.

Map.addLayer(classified, {
  min: 0,
  max: palette.length - 1,
  palette: palette
}, 'Land Use Classification');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.