Image.window#
- Image.window(func: Callable[[...], Any], h: int | None = None, se: ndarray | None = None, border: str = 'reflect', bordervalue: int | float = 0, **kwargs: Any) Any[source]#
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 –
borderis not a valid optionTypeError –
funcnot callableValueError – single channel images only
- Returns:
transformed image
- Return type:
Returns an image where each pixel is the result of applying the function
functo a neighbourhood centred on the corresponding pixel in image. The return value offuncbecomes the corresponding pixel value.The neighbourhood is defined in two ways:
If
seis given then it is the the size of the structuring elementsewhich should have odd side lengths. The elements in the neighbourhood corresponding to non-zero elements inseare packed into a vector (in column order from top left) and passed to the specified callable functionfunc.If
seis None thenhis 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
funcmust be invoked once for every output pixel.
- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.5.3.
- Seealso: