I am working with the Ocean Color SMI: Standard Mapped Image MODIS Aqua Data dataset.

Using the Sea Surface Temperature band, I am trying to assign the value "0" to any pixel in my region that has a value less than 30. Conversely, I need to assign a "1" to a pixel that has a value greater than or equal to 30. Essentially, some sort of binary process on the pixel data so that then when I visualize the map, there will be only two colors, the "0" and the "1."

How can I achieve this?


Simply use the comparison operation: image.gte(30). This will return an image whose pixel values are mapped to 0 and 1 exactly as you are looking for.

(You can also compare to another image; in fact, writing a number is equivalent to constructing and comparing against a constant-valued image.)

  • Thank you! So simply this should work? (Filtered for the month of April 2012 and ROI is my region) var dataset = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst') .filterDate('2012-04-01', '2012-04-30') .filterBounds(ROI); var modis = dataset.median(); var m= modis.gte(30); Map.addLayer(m.clip(ROI),{},'Binary'); – badiskhiari Jan 22 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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