Link Search Menu Expand Document

Tutorial 7

Image projection and reprojection

///////////////Finding image projection information//////////////////
//Find projection information for a Landsat image
// Point to a particular Landsat 5 image scene 
var image = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531'); 

//Print the projection information for the selected image to your Console tab 
print('Projection and transformation information:', image.projection()); 

//Print the nominal pixel size of the image (in meters) at the lowest level of the image pyramid
print('Pixel size in meters:', image.projection().nominalScale());


/////////////////Reprojecting images///////////////////
// Point to a MODIS vegetation index image product
var image = ee.Image('MODIS/MOD13A1/MOD13A1_005_2014_05_09');

//Print the projection information for the MODIS image to the Console 
print(image.projection());

//Display the image
var visParams = {min: 0.15, max: 0.7}; //Define visualization parameters 
Map.setCenter(-77.5127,43.2642,11); //Zoom to location near Rochester at level 11
Map.addLayer(image, visParams, 'original');  //Add the original image to the map.

//The pixels in the image look somewhat distorted, but can be reprojected to Maps Mercator
var reprojected = image
.reproject('EPSG:4326'); //EPSG:4326 is the code for ellipsoidal coordinates based on WGS 84 
Map.addLayer(reprojected, visParams, 'Reprojected');

Image registration

//Load two images to be registered.
var image1 = ee.Image('SKYSAT/GEN-A/PUBLIC/ORTHO/MULTISPECTRAL/s01_20150502T082736Z');
var image2 = ee.Image('SKYSAT/GEN-A/PUBLIC/ORTHO/MULTISPECTRAL/s01_20150305T081019Z');

//Resampling in GEE can use nearest neighbor, bilinear or bicubic interpolation
var image1Orig = image1.resample('bicubic'); //This forces the resampling method to bicubic
var image2Orig = image2.resample('bicubic'); //Without using resample, the default is nearest neighbor

//Choose to register using only the 'R' band.
var image1RedBand = image1Orig.select('R'); //Create a new image that contains only the red band
var image2RedBand = image2Orig.select('R');

//Approach 1 

//Determine the displacement needed to register image2 to image1 (using the selected red bands).
var displacement = image2RedBand.displacement({
referenceImage: image1RedBand, 
maxOffset: 50.0,      //defines the maximum displacement between the two images
patchWidth: 100.0   //size of patch used to determine image offsets.
});

// Use the computed displacement to register all original bands.
var registered = image2Orig.displace(displacement);

// Show the results of co-registering the images.
var visParams = {bands: ['R', 'G', 'B'], max: 4000};
Map.centerObject(image1Orig);
Map.addLayer(image1Orig, visParams, 'Reference');
Map.addLayer(image2Orig, visParams, 'Before Registration');
Map.addLayer(registered, visParams, 'After Registration');

//Approach 2 

// /*If you don't need to know what the displacement is, Earth Engine provides the register() method, which combines calls to displacement() and displace(). The register() function uses all bands of the image in performing the registration. */
var alsoRegistered = image2Orig.register({
referenceImage: image1Orig,
maxOffset: 50.0,
patchWidth: 100.0
});
Map.addLayer(alsoRegistered, visParams, 'Also Registered');