machinevisiontoolbox.Image.window
- Image.window(func, h=None, se=None, border='reflect', bordervalue=0, **kwargs)
Generalized spatial operator
- Parameters:
func (callable) – function applied to window
h (int, optional) – half width of structuring element
se (ndarray(N,M), optional) – structuring element
border (str, optional) – option for boundary handling, see
convolve
, defaults to ‘reflect’bordervalue (scalar, optional) – padding value, defaults to 0
- Raises:
ValueError –
border
is not a valid optionTypeError –
func
not callableValueError – single channel images only
- Returns:
transformed image
- Return type:
Image
Returns an image where each pixel is the result of applying the function
func
to a neighbourhood centred on the corresponding pixel in image. The return value offunc
becomes the corresponding pixel value.The neighbourhood is defined in two ways:
If
se
is given then it is the the size of the structuring elementse
which should have odd side lengths. The elements in the neighbourhood corresponding to non-zero elements inse
are packed into a vector (in column order from top left) and passed to the specified callable functionfunc
.If
se
is None thenh
is the half width of a \(w \times w\) square structuring element of ones, where \(w =2h+1\).
Example:
>>> from machinevisiontoolbox import Image >>> import numpy as np >>> img = Image.Read('monalisa.png', grey=True) >>> out = img.window(np.median, h=3)
- Note:
The structuring element should have an odd side length.
Is slow since the function
func
must be invoked once for every output pixel.
- References:
Robotics, Vision & Control for Python, Section 11.5.3, P. Corke, Springer 2023.
- Seealso: