Image.gradients#

Image.gradients(K: Kernel | ndarray | None = None, mode: str = 'same', border: str = 'reflect', bordervalue: int | float = 0) → tuple[Any, Any][source]#

Compute horizontal and vertical gradients

Parameters:
  • K (Kernel or ndarray, optional) – derivative kernel, defaults to Sobel

  • mode (str, optional) – option for convolution, see convolve, defaults to ‘same’

  • border (str, optional) – option for boundary handling, see convolve, defaults to ‘reflect’

  • bordervalue (scalar, optional) – padding value, , see convolve, defaults to 0

Returns:

horizontal and vertical gradient images

Return type:

2-tuple of Image

Compute horizontal and vertical gradient images.

The gradient images are float32, or float64 for a float64 image, whatever the type of the input image, since a gradient can be negative and a uint8 result would clip every negative value to zero. With the default Sobel kernel, which is normalised, the gradients of a uint8 image lie between -127.5 and 127.5.

Changed in version 2.5.0: The gradients of an integer image are float32. They were the datatype of the image, so a uint8 image lost all of its negative gradients.

Examples

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('monalisa.png', grey=True)
>>> Iu, Iv = img.gradients()

References

See also

Kernel