去除条纹的一种传统方法是对频域中的违规频率应用掩模。
像这样的:输入图像 -> dft -> 应用蒙版 -> idft -> 输出图像
opencv文档中有一篇关于此类分析的文章:
https://docs.opencv.org/4.x/d8/d01/tutorial_discrete_fourier_transform.html
不幸的是,我没有可用的 C/C++ 示例,但它应该没有太大不同,因为 opencv 库提供了 dft 和 idft 函数。
Python中mask在频域的应用示例
import cv2
import numpy as np
from matplotlib import pyplot as plt
img_input = cv2.imread('beans.png', cv2.IMREAD_GRAYSCALE)
img = img_input.copy()
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
h, w = fshift.shape
spectrum_input = 20*np.log(np.abs(fshift))
for j in range(w//2 - 4):
fshift[h//2][j] = 0.0
for j in range(w//2 + 5,w):
fshift[h//2][j] = 0.0
f = np.fft.ifftshift(fshift)
img = np.fft.ifft2(f)
img = np.abs(img)
img = img.astype(np.uint8)
spectrum = 20*np.log(np.abs(fshift))
fig, axs = plt.subplots(2, 2)
axs[0,0].imshow(img_input, cmap = 'gray')
axs[0,1].imshow(spectrum_input, cmap = 'gray')
axs[1,0].imshow(img, cmap = 'gray')
axs[1,1].imshow(spectrum, cmap = 'gray')
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152 次 |
| 最近记录: |