[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gauss2DFit question



I'm trying to use the library routine GAUSS2DFIT to fit some smooth,
blobby functions.  My experience so far has been ... ah ... suboptimal.
It does not converge quickly or well.

Example (modified from the example in the manual):

PRO TEST_GAUSS2D

nx = 128                        ;x-dimension of array
ny = 100                        ;y-dimension of array
x  = FINDGEN(nx)                ;Create x-coordinates
y  = FINDGEN(ny)                ;Create y-coordinates
xx = x # REPLICATE(1.0, ny)     ;Create 2-D x-coordinates
yy = REPLICATE(1.0, nx) # y     ;Create 2-D y-coordinates

;    Offs Scale X width  Y width  X cen   Y cen   Rotation
;    A0   A1    a        b        h       k       tilt
a = [5.0, 10.0, nx/6.0,  ny/10.0, nx/2.0, 0.6*ny, !PI/4.0] ;Parameters

xr   = (xx - a[4])*COS(a[6]) - (yy - a[4])*SIN(a[6]) ;Rotate x
yr   = (xx - a[4])*SIN(a[6]) + (yy - a[4])*COS(a[6]) ;Rotate y
z    = a[0] + a[1]*EXP(-((xr/a[2])^2 + (yr/a[3])^2)/2) ;Compute gaussian
z    = z + RANDOMN(seed, nx, ny)                    ;Add random noise
yfit = GAUSS2DFIT(z, b, /TILT)                      ;Fit the function

PRINT,'Should be:', STRING(a, FORMAT='(6f10.4)')
PRINT,'Is:      :', STRING(b, FORMAT='(6f10.4)')

!P.MULTI = [0, 2, 1, 0, 0]
CONTOUR, z,    x, y
CONTOUR, yfit, x, y

END

Including the noise (RANDOMN line) produces unpredictable bad results.
Commenting that line out produces reproduceable bad results.

Does anyone have a more robust routine for fitting a 2-D Gaussian (with
rotation)?

Thanks, Ken