;----------------------------------------------------------------- ; g_smooth.pro ; ; 06/2001 by Andreas Reigber ;------------------------------------------------------------------ ; Gaussian smooth for float/complex arrays implemented in the ; spectral domain. Boxsizes adjusted for achieving similar ; smoothing strength as with normal smooth. ; ; Usage: ; res = g_smooth(arr,size) ; ; arr = array to be smoothed ; size = box size for smoothing ; ; Keywords: ; /convolution : Use time domain convolution. Can be faster ; for small box sizes. ; /dirty : Very fast but uses a really dirty approximation. ;------------------------------------------------------------------ ; This software has been released under the terms of the GNU Public ; license. See http://www.gnu.org/copyleft/gpl.html for details. ;------------------------------------------------------------------ function g_smooth,_arr,sigma,CONVOLUTION=convolution,DIRTY=dirty on_error,2 s=size(_arr) if s[0] ne 2 then message,'ERROR: Only for two-dimensional arrays' if s[3] ne 4 and s[3] ne 5 and s[3] ne 6 and s[3] ne 9 then $ message,'ERROR: Only for float or complex arrays' xlen=s[1] ylen=s[2] if not keyword_set(convolution) and not keyword_set(dirty) then begin s2 = sigma*1.3 omega_x = shift(findgen(xlen)-xlen/2,xlen/2)/xlen fgaus_x = exp( - (s2^2 * (omega_x)^2)) omega_y = shift(findgen(ylen)-ylen/2,ylen/2)/ylen fgaus_y = exp( - (s2^2 * (omega_y)^2)) sfak = cmul_arr(fgaus_x,fgaus_y) farr = fft(_arr,-1) farr = fft(farr * sfak,1) if s[3] eq 4 or s[3] eq 5 then farr = abs(farr) endif if keyword_set(convolution) then begin gg = gauss(2*sigma,sigma/3.5,sigma) gg2 = cmul_arr(gg,gg) farr=convol(_arr,gg2,/center,/edge_truncate) endif if keyword_set(dirty) then begin s2 = sigma/2.0 farr=smooth(smooth(smooth(_arr,s2,/ed),s2,/ed),s2,/ed) endif return,farr end