Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
There are several spectral transformation methods in Earth Engine. These include instance
methods on images such as normalizedDifference(), unmix(),
rgbToHsv() and hsvToRgb().
Pan sharpening
Pan sharpening improves the resolution of a multiband image through
enhancement provided by a corresponding panchromatic image with finer resolution.
The rgbToHsv() and hsvToRgb() methods are useful for pan
sharpening.
Spectral unmixing is implemented in Earth Engine as the image.unmix() method.
(For more flexible methods, see the Array Transformations
page). The following is an example of unmixing Landsat 5 with predetermined urban,
vegetation and water endmembers:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003eEarth Engine provides spectral transformation methods like \u003ccode\u003enormalizedDifference()\u003c/code\u003e, \u003ccode\u003eunmix()\u003c/code\u003e, \u003ccode\u003ergbToHsv()\u003c/code\u003e, and \u003ccode\u003ehsvToRgb()\u003c/code\u003e for image manipulation.\u003c/p\u003e\n"],["\u003cp\u003ePan sharpening enhances image resolution by integrating a panchromatic band, often achieved using \u003ccode\u003ergbToHsv()\u003c/code\u003e and \u003ccode\u003ehsvToRgb()\u003c/code\u003e for color space conversion.\u003c/p\u003e\n"],["\u003cp\u003eSpectral unmixing, facilitated by \u003ccode\u003eimage.unmix()\u003c/code\u003e, decomposes image pixels into fractions of predetermined spectral endmembers (e.g., urban, vegetation, water).\u003c/p\u003e\n"],["\u003cp\u003eCode examples demonstrate pan-sharpening with Landsat 8 and spectral unmixing with Landsat 5 using both JavaScript and Python APIs in Earth Engine.\u003c/p\u003e\n"]]],[],null,["|---------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|\n| [Run in Google Colab](https://colab.research.google.com/github/google/earthengine-community/blob/master/guides/linked/generated/image_transforms.ipynb) | [View source on GitHub](https://github.com/google/earthengine-community/blob/master/guides/linked/generated/image_transforms.ipynb) |\n\nThere are several spectral transformation methods in Earth Engine. These include instance\nmethods on images such as `normalizedDifference()`, `unmix()`,\n`rgbToHsv()` and `hsvToRgb()`.\n\nPan sharpening\n\nPan sharpening improves the resolution of a multiband image through\nenhancement provided by a corresponding panchromatic image with finer resolution.\nThe `rgbToHsv()` and `hsvToRgb()` methods are useful for pan\nsharpening.\n\nCode Editor (JavaScript) \n\n```javascript\n// Load a Landsat 8 top-of-atmosphere reflectance image.\nvar image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');\nMap.addLayer(\n image,\n {bands: ['B4', 'B3', 'B2'], min: 0, max: 0.25, gamma: [1.1, 1.1, 1]},\n 'rgb');\n\n// Convert the RGB bands to the HSV color space.\nvar hsv = image.select(['B4', 'B3', 'B2']).rgbToHsv();\n\n// Swap in the panchromatic band and convert back to RGB.\nvar sharpened = ee.Image.cat([\n hsv.select('hue'), hsv.select('saturation'), image.select('B8')\n]).hsvToRgb();\n\n// Display the pan-sharpened result.\nMap.setCenter(-122.44829, 37.76664, 13);\nMap.addLayer(sharpened,\n {min: 0, max: 0.25, gamma: [1.3, 1.3, 1.3]},\n 'pan-sharpened');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\nColab (Python) \n\n```python\n# Load a Landsat 8 top-of-atmosphere reflectance image.\nimage = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')\n\n# Convert the RGB bands to the HSV color space.\nhsv = image.select(['B4', 'B3', 'B2']).rgbToHsv()\n\n# Swap in the panchromatic band and convert back to RGB.\nsharpened = ee.Image.cat(\n [hsv.select('hue'), hsv.select('saturation'), image.select('B8')]\n).hsvToRgb()\n\n# Define a map centered on San Francisco, California.\nmap_sharpened = geemap.Map(center=[37.76664, -122.44829], zoom=13)\n\n# Add the image layers to the map and display it.\nmap_sharpened.add_layer(\n image,\n {\n 'bands': ['B4', 'B3', 'B2'],\n 'min': 0,\n 'max': 0.25,\n 'gamma': [1.1, 1.1, 1],\n },\n 'rgb',\n)\nmap_sharpened.add_layer(\n sharpened,\n {'min': 0, 'max': 0.25, 'gamma': [1.3, 1.3, 1.3]},\n 'pan-sharpened',\n)\ndisplay(map_sharpened)\n```\n\nSpectral unmixing\n\nSpectral unmixing is implemented in Earth Engine as the `image.unmix()` method.\n(For more flexible methods, see the [Array Transformations\npage](/earth-engine/guides/arrays_transformations)). The following is an example of unmixing Landsat 5 with predetermined urban,\nvegetation and water endmembers:\n\nCode Editor (JavaScript) \n\n```javascript\n// Load a Landsat 5 image and select the bands we want to unmix.\nvar bands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7'];\nvar image = ee.Image('LANDSAT/LT05/C02/T1/LT05_044034_20080214')\n .select(bands);\nMap.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay\nMap.addLayer(image, {bands: ['B4', 'B3', 'B2'], min: 0, max: 128}, 'image');\n\n// Define spectral endmembers.\nvar urban = [88, 42, 48, 38, 86, 115, 59];\nvar veg = [50, 21, 20, 35, 50, 110, 23];\nvar water = [51, 20, 14, 9, 7, 116, 4];\n\n// Unmix the image.\nvar fractions = image.unmix([urban, veg, water]);\nMap.addLayer(fractions, {}, 'unmixed');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\nColab (Python) \n\n```python\n# Load a Landsat 5 image and select the bands we want to unmix.\nbands = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7']\nimage = ee.Image('LANDSAT/LT05/C02/T1/LT05_044034_20080214').select(bands)\n\n# Define spectral endmembers.\nurban = [88, 42, 48, 38, 86, 115, 59]\nveg = [50, 21, 20, 35, 50, 110, 23]\nwater = [51, 20, 14, 9, 7, 116, 4]\n\n# Unmix the image.\nfractions = image.unmix([urban, veg, water])\n\n# Define a map centered on San Francisco Bay.\nmap_fractions = geemap.Map(center=[37.5010, -122.1899], zoom=10)\n\n# Add the image layers to the map and display it.\nmap_fractions.add_layer(\n image, {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 128}, 'image'\n)\nmap_fractions.add_layer(fractions, None, 'unmixed')\ndisplay(map_fractions)\n```\nFigure 1. Landsat 5 imagery unmixed to urban (red), vegetation (green) and water (blue) fractions. San Francisco bay area, California, USA."]]