machinevisiontoolbox.ImageSpatial.Kernel.Circle

static Kernel.Circle(radius, h=None, normalize=False, dtype='uint8')[source]

Circular structuring element

Parameters:
  • radius (scalar, array_like(2)) – radius of circular structuring element

  • h (int) – half-width of kernel

  • normalize (bool, optional) – normalize volume of kernel to one, defaults to False

  • dtype (str or NumPy dtype, optional) – data type for image, defaults to uint8

Returns:

circular kernel

Return type:

ndarray(2h+1, 2h+1)

Returns a circular kernel of radius radius pixels. Sometimes referred to as a tophat kernel. Values inside the circle are set to one, outside are set to zero.

If radius is a 2-element vector the result is an annulus of ones, and the two numbers are interpretted as inner and outer radii respectively.

The kernel is centred within a square array with side length given by \(2\mathtt{h} + 1\).

Example:

>>> from machinevisiontoolbox import Kernel
>>> Kernel.Circle(2)
array([[0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1],
       [0, 1, 1, 1, 0],
       [0, 0, 1, 0, 0]], dtype=uint8)
>>> Kernel.Circle([2, 3])
array([[0, 0, 0, 1, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 1, 0, 0, 0, 1, 0],
       [1, 1, 0, 0, 0, 1, 1],
       [0, 1, 0, 0, 0, 1, 0],
       [0, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 1, 0, 0, 0]], dtype=uint8)
References:
  • Robotics, Vision & Control for Python, Section 11.5.1.1, P. Corke, Springer 2023.

Seealso:

Box