rescale_shift#

geodesic.boson.rescale_shift(asset, bands=None, scale=None, shift=None, clamp=None, asset_name='rescaled')[source]#

Rescale the pixel values of an asset in a dataset.

Rescales the pixel values of an asset in a dataset by subtracting a shift from the pixel values and then dividing by a scale. This is useful for things like normalizing the pixel values of an image to be between 0 and 1 or 0 and 255, or recalibration pixels values under a linear transformation.

If scale/shift is not specified, will rescale by the local min/max of the pixel values across all bands. Do not use this with tiled services as each tile will be rescaled based on its min/max and the result will be a checkerboard pattern. Instead, use the scale/shift parameters to rescale the entire image tile set.

Parameters:
  • asset (str) – asset to rescale/shift

  • bands (List[str | int] | None) – bands to rescale/shift. If not specified, will use all bands for the specified asset.

  • scale (List[float] | None) – scale values for each band. This will divide the shifted pixel values by this value.

  • shift (List[float] | None) – shift values for each band. This will subtract this value from the pixel values prior to scaling.

  • clamp (List[float] | None) – If specified, must be 2 numbers to clamp the values between ranges. Values less than clamp[0] will be set to clamp[0] and values greater than clamp[1] will be set to clamp[1]. Defaults to None (no clamping)

  • asset_name (str) – name of the asset to create. Defaults to “rescaled”.

Examples

>>> # Rescale the pixel values of an asset with values in uint8 to be between 0 and 1
>>> transform = rescale_shift(
... asset="my_asset",
... bands=[0, 1, 2],
... scale=[255],
... shift=[0],
... asset_name="rescaled"
... )
>>> # Rescale all bands for "my_asset" to be between 0 and 255
>>> transform = rescale_shift(
... asset="my_asset",
... asset_name="rescaled"
... )
>>> # Rescale "red", "green", and "blue" bands for "image" to be between 0 and 1
>>> # using a known min/max
>>> transform = rescale_shift(
... asset="image",
... bands=["red", "green", "blue"],
... scale=[12345, 12345, 12345],
... shift=[123, 456, 789],
... asset_name="rescaled-rgb"
... )