Hi,

I was wondering if it is possible to coregister all the Sentinel-2 images in a Google Earth Engine collection over a year.

I am able to coregister everything to a single image (e.g., the first in the collection) but only for small areas were essentially all the images of the collection have the same footprint of the reference image.

However my area of interest is very large so I would need to define different reference images every time in order to cover the all area of interest.

Any suggestion? I copied below the relevant part of the code:

var listOfImages = dataset.toList(dataset.size()); //the dataset is my images collection made of thousands of Sentinel-2 data.

//print('listOfImages:', listOfImages)

var bandIn = ['B2','B3','B4','B5','B6','B7','B8'];

var bandOut = ['B2','B3','B4','B5','B6','B7','B8'];

var firstImage = listOfImages.get(0) // this is my reference. I would need to create a dynamic reference image but do not know how to do it!

function coregistration_S2(image, listOfImages){

var imgS2SR_reference = ee.Image(firstImage).select(bandIn,bandOut).clip(roi);

var imgS2SR_warp = ee.Image(image).select(bandIn,bandOut).clip(roi);

// Choose to register using only the 'Red' band.

var imgS2SR_reference_red = imgS2SR_reference.select('B4');

var imgS2SR_warp_red = imgS2SR_warp.select('B4');

// Determine the displacement by matching only the 'Red' bands.

var displacement = imgS2SR_warp_red.displacement({

referenceImage: imgS2SR_reference_red,

maxOffset: 20.0,//The maximum offset allowed when attempting to align the input images, in meters

patchWidth: 100.0 // Small enough to capture texture and large enough that ignorable

//objects are small within the patch. Automatically ditermined if not provided

});

//wrap the imgS2SR_warp image

var imgS2SR_aligned = imgS2SR_warp.displace(displacement);

// Compute image offset and direction.

var offset = displacement.select('dx').hypot(displacement.select('dy'));//in m

var angle = displacement.select('dx').atan2(displacement.select('dy'));// in rad

// Display offset distance and angle.

//Map.addLayer(offset, {min:0, max: 5}, 'offset');

//Map.addLayer(angle, {min: -Math.PI, max: Math.PI}, 'angle');

return imgS2SR_aligned;

}

var coregistration_S2_collection = dataset.map(coregistration_S2); // this is where I do the coregistration of the whole collection.

More Alessandro Novellino's questions See All
Similar questions and discussions