arrlp.compress module
- arrlp.compress(array, /, max=1, min=0, *, dtype=None, out=None, stacks=False, channels=False, white=None, black=None, white_percent=None, black_percent=None, saturate=None)[source]
Compresses an array between values by normalizing, with possibility to saturate extrema.
- Parameters:
array (np.ndarray) – Array to normalize.
max (int or float or None) – white value in output. None for no changing of white
min (int or float or None) – black value in output. None for no changing of black
dtype (np.dtype or str or None) – dtype of output, None for same as input
out (array) – Array where to save, if None will create new array.
stacks (bool) – True to apply on stacks.
channels (bool) – True to apply on channels.
white (int or float or None) – white value in input. None for maximum
black (int or float or None) – black value in input. None for minimum
white_percent (int or None) – white percentage distribution in input if white is None.
black_percent (int or None) – black percentage distribution in input if black is None.
saturate (Any or bool or None) – If True, will saturate values above white and black. If Any, will replace by this value. If None no saturation.
- Returns:
array – Normalized and saturated copy of array.
- Return type:
np.ndarray
Examples
>>> from arrlp import compress >>> array = np.arange(100, dtype=np.float32) ... >>> compress(array, 10, 5) # compresses array between 10 and 5 >>> compress(array, white=50, black=40) # compresses array linearly so that 50 value is at 1 and 40 is at 0 >>> compress(array, white=50, black=40, saturate=np.nan) # compresses array linearly so that 50 value is at 1 and 40 is at 0, replace outside values by np.nan >>> compress(array, white_percent=10, black=1) # compresses array linearly so that 10% of array will be white, and 1% black (without saturation) >>> compress(array, white_percent=10, black=1, saturate=True) # compresses array linearly so that 10% of array will be white, and 1% black (with saturation)