Image.to#
- Image.to(dtype: DTypeLike) Image[source][source]#
Convert image datatype
- Parameters:
dtype (str or NumPy dtype) – Numpy data type
- Returns:
image
- Return type:
Create a new image, same size as input image, with pixels of a different datatype. Integer values are scaled according to the maximum value of the datatype, floating values are in the range 0.0 to 1.0.
Example:
>>> from machinevisiontoolbox import Image >>> img = Image.Random(size=3) >>> img.print() 173 100 11 100 58 224 144 79 22 >>> img.to('float').print() 0.68 0.39 0.04 0.39 0.23 0.88 0.56 0.31 0.09 >>> img = Image.Random(size=3, dtype='float') >>> img.print() 0.92 0.29 0.98 0.59 0.42 0.78 0.05 0.31 0.81 >>> img.to('uint8').print() 234 74 250 150 108 200 13 78 207