comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » fitting mixed gaussians
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
fitting mixed gaussians [message #44140] Tue, 17 May 2005 11:22
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Hello,

I would like to employ a "mixed gaussian" fitting routine that fits not
just one peak in a distribution but rather fits any number of peaks.
According to my old Gonzales and Woods Image Processing book this
technique is used in Bayesian classifier - in the two class problem the
saddle of the two fitted curves is used as the point around which the
classes are separated. I just to segment simple grayscale images with it
usiing the histogram as the data to model.

Using GAUSSFIT or MPFIT it's very easy to fit one (the tallest) peak
shown in the example (see code example below.) But how the heck to fit
the second peak? I have scoured the internet and find much written
about it - but it is all in Greek. Really. Yikes.

Is it possible to make the curve fitting routines I have on hand to fit
two gaussian models?

Thanks,
Ben


******START HERE
PRO example_mixedgaussfit

n = 256.
x = Findgen(n)/(n-1)*(n-1)
y = 0.4*RANDOMN(seed, n)

; the coefficients are amplitude, center and width
a = [0.3, n/4., n/20. ]
b = [0.05, n-n/4., n/10.]

z1 = (x - a[1])/a[2]
z2 = (x - b[1])/b[2]

; start with random noise.
y = 0.02*RANDOMN(seed, n) > 0.0

;now add in the 'model' peaks
;the first gaussian the second gaussian
y = y + a[0]*exp(-z1^2/2) + b[0]*exp(-z2^2/2)

;rescale to 0-1 as if probability
y = y/MAX(y)

;use the built in gaussfit
;note that the highest peak is fit
r = gaussfit(x,y, c, nTERMS = 3)
plot, x, y, title = 'Mixed Gaussians'
oplot, x,r, thick = 3

XYOUTS, x[a[1]], y[a[1]]/4 , 'peak a', align = 0.5
XYOUTS, x[b[1]], y[b[1]]/4 , 'peak b', align = 0.5

END

******END HERE
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Looking for IDL code documentation standards
Next Topic: Re: ascii-template

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 15:23:54 PDT 2025

Total time taken to generate the page: 1.28571 seconds