classToBands#

geetools.ImageAccessor.classToBands(class_info, band=0)#

Convert each class into a separate binary mask.

Parameters:
  • class_info (dict) – class information.

  • band (str | int) – band that contains class information

Return type:

ee.Image

Example

import ee, geetools
from geetools.utils import initialize_documentation

initialize_documentation()

class_info = {
  '2': 'dark',
  '3': 'shadow',
  '7': 'clouds_low',
  '8': 'clouds_mid',
  '9': 'clouds_high',
  '10': 'cirrus'
}
image = ee.Image("COPERNICUS/S2_SR_HARMONIZED/20230120T142709_20230120T143451_T18GYT")
decoded = image.geetools.classToBands(class_info, "SCL")
decoded.getInfo()
{'type': 'Image',
 'bands': [{'id': 'dark',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]},
  {'id': 'shadow',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]},
  {'id': 'clouds_low',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]},
  {'id': 'clouds_mid',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]},
  {'id': 'clouds_high',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]},
  {'id': 'cirrus',
   'data_type': {'type': 'PixelType', 'precision': 'int', 'min': 0, 'max': 1},
   'dimensions': [5490, 5490],
   'crs': 'EPSG:32718',
   'crs_transform': [20, 0, 699960, 0, -20, 5300020]}]}