2

I have a natural color of Hawaii Main Island to export, but when I exported it, it only showed a grayscale information in QGIS, but I know that this is not a QGIS problem, it's from GEE.

enter image description here

enter image description here

This was the first script I executed when I exported it without knowing that I was having a grayscale .tif Image:

/**
 * Function to mask clouds based on the pixel_qa band of Landsat 8 SR data.
 * @param {ee.Image} image input Landsat 8 SR image
 * @return {ee.Image} cloudmasked Landsat 8 image
 */
function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 5);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterDate('2014-01-01', '2020-12-31')
                  .map(maskL8sr);

var visParams = {
  bands: ['B4', 'B3', 'B2'],
  min: 0,
  max: 3000,
  gamma: 1.4,
};
Map.setCenter(-155.5459, 19.5623, 9);
Map.addLayer(dataset.median(), visParams);

var IMGLandsat8= ee.ImageCollection ('LANDSAT/LC08/C01/T1_SR') 
  .filterDate ('2014-01-01', '2020-12-31') 
  .filterBounds (geometry) 
  .filterMetadata ('CLOUD_COVER', 'Less_Than', 4);
var Landsat8Filtro = ee.Image(IMGLandsat8.median());
var Landsat8Clip = Landsat8Filtro.clip (geometry);
Map.addLayer (Landsat8Clip, {
  min: 0.0,
  max: 2500,
  gamma: 1.0,
  bands: ['B4','B3','B2']}, 
  'Imagen Landsat 8');
print (Landsat8Filtro);
Export.image.toDrive({
  image: Landsat8Clip.select("B4", "B3", "B2"),
  description: 'Landsat8_30m',
  scale: 30,
  region: geometry});

Here I will leave you a link to make it simpler to see:

Hawaii Export Script

Everything's ok until I discovered it exported in grayscale, now I was looking around here and got some code to export it in RGB scale, but when I click in run it appears the message:

"image" is not defined in this scope."

Because I'm new on GEE, I don't know how I can solve it. Can anyone more experienced help me?

Here's the code I've tried:

  /**
 * Function to mask clouds based on the pixel_qa band of Landsat 8 SR data.
 * @param {ee.Image} image input Landsat 8 SR image
 * @return {ee.Image} cloudmasked Landsat 8 image
 */
function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 5);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterDate('2014-01-01', '2020-12-31')
                  .map(maskL8sr);

var visParams = {
  bands: ['B4', 'B3', 'B2'],
  min: 0,
  max: 3000,
  gamma: 1.4,
};
Map.setCenter(-155.5459, 19.5623, 9);
Map.addLayer(dataset.median(), visParams);

var imageRGB = image.visualize({bands: ['B4', 'B3', 'B2'], min: 0, max: 2500});
print("rgb",imageRGB);

Export.image.toDrive({
  scale: 30,
  image: imageRGB,
  description: 'example_image_RGB',
  fileFormat: 'GeoTIFF',
  region: image.geometry});

Here's the link of this script:

Hawaii RGB Export Script

0

1 Answer 1

4

Looks like you haven't defined a variable called image - which is what you pass along to the visualize() function. Try changing your visualize line to:

var imageRGB = dataset.median().visualize({bands: ['B4', 'B3', 'B2'], min: 0, max: 2500});
print("rgb",imageRGB);

You’ll also need to update the geometry in your export because ‘image’ doesn’t exist:

Export.image.toDrive({
  scale: 30,
  image: imageRGB,
  description: 'example_image_RGB',
  fileFormat: 'GeoTIFF',
  region: geometry});
8
  • I've tried but got this message: Image (Error) Image.visualize: No band named 'B4_median'. Available band names: [B1, B2, B3, B4, B5, B6, B7, B10, B11, sr_aerosol, pixel_qa, radsat_qa]. "image" is not defined in this scope. Commented Aug 4, 2020 at 19:23
  • Oops - my bad. I've run into band renaming issues before. Try the updated code. Commented Aug 4, 2020 at 19:38
  • Ok it solved the script problem, but when I downloaded the result in drive and compress the files I got this: drive.google.com/file/d/1xcEimWWB7iVaii1iQNqmPf_yVoU5QW-7/… Commented Aug 4, 2020 at 21:06
  • This it's what I did with your code: code.earthengine.google.com/0da95158823fee166130743eda8ebb8f Commented Aug 4, 2020 at 21:08
  • Ah - I see the problem. You want to export within the region bounds geometry which you are using as a polygon, rather than a function which is what I originally thought you wanted. It might be worth renaming your ROI to something less conflict-y (given that geometry() is also a function in Earth Engine. Regardless, the region definition above fixes your problem based on an ROI called "geometry". Commented Aug 4, 2020 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.