summaryrefslogtreecommitdiff
path: root/stripeeraser.m
blob: c0d48a639b4d0ab2cd26a5b927159497d7c3b801 (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
function [img_cleaned,img_fourier,img_mask]=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.

img_fourier=fftshift(fft2(img)); % move to Fourier space
max1=max(abs(img_fourier(:)));
threshold=max1*(10^(-threshold_power));
[Ny, Nx] = size (img); % image size
[x,y]=meshgrid(1:Nx,1:Ny); % matrix xy coordinates

d=sqrt((x-(Nx+1)/2).^2+(y-(Ny+1)/2).^2); % distance from center of the image
% For high enough frequency components
% suppress this frequency components which are mostly stripes.
% But leave untouched small sharp features of the beam 
% since they are spectrally weak
img_mask = d>radius & abs(img_fourier)>threshold;

img_fourier(img_mask)=img_fourier(img_mask).*exp(-(d(img_mask)/radius).^2);

img_cleaned = abs( ifft2(ifftshift(img_fourier)) );