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 (
Kernelor ndarray, optional) – derivative kernel, defaults to Sobelmode (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, orfloat64for afloat64image, whatever the type of the input image, since a gradient can be negative and auint8result would clip every negative value to zero. With the default Sobel kernel, which is normalised, the gradients of auint8image 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 auint8image lost all of its negative gradients.Examples
>>> from machinevisiontoolbox import Image >>> img = Image.Read('monalisa.png', grey=True) >>> Iu, Iv = img.gradients()
References
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.5.1.3.
See also