def kernel_impute(img, S):
F = pad2(img)
F.data[F.mask] = 0. # make sure its zero-filled!
img_w, img_h, img_ch = img.shape
Q = S
specF = np.fft.fft2(F.data.astype(float), axes=(0, 1))
specN = np.fft.fft2(1. - F.mask.astype(float), axes=(0, 1))
specQ = np.fft.fft2(Q[::-1, ::-1])
numer = np.real(np.fft.ifft2(specF * specQ[:, :, np.newaxis], axes=(0, 1)))
denom = np.real(np.fft.ifft2(specN * specQ[:, :, np.newaxis], axes=(0, 1)))
eps = 1e-15
fill = numer/(denom+eps)
fill = fill[-img_w:, -img_h:]
image = img.data.copy()
# img = img.copy()
image[img.mask] = fill[img.mask]
mask = np.zeros_like(img.mask, dtype=bool)
return np.ma.MaskedArray(data=image, mask=mask)
评论列表
文章目录