summaryrefslogtreecommitdiff
path: root/stripeeraser.m
blob: 5d472fe868cc3292a10c0cf4b6e131d05e2a5a7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [img_cleaned,imfourier]=stripeeraser(img,radius,threshold_power)
% Cleans an image from the stripes produced by interference fringes.
% Such parallel fringes appears like a strong peak in the Fourier transformed image.
% so it easy to clean them, especially if their spatial frequency is high.
%
% We will clean strong frequency components higher them max*10^(-threshold_power)
% by suppressing them with exponential factor which is increases with distance
% from the center i.e. zero spatial frequencies.

immask=fftshift(fft2(img)); % move to Fourier space
max1=max(immask(:));
for x=1:640
    for y=1:480
        d=sqrt((x-320)^2+(y-240)^2);
        if d>radius                                                        
		% for high enough frequency components
		%The filter works like a neutral density filter. 
            if abs(immask(y,x))>max1*(10^(-threshold_power));                       
		    % Suppress this frequency components which are mostly stripes
		    % but leave untouched small sharp features of the beam 
		    % since they are spectrally weak
		    immask(y,x)=immask(y,x)*exp(-(d/radius)^2);
            end;
        end;
    end;
end;
imfourier=immask;
img_cleaned=ifft2(ifftshift(immask));