3
$\begingroup$

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? enter image description here

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)');

Hp = im2double(imread('spec-mask.png'));
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: enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$ Sep 16, 2015 at 9:04
  • $\begingroup$ @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! $\endgroup$ Sep 16, 2015 at 11:25
  • $\begingroup$ Are you missing an ifftshift perhaps? I don't see it in the code but perhaps it will make a difference $\endgroup$ Sep 16, 2015 at 12:19
  • $\begingroup$ @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? $\endgroup$ Sep 17, 2015 at 6:34

1 Answer 1

2
$\begingroup$

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


PS. geometrikal - thanks for putting me on the right track!

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.