def fwd_filter(img, S):
img_w, img_h, ch = img.shape
F = pad2(img)
F.data[F.mask] = 0. # make sure its zero-filled!
# Forward transform
specF = np.fft.fft2(F.data.astype(float), axes=(0, 1))
specN = np.fft.fft2(1. - F.mask.astype(float), axes=(0, 1))
specS = np.fft.fft2(S[::-1, ::-1])
out = np.real(np.fft.ifft2(specF * specS[:, :, np.newaxis], axes=(0, 1)))
norm = np.real(np.fft.ifft2(specN * specS[:, :, np.newaxis], axes=(0, 1)))
eps = 1e-15
norm = np.maximum(norm, eps)
out /= norm
out = out[-img_w:, -img_h:]
out[img.mask] = 0.
return np.ma.MaskedArray(data=out, mask=img.mask)
评论列表
文章目录