简体   繁体   English

使用FFT删除图像中的一行

[英]Remove a line in image with FFT

I would like to remove vertical line from an image (an example). 我想从图像中删除垂直线(示例)。 I took a 2D FFT and try to apply a mask to suppress the line. 我进行了2D FFT,并尝试应用遮罩来抑制线条。 Nonethelesse the approch is not very efficient, because i lose an important part of information. 但是,此方法不是很有效,因为我丢失了重要的信息部分。 How can i improve the treatment of FFT data? 如何改善对FFT数据的处理? In FFT, how find the line? 在FFT中,如何找到线?

在此处输入图片说明

My piece of code : 我的代码:

import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage import data, img_as_float

Path_input = "C:\\Users\\yoyo\\Desktop\\"

imggray = img_as_float(data.astronaut())[:,:,0]*255 #opening image 
imggray[:,254:255] = 0 #force a vertical line
plt.imshow(imggray);plt.show()

imfft = np.fft.fft2(imggray)
mags = np.abs(np.fft.fftshift(imfft))
angles = np.angle(np.fft.fftshift(imfft))
visual = np.log(mags)
visual2 = (visual - visual.min()) / (visual.max() - visual.min())*255
plt.imshow(visual2);plt.show()

mask = io.imread(Path_input + 'mask_astro.png')[:,:,0]
mask = (mask < 100)
visual[mask] = np.mean(visual)

newmagsshift = np.exp(visual)
newffts = newmagsshift * np.exp(1j*angles)
newfft = np.fft.ifftshift(newffts)
imrev = np.fft.ifft2(newfft)
newim2 = np.abs(imrev).astype(np.float32)

plt.imshow(newim2);plt.show()

----- EDIT LATER ---- -----编辑之后----

My "real" image: 我的“真实”图片:

在此处输入图片说明

https://image.noelshack.com/fichiers/2018/36/5/1536312281-test.png https://image.noelshack.com/fichiers/2018/36/5/1536312281-test.png

Seems that width of that line is 1 pixel. 似乎那条线的宽度是1像素。

In this case you can get rid of line with horizontal median filter of size 3 (applied to narrow column) 在这种情况下,您可以使用大小为3的水平中值过滤器摆脱行(适用于窄列)

Edit 编辑
With real picture we can see horizontal defective rows. 使用真实图片,我们可以看到水平的缺陷行。

At first you can determine their Y-position, using edge-revealing filters like Sobel one. 首先,您可以使用像Sobel one这样的边缘显示滤镜确定其Y位置。

Then apply median filter with mostly vertical aperture only to bad regions (or some kind of interpolation, as @SilverMonkey noticed in comments). 然后将具有大部分垂直孔径的中值滤波器仅应用于不良区域(或某种插值,如@SilverMonkey在注释中注意到的)。

Example of quick-made OpenCV treatment with CV_MEDIAN filter size 11 x 3 applied twice with two ROI (region of interests) near y=110 and y=205. 快速制作的OpenCV处理示例,其CV_MEDIAN filter size 11 x 3两次,在y = 110和y = 205附近具有两个ROI(感兴趣区域)。 Note good compensation of the second defect, but the first one needs more work. 注意可以很好地补偿第二个缺陷,但是第一个缺陷需要做更多的工作。 Peculiarities are preserved. 特殊性得以保留。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM