Parametrize pixel values to fit a desired range

You must know the actual range (computing it could take too much EE memory capacity)


In [1]:
import ee
ee.Initialize()

In [2]:
from geetools import tools

In [3]:
import ipygee as ui

In [4]:
i = ee.Image('COPERNICUS/S2/20181122T142749_20181122T143353_T18GYT').select('B1')

In [5]:
Map = ui.Map()

In [6]:
Map.show()



In [7]:
Map.addLayer(i, {'min':0, 'max': 6000}, 'Original')

As values in Sentinel 2 go from 0 to 10000, parametrize values to be between 0 and 1


In [8]:
parametrized = tools.image.parametrize(i, (0, 10000), (0, 1))

In [9]:
Map.addLayer(parametrized, {'min':0, 'max': 0.6}, 'Parametrized')

BEFORE


In [10]:
tools.image.getValue(i, i.geometry().centroid(), 10, 'client')


Out[10]:
{'B1': 4712}

AFTER


In [11]:
tools.image.getValue(parametrized, i.geometry().centroid(), 10, 'client')


Out[11]:
{'B1': 0.4712}

Range can be switched


In [12]:
switch_parametrized = tools.image.parametrize(i, (0, 10000), (1, 0))

AFTER

1 - 0.4712 = 0.5288

In [13]:
tools.image.getValue(switch_parametrized, i.geometry().centroid(), 10, 'client')


Out[13]:
{'B1': 0.5287999999999999}

In [ ]: