viqa.utils.correlate_convolve_abs

viqa.utils.correlate_convolve_abs(img, kernel, mode='correlate', border_mode='constant', value=0)[source]

Correlates or convolves a numpy array with a kernel.

Parameters:
  • img (np.ndarray) – Input image

  • kernel (np.ndarray) – Kernel

  • mode (str, default='correlate') – ‘correlate’ or ‘convolve’

  • border_mode (str, default='constant') –

    ‘constant’, ‘reflect’, ‘nearest’, ‘mirror’ or ‘wrap’

    See also

    See NumPy documentation for numpy.pad().

  • value (int, optional, default=0) – Value for constant border mode

Returns:

res – Convolved result as numpy array

Return type:

np.ndarray

Raises:

ValueError – If border_mode is not supported If number of dimensions is not supported

Notes

Correlates or convolves a numpy array with a kernel in the form \(\operatorname{mean}(\lvert \pmb{I} \cdot \mathcal{K} \rvert)\) with \(\pmb{I}\) denoting the image and \(\mathcal{K}\) denoting the Kernel. Works in 2D and 3D.

Examples

>>> import numpy as np
>>> from viqa import kernels
>>> img = np.random.rand(128, 128)
>>> kernel = kernels.sobel_kernel_2d_x()
>>> res = correlate_convolve_abs(
...         img,
...         kernel,
...         mode="correlate",
...         border_mode="constant",
...         value=0
... )