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

Home » Public Forums » archive » Curve Fitting Question
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
Curve Fitting Question [message #1309] Tue, 14 September 1993 11:01 Go to next message
ftdwh is currently offline  ftdwh
Messages: 1
Registered: September 1993
Junior Member
The question I have is how to properly use the curvefit routine to fit a
function that I am defining. It is as follows:

mclat = A1 + A2*cos(mlt + A3) + A4*cos(2*mlt + 2*A5) + A6*cos(3*mlt + 3*A7)

where mclat is the magnetic co-latitude, mlt is an angular representation of
the magnetic local time.(This is a Fourier fit)

I have in my data set the mclat and mlt, but I want to find the coefficients
A1-A7. Can I do this using the fitting routine in IDL? If I can, what are the
steps I need to follow? (As with most manuals they seem to be written for
somebody who already knows what they are doing. Along that train of thought
can any body recommend a book that might help those of us not fully
knowledgable in IDL)

David Hembroff
Geophysical Institute
University of Alaska Fairbanks
"I R A Grad Student"
Re: Curve Fitting Question [message #82001 is a reply to message #1309] Tue, 13 November 2012 15:24 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mark Piper writes:

> Coincidentally, we're adding an IMAGE_THRESHOLD function in 8.2.2 that implements Otsu's method among other automatic thresholding techniques.

Yes, this Otsu's thresholding function works great. It
didn't have quite as many features as I would have liked,
so I stole the main ideas and wrote up a similar program
that is working very, very well with the data sets I
am working with today. It even picks reasonable
thresholds when the dividing line between pixel
populations is not totally straightforward. Thanks
for bringing it to my attention.

You can find my version of the program here:

http://www.idlcoyote.com/programs/cgotsu_threshold.pro

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82006 is a reply to message #1309] Tue, 13 November 2012 08:31 Go to previous messageGo to next message
Mark Piper is currently offline  Mark Piper
Messages: 198
Registered: December 2009
Senior Member
On Monday, November 12, 2012 5:23:53 PM UTC-7, Gianguido Cianci wrote:
> How about Otsu's method? Meant for images but works for any set of numbers.
>
>
>
> http://www.cis.rit.edu/~cnspci/media/software/otsu_threshold .pro
>
>
>
> If your numbers aren't integers, I'd multiply by 1000, round, run otsu, divide by 1000. That's assuming 3 sig figs are enough...

Coincidentally, we're adding an IMAGE_THRESHOLD function in 8.2.2 that implements Otsu's method among other automatic thresholding techniques.

mp
Re: Curve Fitting Question [message #82016 is a reply to message #1309] Mon, 12 November 2012 19:40 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
ben.bighair writes:

> Would this work? It's a bit dated and never ran very fast, but it worked well for me.
>
> https://groups.google.com/d/topic/comp.lang.idl-pvwave/XlS5x dTmKPI/discussion

My goodness! We are going to have a BCS-like play-off
tomorrow at work. :-)

Thanks!

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82018 is a reply to message #1309] Mon, 12 November 2012 18:47 Go to previous messageGo to next message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On Monday, November 12, 2012 5:56:03 PM UTC-5, Coyote wrote:
> Folks,
>
>
>
> I have a data set with two more or less Gaussian peaks in its histogram. I am not overly concerned with the shape of the peaks, or even what their maximum values are. Rather, I am interested in how I might separate these two populations by picking an appropriate threshold between them. Visually, the separation is quite clear, but it appears in a somewhat different location with each data set, thus the need for a programmatic solution.
>
>
>
> Although I don't yet know how to do this, it occurs to me that I might be able to use Craig's MPFit program to fit some kind of double Gaussian to the data and look for the low point between the peaks. If anyone knows how to do this, I would be most grateful for pointers. Or, failing that, I would be interested in other IDL solutions to this problem. Thanks!
>

Hi David,

Would this work? It's a bit dated and never ran very fast, but it worked well for me.

https://groups.google.com/d/topic/comp.lang.idl-pvwave/XlS5x dTmKPI/discussion

Cheers,
Ben
Re: Curve Fitting Question [message #82019 is a reply to message #1309] Mon, 12 November 2012 17:23 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt writes:

> How noisy are the peak and non-peak regions of your histogram in the potential worst case? If the noise in non-peak regions can never be as high as the peaks, I probably wouldn't fit it. I would probably walk in from the left and right sides one bin at a time until you find a local max in each case.

Walking to a local minimum *might* work. I can see it would
work in some cases. I might have too few pixels in some
cases to avoid minimums in areas that should be in the
same group. I probably could look for a minimum of
some specified "width" as I walked. I'll give it a try.

Thanks!

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82020 is a reply to message #1309] Mon, 12 November 2012 17:18 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gianguido Cianci writes:

> How about Otsu's method? Meant for images but works for any set of numbers.
>
> http://www.cis.rit.edu/~cnspci/media/software/otsu_threshold .pro
>
> If your numbers aren't integers, I'd multiply by 1000, round, run otsu, divide by 1000. That's assuming 3 sig figs are enough...

Oh, that looks promising! I'll let you know. Thanks!

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82022 is a reply to message #1309] Mon, 12 November 2012 15:51 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Monday, November 12, 2012 5:56:03 PM UTC-5, Coyote wrote:
> Folks,
>
>
>
> I have a data set with two more or less Gaussian peaks in its histogram. I am not overly concerned with the shape of the peaks, or even what their maximum values are. Rather, I am interested in how I might separate these two populations by picking an appropriate threshold between them. Visually, the separation is quite clear, but it appears in a somewhat different location with each data set, thus the need for a programmatic solution.
>
>
>
> Although I don't yet know how to do this, it occurs to me that I might be able to use Craig's MPFit program to fit some kind of double Gaussian to the data and look for the low point between the peaks. If anyone knows how to do this, I would be most grateful for pointers. Or, failing that, I would be interested in other IDL solutions to this problem. Thanks!

How noisy are the peak and non-peak regions of your histogram in the potential worst case? If the noise in non-peak regions can never be as high as the peaks, I probably wouldn't fit it. I would probably walk in from the left and right sides one bin at a time until you find a local max in each case.

Craig
Re: Curve Fitting Question [message #82095 is a reply to message #82001] Wed, 14 November 2012 06:22 Go to previous messageGo to next message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
Holy bytescale Batman!

Forget the Physics Nobel Prize: when your name is burried in the header of a program by THE David Fanning, then, you have arrived! :-) No seriously.

Btw, I have a super clumsy version of Otsu that estimates local thresholds. It runs like molasses on a cold day in January.

I loop in x and y with a given step and consider a box of size L around x,y. I then run Otsu on that box. For all the values of x,y that I skipped I proceed as follows:

Because they don't teach interpolation at stupid school, I start with the subarray with the threholds I calculated [nx/step, ny/step]). I then use congrid to enlarge the subarray with the thresholds to the original image size [nx,ny]. Kinda works, I am ashamed to say.

If you wanted to get a local Otsu Threshold for each pixel how would you go about it? I was thinking it would be nice to calculate the local thresholds for a set of random points in the image, and then interpolate those. No idea how to proceed. INTERPOL? INTERPOLATE? ahhh!

Infact, you could then start chosing the points at not-so-random (more points where there is more info in the image, say).

Thoughts?

Gianguido

On Tuesday, November 13, 2012 5:24:20 PM UTC-6, David Fanning wrote:
>
> Yes, this Otsu's thresholding function works great. It
>
> didn't have quite as many features as I would have liked,
>
> so I stole the main ideas and wrote up a similar program
>
> that is working very, very well with the data sets I
>
> am working with today. It even picks reasonable
>
> thresholds when the dividing line between pixel
>
> populations is not totally straightforward. Thanks
>
> for bringing it to my attention.
>
>
>
> You can find my version of the program here:
>
>
>
> http://www.idlcoyote.com/programs/cgotsu_threshold.pro
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82110 is a reply to message #1309] Tue, 20 November 2012 06:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Hold off on this a minute. I've been using my version
> of the OTSU_THRESHOLD program for a week now, and I've
> been seeing some strange results. The only thing I did
> in my program was to beef up the keywords and error handling
> for the histogram itself. I didn't change the underlying
> code for OTSU_THRESHOLD.
>
> In fact, just to confirm this, I've now gone back and
> used the VERY same variable names, etc. But, I seem
> to be getting different slightly different results with
> the two programs.
>
> I am trying to track this down now. In fact, I'm using the
> newsgroup in EXACTLY the way Helder describes this morning!
>
> Here is what just occurred to me. One of the things I am
> VERY particular about (long experience, probably) is matching
> the data type of the BINSIZE keyword with the data type of
> the data going into the histogram. The OTSU_THRESHOLD program
> I was using as a model didn't do this. I wonder if this is
> the source of the difference. Back soon! :-)

Humm. There is always something strange going on with Histogram!

The difference in our two programs is that I set the MIN and MAX
keywords on the Histogram call to the minimum and maximum
of the data. OTSU_THRESHOLD doesn't do this. As a result the
output min and max for their histogram of byte data is 0 to 255.
Mine is 1 to 50. If I use the MIN and MAX keywords to set the
histogram range to 0 to 255, my results are identical.

I'm going to have to think about this. I think OTSU_THRESHOLD has
been written *assuming* byte data is coming in. I can't always
be so trusting of the data I work with. So...humm. Any ideas?

I would have thought the OTSU threshold method would work for ANY
bimodal population of values, assuming you could calculate
a histogram.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Curve Fitting Question [message #82112 is a reply to message #82001] Tue, 20 November 2012 06:22 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Yes, this Otsu's thresholding function works great. It
> didn't have quite as many features as I would have liked,
> so I stole the main ideas and wrote up a similar program
> that is working very, very well with the data sets I
> am working with today. It even picks reasonable
> thresholds when the dividing line between pixel
> populations is not totally straightforward. Thanks
> for bringing it to my attention.
>
> You can find my version of the program here:
>
> http://www.idlcoyote.com/programs/cgotsu_threshold.pro

Hold off on this a minute. I've been using my version
of the OTSU_THRESHOLD program for a week now, and I've
been seeing some strange results. The only thing I did
in my program was to beef up the keywords and error handling
for the histogram itself. I didn't change the underlying
code for OTSU_THRESHOLD.

In fact, just to confirm this, I've now gone back and
used the VERY same variable names, etc. But, I seem
to be getting different slightly different results with
the two programs.

I am trying to track this down now. In fact, I'm using the
newsgroup in EXACTLY the way Helder describes this morning!

Here is what just occurred to me. One of the things I am
VERY particular about (long experience, probably) is matching
the data type of the BINSIZE keyword with the data type of
the data going into the histogram. The OTSU_THRESHOLD program
I was using as a model didn't do this. I wonder if this is
the source of the difference. Back soon! :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Dimensional confusion
Next Topic: Re: Dimensional confusion

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

Current Time: Wed Oct 08 15:54:25 PDT 2025

Total time taken to generate the page: 0.00475 seconds