I have an Image of LULC raster values where each band represents the classification for the years 2000-2023. I would like to count the last number of consecutive forest classifications (LULC code 3) for each pixel.
For example, with 10 fictitious years, the bands for a pixel and the resulting value looks like:
- 1,3,4,3,3,3,3 -> 4
- 3,3,7,7,7,3,7 -> 1
I have looked into counting runs for the longest consecutive block of 3's, but cannot figure out how to do it for the last consecutive block.
Here is the initial code so far:
var lulc = ee.Image('projects/mapbiomas-public/assets/brazil/lulc/collection9/mapbiomas_collection90_integration_v1');
var years = ee.List.sequence(2000, 2023);
var bandNames = years.map(function(y) { return ee.String('classification_').cat(ee.Number(y).toInt()); });
var selected = lulc.select(bandNames);
// TODO: Count number of last consecutive LULC=3's.