AlbumentationsExplore
DocumentationExploreAdoptionCommercial LicenseBlog
GitHub

ToFloat Albumentations documentation

ToFloat

Targets:
image
volume
Image Types:uint8, float16, float32

Convert byte intensities to floating values using a chosen maximum, while preserving the values and precision of floating inputs.

Arguments
max_value
float | None

The maximum possible input value. If None, the transform will try to infer the maximum value by inspecting the data type of the input image:

  • uint8: 255
  • float16, float32: 1.0 (floating inputs are preserved) Default: None.
p
float
1

Probability of applying the transform. Default: 1.0.

Examples
>>> import numpy as np
>>> import albumentations as A
>>>
# Convert uint8 image to float
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.ToFloat(max_value=None)
>>> float_image = transform(image=image)['image']
>>> assert float_image.dtype == np.float32
>>> assert 0 <= float_image.min() <= float_image.max() <= 1.0
>>>
Returns
np.ndarray | torch.Tensor

Converted image in the input container.

Notes
  • Floating inputs retain their dtype and values, including NumPy float16.
  • Uint8 values are divided by max_value into float32 without clipping.
  • This transform is often used as a preprocessing step before applying other transformations or feeding the image into a neural network.
See Also

FromFloat: The inverse operation, converting from float back to the original data type.