【发布时间】:2023-03-06 12:17:01
【问题描述】:
【问题讨论】:
标签: python image-processing fft imagefilter gaussianblur
【问题讨论】:
标签: python image-processing fft imagefilter gaussianblur
要完成这个转换,你要先pad the image,然后用ifftshift将原点移动到左上角:
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)
请注意,此处的焊盘尺寸经过精心选择,以保留原点的正确位置,这在过滤中很重要。对于奇数大小的内核,原点位于中间像素。对于在中间没有像素的均匀大小的内核,原点是从真正中心向右下方的像素。在这两种情况下,此位置都是使用K.shape // 2 计算的。
【讨论】: