hypso.rgb.exposure#

Exposure adjustment of RGB images: one gain for all channels, so colours are kept (unlike a per-channel percentile stretch, which also white-balances).

Works on any RGB here: a camera image (hypso.rgb.read_camera_image()), a camera product (hypso.rgb.camera_product(), R/G/B variables), an hypso.rgb.HSI2RGB() rendering or any (..., 3) array.

Examples

>>> brighter = adjust_exposure(camera, ev=1.5)          # +1.5 stops
>>> auto = adjust_exposure(camera)                      # 99th percentile of brightness -> 90% of full scale
>>> display = adjust_exposure(camera, gamma=2.2, normalize=True)   # 0-1 floats for plotting

Functions#

adjust_exposure(image[, ev, percentile, target, ...])

Brighten or darken an RGB image with one gain for all channels.

black_level(rgb[, mode, percentile])

Black level(s) to subtract: the percentile of each channel

exposure_gain(rgb[, percentile, target, full_scale])

The gain that maps the percentile of the image's luminance to

Module Contents#

hypso.rgb.exposure.adjust_exposure(image, ev=None, percentile=99.0, target=0.9, gamma=None, full_scale=255.0, normalize=False, black_point=None, black_percentile=1.0)[source]#

Brighten or darken an RGB image with one gain for all channels.

Parameters:
  • image (xarray.DataArray, xarray.Dataset or numpy.ndarray) – (y, x, channel) DataArray, a Dataset with R, G, B variables, or an array whose last axis is R, G, B.

  • ev (float, optional) – Exposure change in stops (gain 2**ev): +1 doubles, -1 halves. Default: automatic, so the percentile of the luminance lands at target of full_scale.

  • percentile (float, default 99 and 0.9) – Automatic exposure only.

  • target (float, default 99 and 0.9) – Automatic exposure only.

  • gamma (float, optional) – Display gamma applied after the gain (e.g. 2.2 lifts dark water); None keeps the result linear.

  • full_scale (float, default 255) – The value of white: 255 for the camera’s 8-bit counts, 1 for 0-1 images such as HSI2RGB output.

  • normalize (bool, default False) – Return 0-1 values instead of 0-full_scale.

  • black_point ({None, "common", "channel"} or float or 3 floats, optional) – Subtract a black level before the gain: "channel" the black_percentile of each channel (removes haze and the camera’s dark offset; usually the most natural look over water), "common" one level for all channels (keeps the colour balance), or given value(s) in the image’s units. None (default): gain only. A channel that is saturated (e.g. blue in a bright summer capture) cannot be restored, and per-channel levels then shift the colour.

  • black_percentile (float, default 1) – For "common"/"channel".

Returns:

Float32, clipped at full scale (saturated pixels stay white). Xarray results carry exposure_gain, exposure_ev, exposure_gamma and exposure_black attributes.

Return type:

Same type as image

hypso.rgb.exposure.black_level(rgb, mode='channel', percentile=1.0)[source]#

Black level(s) to subtract: the percentile of each channel ("channel": removes a colour cast such as atmospheric haze, like dark object subtraction) or its smallest value over the channels ("common": keeps the colour balance).

Parameters:
Return type:

numpy.ndarray

hypso.rgb.exposure.exposure_gain(rgb, percentile=99.0, target=0.9, full_scale=255.0)[source]#

The gain that maps the percentile of the image’s luminance to target of full_scale (NaN pixels ignored).

Parameters:
Return type:

float