Kamal Hosen
Kamal Hosen
Geospatial Developer | Data Science | Python

Oct 25, 2022

Visualize Image in Google Earth Engine


We can visualize raw or processed images in various ways at Google Earth Engine.

In this tutorial, I will show you how to visualize different types of images in GEE.


(A) Visualize Landsat 8 Raw Satellite Image

Step 1: Load Landsat 8 image

var img = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_137044_20140330');

Step 2: Define Visual Parameters

var vizParams = {
  bands: ['B5', 'B4', 'B3'],
  min: 0,
  max: 0.5,
  gamma: [0.95, 1.1, 1]

Step 3: Set map center and visualize the image

Map.setCenter(89.53852287434427, 22.838390957302963, 10); // Khulna Bangladesh
Map.addLayer(image, vizParams, 'false color composite');

Here, band 'B5' is assigned to red, 'B4' is assigned to green, and 'B3' is assigned to blue.


(B) Visualize Single Band Image

To display a single band of an image in color, set the palette parameter with a color ramp represented by a list of CSS-style color strings.

Step 1: Load Image

var img = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_137044_20140330');

Step 2: Create NDWI from image

var ndwi = img.normalizedDifference(['B3', 'B5']);

Step 3: Define visual parameters

var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']}; // cyan ('00FFFF') to blue ('0000FF') 

Step 4: Add and display image on map

Map.addLayer(ndwi, ndwiViz, 'NDWI', false);

Here, the cyan (low value) indicates non-water and blue (higher value) indicates water.

(C) Adding opacity to image pixel during visualization

GEE provides a masking function to set the opacity of individual pixels based on where pixels in a mask image are non-zero. Pixels equal to zero in the mask are excluded from computations, and the opacity is set to 0 for display. We will use the above NDWI image and mask it by 0 values to get only water pixels.

// Mask the non-watery parts of the image, where NDWI < 0.4.
var ndwiMasked = ndwi.updateMask(ndwi.gte(0.4));
Map.addLayer(ndwiMasked, ndwiViz, 'NDWI masked');


Share To

About Author
  • Kamal Hosen
  • Kamal Hosen
    Geospatial Developer | Data Science | Python

    A passionate geospatial developer and analyst whose core interest is developing geospatial products/services to support the decision-making process in climate change and disaster risk reduction, spatial planning process, natural resources management, and land management sectors. I love learning and working with open source technologies like Python, Django, LeafletJS, PostGIS, GeoServer, and Google Earth Engine.