python - FFT去除周期性噪声

标签 python image-processing fft

这是一个讨论很多的话题,但我恰好有一个问题尚未得到解答。 我的问题不是它本身的方法,而是它的适用性: 我的图像的 f(x,y) 代表可以是负数或正数的物理值。当我屏蔽与中值对应的峰值时,在应用逆 FFT 后,我得到一个复杂的图像。

如果 image != image,这接缝合乎逻辑 image != ifft(fft(image)),因此它很可能是复杂的结果?

因此,我采用了图像数组的绝对值,并得到了一个干净利落的图像。但是通过获取图像的 abs 我已经失去了负值!

我的代码很复杂,并使用多个图像来找到要遮盖的正确位置,因此我将分解为要点:

def everything(fft,fftImage,sizeOfField,shapeOfFFT):
max_x = []
max_y = []
median = np.median(fft)

threshold = 500
#correctLocalMax() holds several subfunctions that look for the propper max_x and max_y. This works fine and returns 2 lists max_x,max_Y that contain the coordiantes of the max's
max_x,max_y = correctLocalMax(iStart = 0,iStop = 30, jStart =0 , jStop = shapeOfFFT[1],threshold=threshold, max_x = max_x, max_y = max_y)

for i in range(len(max_x)):
    for k in range(sizeOfField):
        for l in range(sizeOfField):
            fftImage[max_x[i]+k][max_y[i]+l] = median

return(fftImage)

image, coverage, stdev = pickleOpener(dataDir,i)
field = getROI(image,area,i0,j0)

fftImage = np.fft.fft2(image)
fftImage = np.fft.fftshift(fftImage)

fft = np.fft.fft2(coverage)
fft = np.fft.fftshift(fft)

fftMod = everything(fft, fftImage, sizeOfField, shapeOfFFT)
imageBack = np.fft.ifft2(fftMod)
imageBack = np.abs(imageBack)
field = getROI(imageBack,area,i0,j0)

处理后我得到的图像是这样的: enter image description here 条纹图案是我想去掉的

enter image description here 这些是应用于 FFT 的掩码

enter image description here 条纹图案大部分被移除,但现在图像是纯正的!

您可以在评论中找到问题的正确解决方案!

最佳答案

您可以尝试两种不同的方法: 您要么先在原始值之间缩放图像,然后再重新缩放,有点像这样:

max_val = max(max(A))
min_val = min(min(A))
% normalize to [0,1]
image = norm(image)
% do your stuff here
% then rescale to original values
image = min_val + (max_val - min_val).*image / (max_val - min_val)

另一种方法是首先保存负值。 虽然我建议检查它们是否在您的函数调用期间发生了变化,以避免恢复您的噪音

关于python - FFT去除周期性噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40105777/

相关文章:

python - 我该如何修改这段代码,以便它能正确打印图案?

python - 如何在django查询中获取每个人最近添加的记录

python - 在Python中模拟SHL和SHR ASM指令

opencv - 使用opencv在c++中进行简单拼接

Verilog : Error using nested for loop 中的 FFT 实现

python - 如何在 python 中获取通过 AJAX 发布的值数组?

java - 如何在java中获取图像每个像素的灰度级

iphone - 从原始 RGBA 数据创建 UIImage

python - 生成准周期信号

matlab - 在我的傅里叶逆变换中出现尖峰