convolution#
- datacheese.convolution.conv2d(img, kernel, stride=(1, 1), padding=0, fill=0)#
Perform 2D convolution operation over image array using kernel.
- Parameters:
img (numpy.ndarray) – 2D image array to perform convolution on.
kernel (numpy.ndarray) – 2D kernel array.
stride (tuple) – 2-value tuple representing stride in each dimension.
padding (int) – Number of layers of padding to add around image.
fill (float) – Fill value to use when padding.
- Returns:
out – 2D output array.
- Return type:
numpy.nadarray
Examples
>>> import numpy as np >>> from datacheese.convolution import conv2d
Define image and kernel:
>>> img = np.array( ... [ ... [5, -2, 8, 1], ... [3, -1, 0, -2], ... [-9, 2, 8, -3], ... [4, 7, -3, 4], ... ] ... ) >>> kernel = np.array( ... [ ... [-2, 3], ... [0, 1], ... ] ... )
Perform convolution of kernel over image using strides of 2 in both dimensions:
>>> conv2d(img, kernel, stride=(2, 2)) array([[-17, -15], [ 31, -21]])