Reputation: 3862
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?
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
Upvotes: 0
Views: 669
Reputation: 80187
Seems that width of that line is 1 pixel.
In this case you can get rid of line with horizontal median filter of size 3 (applied to narrow column)
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.
Then apply median filter with mostly vertical aperture only to bad regions (or some kind of interpolation, as @SilverMonkey noticed in comments).
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. Note good compensation of the second defect, but the first one needs more work. Peculiarities are preserved.
Upvotes: 3