English | Deutsch
Helpers for files¶
Colour enhancement¶
The true-colour download and the false-colour downloads call these when enhance_color=True or
enhance_contrast=True (Colours and values). They are not exported by the cdec package;
import them from cdec.eo.postprocessing. The ..._raster functions rewrite a file in place.
- cdec.eo.postprocessing.enhance_color(data)[source]¶
Apply the Sentinel-2 true-color enhancement to RGB reflectance data.
- Parameters:
data (ndarray) – Array with shape
(3, height, width)containing red, green, and blue reflectance values.- Returns:
The enhanced image as 8-bit values (0 to 255), same shape as
data.- Return type:
numpy.ndarray
- Raises:
ValueError – If
datadoes not have the shape(3, height, width).
- cdec.eo.postprocessing.enhance_contrast(data, min_val=0.0, max_val=0.4)[source]¶
Stretch reflectance contrast while compressing bright highlights.
This is a NumPy approximation of Sentinel Hub’s HighlightCompressVisualizer. Input values are reflectance, typically in the range 0..1. The result contains display intensities in the range 0..1. The default stretch uses 0..0.4, as in the Sentinel-2 false-colour urban visualization.
The stretch is fixed: it depends only on
min_valandmax_val, never on the values indata, so the same reflectance always gives the same intensity.- Parameters:
data (ndarray) – Array of reflectance values, any shape.
min_val (float) – Reflectance that is displayed as black (0).
max_val (float) – Reflectance at the top of the linear stretch, displayed at about 93 % brightness. Brighter values are compressed instead of clipped; a reflectance of
2 * max_val - min_valand above is white (1).
- Returns:
Display intensities from 0 to 1, same shape as
data.- Return type:
numpy.ndarray
- Raises:
ValueError – If
max_valis not greater thanmin_val, or if one of them is not finite.
- cdec.eo.postprocessing.enhance_color_raster(raster_path)[source]¶
Rewrite a red/green/blue reflectance GeoTIFF in place as enhanced 8-bit RGB.
Uses
enhance_color(). The bands must be ordered red, green, blue. Pixels without data stay without data (black, with a mask stored inside the file).This changes the file itself and the original reflectance values are lost. Normally you do not call it yourself:
download_true_color_imagedoes it for you whenenhance_color=True.- Parameters:
raster_path (str | Path) – Three-band GeoTIFF with red, green and blue reflectance. It is overwritten with an 8-bit RGB GeoTIFF.
- Raises:
ValueError – If the file does not have exactly three bands.
- cdec.eo.postprocessing.enhance_contrast_raster(raster_path)[source]¶
Rewrite a three-band reflectance GeoTIFF in place as contrast-enhanced 8-bit RGB.
Uses
enhance_contrast(). The bands must already be ordered as the intended red, green and blue display channels. Pixels without data stay without data (black, with a mask stored inside the file).This changes the file itself and the original reflectance values are lost. Normally you do not call it yourself:
download_false_color_urbandoes it for you whenenhance_contrast=True.- Parameters:
raster_path (str | Path) – Three-band GeoTIFF with reflectance in the order of the display channels (red, green, blue). It is overwritten with an 8-bit RGB GeoTIFF.
- Raises:
ValueError – If the file does not have exactly three bands.