machinevisiontoolbox.Image.stretch

Image.stretch(max=1, range=None, clip=True)

Image normalisation

Parameters:
  • max (int, float, optional) – maximum value of output pixels, defaults to 1

  • range (array_like(2), optional) – range[0] is mapped to 0, range[1] is mapped to max

  • clip (bool, optional) – clip pixel values to interval [0, max], defaults to True

Returns:

Image with pixel values stretched to M across r

Return type:

Image

Returns a normalised image in which all pixel values are linearly mapped to the interval of 0.0 to max. That is, the minimum pixel value is mapped to 0 and the maximum pixel value is mapped to max.

If range is specified then range[0] is mapped to 0.0 and range[1] is mapped to max. If clip is False then pixels less than range[0] will be mapped to a negative value and pixels greater than range[1] will be mapped to a value greater than max.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> img.stretch().A
array([[0.   , 0.125, 0.25 ],
       [0.375, 0.5  , 0.625],
       [0.75 , 0.875, 1.   ]])
References:
  • Robotics, Vision & Control, Section 12.1, P. Corke, Springer 2011.