summaryrefslogtreecommitdiff
path: root/striperemoval.m
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2014-11-25 14:41:05 -0500
committerEugeniy Mikhailov <evgmik@gmail.com>2014-11-25 14:41:05 -0500
commit35d90f6d9ceb7fe9ac6a592a9ea4126f27951f3f (patch)
tree03aa63cd3b4b0e201a709e0af89b40e926fa8ffe /striperemoval.m
parent1c9897e82b9dbecb0be7a93c3a06ef9a3cefe821 (diff)
downloadbeam_profiler-35d90f6d9ceb7fe9ac6a592a9ea4126f27951f3f.tar.gz
beam_profiler-35d90f6d9ceb7fe9ac6a592a9ea4126f27951f3f.zip
added alternative stripe removal function
Diffstat (limited to 'striperemoval.m')
-rw-r--r--striperemoval.m54
1 files changed, 54 insertions, 0 deletions
diff --git a/striperemoval.m b/striperemoval.m
new file mode 100644
index 0000000..7563bf0
--- /dev/null
+++ b/striperemoval.m
@@ -0,0 +1,54 @@
+function [img_cleaned]=striperemoval(img, varargin)
+% Cleans an image from the stripes produced by interference fringes.
+% img - image with stripes to be removed
+% varargin - not used, it is here for compatibility
+% By Eugeniy E. Mikhailov 2014/11/25
+%
+% be aware of "slow" spatial stripes their Fourier components will overlap with Gaussian.
+% Such parallel fringes appears like strong isolated peaks in the Fourier transformed image.
+% What is even nice they appear symmetrical with respect to origin but not symmetrical to
+% fold
+%
+% ^
+% |
+% * |
+% |
+% oOo
+% -------------O0O-------------->
+% oOo <- gaussian beam fft
+% |
+% | * <- stripe fft peak
+% |
+%
+%
+% so it easy to clean them, especially if their spatial frequency is high.
+%
+
+img_fourier=fftshift(fft2(img)); % move to Fourier space
+
+imgfa= abs(img_fourier); % amplitude of Fourier components
+imgfa= imgfa/max(imgfa(:)); % normalized amplitudes
+
+[Ny, Nx] = size (img); % image size
+
+mask = img_fourier.*0;
+for xi = 1:Nx
+ % strictly speaking one of dimensions can be only half sampled due to symmetry of the mask
+ for yi = 1:Ny
+ xr = Nx - xi + 1; % reflected x
+ yr = Ny - yi + 1; % reflected y
+ mt = imgfa( yi, xi ); % test point
+ ms = imgfa( yr, xr ); % symmetrical point with respect to origin
+ mr = imgfa( yi, xr ); % symmetrical point with respect to Y axis (right)
+ md = imgfa( yr, xi ); % symmetrical point with respect to Y axis (down)
+
+ m = ( mt + ms ) - ( mr + md ); % high value to the points shown at figure
+ m = m/max([mt, ms, mr, md]);
+ mask(yi,xi) = m;
+ end
+end
+
+threshold = max(mask(:))/2;
+mask = mask < threshold; % points due to stripes need to be removed
+
+img_cleaned = abs( ifft2(ifftshift(img_fourier.*mask)) );