Image.to_float#
- Image.to_float(floatclass: DTypeLike = 'float32') ndarray[source][source]#
Image as float NumPy array
- Parameters:
floatclass (str or NumPy dtype) – ‘single’, ‘double’, ‘float32’ [default], ‘float64’
- Returns:
NumPy array with floating point values
- Return type:
ndarray(H,W) or ndarray(H,W,P)
Return a NumPy array with pixels converted to the floating point class
floatclassand the values span the range 0 to 1. For the case where the input image is:an integer class, the pixel values are scaled from an input range spanning zero to the maximum positive value of the integer class to [0.0, 1.0]
a floating class, the pixels are cast to change type but not their value.
boolean class, False is mapped to 0.0 and True is mapped to 1.0.
Example:
>>> from machinevisiontoolbox import Image >>> img = Image([[50, 100], [150, 200]]) >>> img Image(size=(2, 2), dtype=uint8) >>> img.to_float() array([[0.1961, 0.3922], [0.5882, 0.7843]], dtype=float32) >>> img = Image([[0.0, 0.3], [0.5, 1.0]]) >>> img Image(size=(2, 2), dtype=float32) >>> img.to_float('float64') array([[0. , 0.3], [0.5, 1. ]]) >>> img = Image([[False, True], [True, False]]) >>> img.to_float() array([[0., 1.], [1., 0.]], dtype=float32)
Note
Works for greyscale or color (arbitrary number of planes) image
Deprecated since version 2.0.0: Use
array_asinstead.