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. Nonethelesse the approch is not very efficient, because i lose an important part of information. How can i improve the treatment of FFT data? In FFT, how find the line?

enter image description here

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

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

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)


---- EDIT LATER ----

My "real" image with darkest parts that i have to maintain and stripes of noise.

enter image description here

and you can download here : https://image.noelshack.com/fichiers/2018/36/5/1536312281-test.png

  • $\begingroup$ why would you try to do that with an FFT? Your stripe has all frequencies in horizontal direction (it's effectively an impulse), and thus is not very "located" in frequency domain. However, it's very much precisely located in spatial domain. So, going through a frequency domain seems like a … losing move? $\endgroup$ Sep 7, 2018 at 11:45
  • $\begingroup$ in reality i think i will apply that with wavelet approach to specify my direction $\endgroup$ Sep 7, 2018 at 11:57
  • 1
    $\begingroup$ Why? This is a spatial problem. Solve it spatially. You already have the problem as isolated as you could have it in the spatial domain. Every transform you can do can only make the problem harder. Engineering is not just throwing any solution at a problem – it's understanding what needs to be done and doing exactly that. $\endgroup$ Sep 7, 2018 at 12:31
  • $\begingroup$ osapublishing.org/oe/abstract.cfm?uri=oe-17-10-8567 It is an approach well known in X ray imaging ;) $\endgroup$ Sep 7, 2018 at 12:43
  • 1
    $\begingroup$ That's completely different from your problem. The text you link to refers to multiple parallel stripes of unknown locations. That's significant energy at a single vertical frequency and with unknown locality. So, there the "detour" through a frequency domain makes sense. Not so much for you, here. $\endgroup$ Sep 7, 2018 at 14:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.