# Remove stripes from image using FFT

I try to remove from an image all stripes with slope between 110° and 120° (Fig. 1a) and my first idea was to filter my image in the frequency domain.

As far as I remembered, the spectrum of those stripes should occupy a pie segment between 20-30° (i.e. the original slope - 90°), but to be sure I prepared an artificial black-and-white image with similar pattern (Fig. 2a). It seemed my speculations were correct (Fig. 2b).

Now, I tried to create a mask and simply "cut off" part of the spectrum to supress high frequencies associated with 10-120° stripes.

Only after several trials I came across a mask (Fig. 3a) which satisfies my needs to some degree (Fig. 4). However, I can't figure the relation between this empirically-obtained mask and the spectrum.

Could someone give me some advice where are flaws in my code or in my reasoning? Here's the MATLAB code I've used for filtering:

f = imread('img/crystal-grain_sample.jpg');
figure, imshow(f); title('f');

m = max(size(f));
P = 2^nextpow2(2*m);
PQ = [P, P];

Fp = fft2(f, PQ(1), PQ(2));

Fc = fftshift(Fp);
Fc_abs = abs(Fc);
Fs_log = log(1+Fc_abs);

%figure; imshow(Fc_abs, []); title('Fc (abs)');
%figure; imshow(Fs_log, []); title('Fs (log)');

Gp = Hp .* Fp;
gp = real(ifft2(Gp));
gpc1 = gp(1:size(f,1), 1:size(f,2));
figure; imshow(gpc1, []); title('g');


And here's the original image: • Can you show the output of the mask in 3b? It only cuts out a tiny part of the very high frequencies. Also, the mask is not symmetric so the output of the inverse DFT will have imaginary parts. – geometrikal Sep 16 '15 at 9:04
• @geometrikal: My bad, I forgot that I make the mask symmetric in MATLAB. I've updated the mask, added the result and posted a MWE. Good that you've pointed it out! – Paweł Kłeczek Sep 16 '15 at 11:25
• Are you missing an ifftshift perhaps? I don't see it in the code but perhaps it will make a difference – geometrikal Sep 16 '15 at 12:19
• @geometrikal: Exactly, that was the case. I designed my mask on a shifted image of the spectrum but in MATLAB I multipled it with an unshifted spectrum. Maybe you could post it as an answer so that I can accept it? – Paweł Kłeczek Sep 17 '15 at 6:34

The problem was I've masked the shifted spectrum. After I've used ifftshift on my mask, I obtained the desired effect.