Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

06-04-2010 04:09 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Hello,

I am looking for 2-D fitting code for LabVIEW. I can make use of code for an arbitrary function, but I specifically need to fit a CCD image to a general 2-D Gaussian profile. The image spot is not circular and the major axis can be at an arbitrary angle with respect to the image x and y axes. If you have any such code or pointers to some or to how to develop it myself (preferably without becoming a Levenberg-Marquardt expert), I'd be forever grateful.

Thanks,

-Rob Vest

NIST

06-06-2010 10:38 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

OK, this seems easy enough starting with one of my existing examples. Basically, you need a model with 6 parameters:

(0) Amplitude

(1) X-Pos

(2) Y-Pos

(3) width A

(4) Width B

(5) angle (0..pi)

I did a quick modification of my old model and it seems to work. Do you have a typical example data set so I can test?

06-06-2010 04:00 PM - edited 06-06-2010 04:00 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

OK, here's a quick attempt (LabVIEW 2009), using the above mentioned set of six parameters.

There is some ambiguity, because the two principal width are interchangeable and would correspond to a 90 degree rotation. I added some cleanup code that sorts the widths and align the angle with the larger width.

Currently, the reference definition for the rotation is somewhat arbitrary, and the principal Gaussian widths are defined as 2*sigma for code simplicity. Statisticians like widths in terms of standard deviations, while spectroscopists prefer widths defined as width at half height. (If you also need an **offset**, that would be easy to add later, resulting in seven parameters). The current model VI can be easily adapted for all this with minor changes. I don't know what you want!

Note that the current calculation is a bit slow. I have parallelized the main model loop to speed things up a bit on multicore hardware. I am sure the speed can be significantly improved.

Still, this should get you started. From my limited testing, it seems pretty robust and converges with a wide range of simulated data. Of course if the two principal width are very similar, the angle will have a large error. If the widths are identical, the angle will probably be random.

Message Edited by altenbach on 06-06-2010 02:00 PM

- Tags:
- 2DFit

06-06-2010 04:25 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Additional suggestions:

- The normalization subVI should take the absolute value of the two widths before comparing them. (The fit could return a negative width)
- Use a table for the output instead of a 2D array.

06-07-2010 09:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

06-07-2010 11:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I streamlined the model code a little bit causing a **3-4x** increase in fitting speed for the default data. There is probably still quite a bit of slack left.

(Of course the default image size currently is ~300x250, meaning that the y-size is ~75k. The speed could be dramatically improved if we could just select the area of interest instead of fitting 5% important points and 95% of irrelevant background data. )

02-11-2011 02:57 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

02-12-2011 12:30 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@c5 wrote:

I am having a hard time understanding how the curve fitting inputs "X", "Y", and "data" are used here.

Well, I don't even use the x input. X is not in any of the fitting algorithms, only in the model and is an optional input. As you will see, our model has no need for x.

All the model needs to be able to do is generate a set of simulated values based on the parameters that correspond to an equally arranged set of datapoints from your image. These are the "Y' values. You have a 2D array of data, but the fitting VIs require a 1D array. Using reshape array with a size equal to the product of the image dimension will arrange the same data as a 1D array. Similarly, the model calculates a matching image, then also rehapes it to a 1D array.

The fitting VI will compare the two 1D arrays (data vs model) and adjust the parameters until the two 1D arrays agree as much as possible.

In order to calculate the model, the 2D dimension of the image needs to be known. The data variant input can be used to inform the model about any other information that are needed. In this particluar case we use it to relay information about the image size from the toplevel to the model. A variant is a generic container that can hold any kind of data (a cluster of two I32 scalars in this particular case). Of course the model needs to be able to convert the variant back to the original cluster, so for that it needs to know what the datatype is. Thus we wire a cluster with the correct structure (values are irrelevant) to the type input of "variant to data". Like magic, the output is again a cluster of two I32 values that we now can tap for the 2D model computations.

The model is defined via a strictly typed static VI reference. You can click that reference to edit the model VI. We use the same model also via "call by reference node" in order to calculate the image based on the initial guess parameters.

@c5 wrote:

Specifically I have an image that I convert to an array via ImageToArray and want to put this in a format where I can enter it into your program.

As I said, all you need to do is reshape to a 1D array with a size equivalent to the number of pixels in the image.

What is your LabVIEW version?

02-13-2011 02:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thanks for this very helpful information. I am using Labview 2010.

05-12-2011 09:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thank you very much for your great example! I adapted it so that I can fit images from a camera.

You write here that you have improved the model for better performance.

Could I maybe get this improved version? That would be great!

Thank you very much for everything!