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.
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:
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: