I am trying to get the big image from the smaller one (on the left). This is 15x15 kernel and I need to get the big image. How do I pad values into the array so that I get the big image? I am newbie. Explanation would be appreciated.
To accomplish this transformation, you want to first pad the image, and then use ifftshift
to move the origin to the top-left corner:
import numpy as np
K = np.zeros((15,15))
K[7,7] = 1 # not exactly the 15x15 kernel on the left, but similar
sz = (256, 256) # the output sizes
after_x = (sz[0] - K.shape[0])//2
before_x = sz[0] - K.shape[0] - after_x
after_y = (sz[1] - K.shape[1])//2
before_y = sz[1] - K.shape[1] - after_y
K = np.pad(K, ((before_x, after_x), (before_y, after_y)), 'constant')
K = np.fft.ifftshift(K)
Note that the pad sizes here are carefully chosen to preserve the correct location of the origin, which is important in filtering. For an odd-sized kernel, the origin is in the middle pixel. For an even-sized kernel, which has no pixel exactly in the middle, the origin is the pixel to the right and down from the true center. In both cases, this position is computed using K.shape // 2
.