Skip to content

Instantly share code, notes, and snippets.

@jscarto
Last active July 19, 2022 02:45
Show Gist options
  • Save jscarto/599914ac223f21fc45a2 to your computer and use it in GitHub Desktop.
Save jscarto/599914ac223f21fc45a2 to your computer and use it in GitHub Desktop.
Pan-sharpen and display a Landsat 8 scene in Google Earth Engine
// Band combinations
var natural = ['B4', 'B3', 'B2'];
var swir = ['B6', 'B5', 'B3'];
var urban = ['B7', 'B6', 'B4'];
var veg = ['B5', 'B4', 'B3'];
// Get a Landsat scene
var scene = ee.Image('LANDSAT/LC8_L1T_TOA/LC80450332015263LGN00');
// Convert the RGB bands to the HSV
var hsv = scene.select(urban).rgbToHsv();
// Add band 8 and convert back to RGB
var sharpened = ee.Image.cat([
hsv.select('hue'), hsv.select('saturation'), scene.select('B8')
]).hsvToRgb();
// Do a very basic color correction
var imageRGB = sharpened.visualize({min: 0, max:0.18,
gamma:[
1.05, // red
1.08, // green
0.8] // blue
});
// Display the image and zoom to it
Map.addLayer(imageRGB);
Map.centerObject(sharpened, 9);
@EkMuyal
Copy link

EkMuyal commented Aug 5, 2019

Hi, good example.
I was trying to do the same process but using sentinel-2. I got a white image instead a color composition, I think the problem is related to the visualization parameters, do you know how can I change it ?

@jscarto
Copy link
Author

jscarto commented Aug 5, 2019

Sentinel-2 does not have a panchromatic band, so this code will not work. It is specific to Landsat 8.

@BoineeloMoyo
Copy link

Hello, I tried to do for Landsat 7 using the same approach but I cant seem to get a collection of images that has a unique ID like yours. How do I pan sharpen a Landsat 7 image?

Thank you in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment