machinevisiontoolbox.Image.like
- Image.like(value, maxint=None)[source]
Convert value to the same type as image
- Parameters:
value (scalar, ndarray) – scalar or NumPy array
maxint (int, optional) – maximum integer value for an integer image, defaults to maximum positive value of the class
- Raises:
ValueError – [description]
- Returns:
converted value
- Return type:
NumPy type
The value, scalar or integer, is converted to the same type as the image. The result is optionally rescaled and cast:
Float to float: values are cast
Float to int: values in the interval [0, 1] are scaled to the interval [0,
maxint
] and then castInt to float: values in the interval [0,
maxint
] are scaled to the interval [0, 1] and then cast.Int to int: values are scaled and cast.
Warning
For integer to integer conversion, integer values greater than the maximum value of the destination class are wrapped not clipped.
Example:
>>> from machinevisiontoolbox import Image >>> img = Image.Read('flowers1.png') >>> img.like(0.5) 127