I am struggling to create the code where if the previous classified image and the sequential classified image in the image collection are both urban for example, then make the current image class urban at that pixel as well.
What I have so far, but doesn't work:
var sortedCollection = classified2.sort('system:time_start', true);
var adjustImage = function(image) {
var currentImage = image.get('system:time_start');
var previousImage = ee.Image(sortedCollection.filter(ee.Filter.lt('system:time_start', currentImage)).first());
var nextImage = ee.Image(sortedCollection.filter(ee.Filter.gt('system:time_start', currentImage)).first());
if (previousImage !== null && nextImage !== null) {
var imageFixed = currentImage.where(previousImage.eq(6), 6);
return imageFixed;
} else {
return currentImage;
}
};
var correctedCollection = sortedCollection.map(adjustImage);
Map.addLayer(correctedCollection, {}, 'FirstCorrectedImage');