machinevisiontoolbox.Image.astype
- Image.astype(dtype: DType)[source]
Cast image datatype
- Parameters:
dtype (str) – Numpy data type
- Returns:
image
- Return type:
Image
Create a new image, same size as input image, with pixels of a different datatype. Values are retained, only the datatype is changed.
Example:
>>> from machinevisiontoolbox import Image >>> img = Image.Random(3) >>> img.image array([[175, 25, 55], [ 61, 140, 164], [ 58, 92, 203]], dtype=uint8) >>> img.astype('float').image array([[175., 25., 55.], [ 61., 140., 164.], [ 58., 92., 203.]]) >>> img = Image.Random(3, dtype='float') >>> img.image array([[0.6275, 0.8877, 0.1883], [0.8209, 0.8905, 0.4252], [0.5095, 0.3612, 0.3965]]) >>> img.astype('uint8').image array([[0, 0, 0], [0, 0, 0], [0, 0, 0]], dtype=uint8)
- Seealso: