machinevisiontoolbox.Image.astype
- Image.astype(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([[253, 0, 221], [ 19, 252, 90], [ 36, 228, 151]], dtype=uint8) >>> img.astype('float').image array([[253., 0., 221.], [ 19., 252., 90.], [ 36., 228., 151.]]) >>> img = Image.Random(3, dtype='float') >>> img.image array([[0.4992, 0.5207, 0.3147], [0.7067, 0.9963, 0.2233], [0.6516, 0.3508, 0.9426]]) >>> img.astype('uint8').image array([[0, 0, 0], [0, 0, 0], [0, 0, 0]], dtype=uint8)
- Seealso: