colour.io.convert_bit_depth¶
- colour.io.convert_bit_depth(a: ArrayLike, bit_depth: Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128'] = 'float32') numpy.ndarray [source]¶
Convert given array to given bit depth, the current bit depth of the array is used to determine the appropriate conversion path.
- Parameters
a (ArrayLike) – Array to convert to given bit depth.
bit_depth (Literal['uint8', 'uint16', 'float16', 'float32', 'float64', 'float128']) – Bit depth.
- Returns
Converted array.
- Return type
class`numpy.ndarray`
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)