Convert image from float [0, 1] to discrete type (e.g. uint8 [0, 255]). Inverse of ToFloat. max_value and dtype control scaling and output type.
This transform is designed to convert images from a normalized floating-point representation (typically with values in the range [0, 1]) to other data types, scaling the values appropriately.
dtypeThe desired output data type. Only 'uint8' is supported. Default: 'uint8'.
max_valueThe maximum value for the output dtype. If None, 255 for uint8.
pProbability of applying the transform. Default: 1.0.
>>> import numpy as np
>>> import albumentations as A
>>> transform = A.FromFloat(dtype='uint8', max_value=None, p=1.0)
>>> image = np.random.rand(100, 100, 3).astype(np.float32) # Float image in [0, 1] range
>>> result = transform(image=image)
>>> uint8_image = result['image']
>>> assert uint8_image.dtype == np.uint8
>>> assert uint8_image.min() >= 0 and uint8_image.max() <= 255from_float function internally, which ensures output values
are within the valid range for the specified dtype.