satpy.enhancements.contrast module
Stretching.
- satpy.enhancements.contrast._compute_luminance_from_rgb(r, g, b)[source]
Compute the luminance of the image.
- satpy.enhancements.contrast.btemp_threshold(img, min_in, max_in, threshold, threshold_out=None, **kwargs)[source]
Scale data linearly in two separate regions.
This enhancement scales the input data linearly by splitting the data into two regions; min_in to threshold and threshold to max_in. These regions are mapped to 1 to threshold_out and threshold_out to 0 respectively, resulting in the data being “flipped” around the threshold. A default threshold_out is set to 176.0 / 255.0 to match the behavior of the US National Weather Service’s forecasting tool called AWIPS.
- Parameters:
img (trollimage.xrimage.XRImage) – Image object to be scaled
min_in (float) – Minimum input value to scale
max_in (float) – Maximum input value to scale
threshold (float) – Input value where to split data in to two regions
threshold_out (float) – Output value to map the input threshold to. Optional, defaults to 176.0 / 255.0.
- satpy.enhancements.contrast.cira_stretch(img, **kwargs)[source]
Logarithmic stretch adapted to human vision.
Applicable only for visible channels.
- satpy.enhancements.contrast.piecewise_linear_stretch(img, xp, fp, reference_scale_factor=None, **kwargs)[source]
Apply 1D linear interpolation.
This uses
numpy.interp()mapped over the provided dask array chunks.- Parameters:
img (
XRImage) – Image data to be scaled. It is assumed the data is already normalized between 0 and 1.xp (numpy.typing.ArrayLike) – Input reference values of the image data points used for interpolation. This is passed directly to
numpy.interp().fp (numpy.typing.ArrayLike) – Target reference values of the output image data points used for interpolation. This is passed directly to
numpy.interp().reference_scale_factor (
Optional[Number]) – Dividexpandfpby this value before using them for interpolation. This is a convenience to make matching normalized image data to interp coordinates or to avoid floating point precision errors in YAML configuration files. If not provided,xpandfpwill not be modified.
- Return type:
Examples
This example YAML uses a ‘crude’ stretch to pre-scale the RGB data and then uses reference points in a 0-255 range.
true_color_linear_interpolation: sensor: abi standard_name: true_color operations: - name: reflectance_range method: !!python/name:satpy.enhancements.stretching.stretch kwargs: {stretch: 'crude', min_stretch: 0., max_stretch: 100.} - name: Linear interpolation method: !!python/name:satpy.enhancements.stretching.piecewise_linear_stretch kwargs: xp: [0., 25., 55., 100., 255.] fp: [0., 90., 140., 175., 255.] reference_scale_factor: 255
This example YAML does the same as the above on the C02 channel, but the interpolation reference points are already adjusted for the input reflectance (%) data and the output range (0 to 1).
c02_linear_interpolation: sensor: abi standard_name: C02 operations: - name: Linear interpolation method: !!python/name:satpy.enhancements.stretching.piecewise_linear_stretch kwargs: xp: [0., 9.8039, 21.5686, 39.2157, 100.] fp: [0., 0.3529, 0.5490, 0.6863, 1.0]
- satpy.enhancements.contrast.reinhard_to_srgb(img, saturation=1.25, white=100, **kwargs)[source]
Stretch method based on the Reinhard algorithm, using luminance.
- Parameters:
saturation – Saturation enhancement factor. Less is grayer. Neutral is 1.
white – the reflectance luminance to set to white (in %).
Reinhard, Erik & Stark, Michael & Shirley, Peter & Ferwerda, James. (2002). Photographic Tone Reproduction For Digital Images. ACM Transactions on Graphics. :doi: 21. 10.1145/566654.566575