colour.io.convert_bit_depth#
- colour.io.convert_bit_depth(a: ArrayLike, bit_depth: Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128'] = 'float32') NDArrayReal[source]#
Convert the specified array to the specified bit-depth.
The conversion path is determined by the current bit-depth of the input array and the target bit-depth. Supports conversions between unsigned integers, floating-point types, and mixed type conversions with appropriate scaling.
- Parameters:
- Returns:
Array converted to the specified bit-depth.
- Return type:
- Raises:
AssertionError – If the source or target bit-depth is not supported.
Examples
>>> a = np.array([0.0, 0.5, 1.0]) >>> convert_bit_depth(a, "uint8") array([ 0, 128, 255], dtype=uint8) >>> convert_bit_depth(a, "uint16") array([ 0, 32768, 65535], dtype=uint16) >>> convert_bit_depth(a, "float16") array([ 0. , 0.5, 1. ], dtype=float16) >>> a = np.array([0, 128, 255], dtype=np.uint8) >>> convert_bit_depth(a, "uint16") array([ 0, 32896, 65535], dtype=uint16) >>> convert_bit_depth(a, "float32") array([ 0. , 0.501960..., 1. ], dtype=float32)