pybsm.simulation.functional.stretch_contrast_convert_8bit

pybsm.simulation.functional.stretch_contrast_convert_8bit(*, img: ndarray, perc: list[float] | None = None) ndarray

Adjusts the contrast of an image and converts it to an 8-bit format.

This function stretches the contrast of the input image based on specified percentile values. The pixel values are normalized to the 8-bit range (0-255) and any values outside this range are clipped.

Parameters:
  • img – The original image.

  • perc – A list of two percentile values (0-100) to determine the contrast stretch. The first value corresponds to the lower percentile and the second to the upper percentile. If not provided, defaults to [0.1, 99.9].

Returns:

A numpy array of the same shape as img, with pixel values converted to 8-bit unsigned integers (0-255) after contrast stretching.

Example:
>>> import numpy as np
>>> img = np.random.rand(100, 100) * 65535  # Example 16-bit image
>>> stretched_img = stretch_contrast_convert_8bit(img=img)