viqa.utils.normalize_data¶
- viqa.utils.normalize_data(img: ndarray | ImageArray, data_range_output: Tuple[int, int], data_range_input: Tuple[int, int] | None = None, automatic_data_range: bool = True) ndarray | ImageArray [source]¶
Normalize an image to a given data range.
- Parameters:
img (np.ndarray or ImageArray) – Input image.
data_range_output (Tuple[int]) – Data range of the returned data.
data_range_input (Tuple[int], default=None) – Data range of the input data. Needs to be set if
automatic_data_range
is False.automatic_data_range (bool, default=True) – Automatically determine the input data range.
- Returns:
img_arr – Input image normalized to data_range.
- Return type:
np.ndarray or ImageArray
- Raises:
ValueError – If data type is not supported. If
data_range_output
is not supported. Ifautomatic_data_range
is False anddata_range_input
is not set.- Warns:
RuntimeWarning – If data is already normalized.
Notes
Currently only 8 bit int (0-255), 16 bit int (0-65535) and 32 bit float (0-1) data ranges are supported.
Examples
>>> import numpy as np >>> from viqa import normalize_data >>> img = np.random.rand(128, 128) >>> img_norm = normalize_data( >>> img, >>> data_range_output=(0, 255), >>> automatic_data_range=True, >>> ) >>> np.max(img_norm) 255