01-17-2013 05:19 PM
Yes, my image looks like the one you have. It's elliptical and with an angle. I attached your code only because I changed some wiring when I use your fitwithRotation code based on your 2DGaussianFit with offset. I was just wondering if I was doing something stupid by mixing your two different codes. I attached what I'm using with minor 'messing up' modification from your code. Also in the fitting model, I added an offset too. Thank you very much for your help.
01-18-2013 02:08 AM - edited 01-18-2013 02:20 AM
Sorry, I don't have IMAQ.
Can you run your VI, reading the image data, then stop. Now right-click the terminal of "Image Pixels (I16 to DBL) in ROI" and select "change to constant". Save the VI under a new name a re-attach it here. Now I have VI containing the 2D data and I can delete all the IMAQ stuff. Thanks!
All that said, you are using a model with 7 parameters, but your parameter estimates array only has 6 elements. This one needs to be of size=7, else nothing will work. Also, if you look inside the model VI, notice that f(x) output is not hooked up for some reason.
Fix these two things first, maybe the rest will fall into place.
(I haven't looked very hard for additional problems of similar nature, though, so there could be more....)
01-18-2013 09:15 AM
Hi, Altenbach,
I converted it into a constant array and change guess parameter array to size 7 and I patched that wire. All output is zero for some reason. Would you mind take a look at the code again and enlighten me on how to set the parameters if I got it wrong? Thank you so much!
01-18-2013 11:08 AM - edited 01-18-2013 11:14 AM
OK, this was easy. You have a mismatch in the variant.
Inside the model, you are trying to convert the variant to a cluster of two I32 elements, but in the main program you are converting an I32 array with to elements to a variant. SInce the types don't match, the FOR loops don't even execute inside the model (iteration=0)
All I basically did was converting the array to a cluster (output size=2) and things fall into place. 😄
(You could make more reasonable guesses, for example the last parameter (offset) could be the value of element (0,0) of the data array.)
Of course the "actual" and "difference" columns make no sense, because you don't have simulated data)
01-18-2013 11:48 AM
Thank you so much for fixing my problem so quickly. What do you mean by "Of course the "actual" and "difference" columns make no sense, because you don't have simulated data)" ?
01-18-2013 12:57 PM - edited 01-18-2013 01:01 PM
@soljiang wrote:
What do you mean by "Of course the "actual" and "difference" columns make no sense, because you don't have simulated data)" ?
In the original program, we are simulating data, so we know what the result is supposed to be.
In your case, we don't know until after fitting. For some unknown reason you are mergin the guess and fit parameters with the raw data, which makes absolutely no sense (resize the output array down to see the problem).
All you can show are the guess and best fit paramters. Since there are seven, the array should be resized to show seven rows.
Here's what I meant.
01-18-2013 02:57 PM
If you want to find the centroid of the 2 clusters and you want a code that'll be generic. i.e., find centroid of more than 2 clusters, I'd suggest this.
I've done something very similar. I've had 81 clusters [9x9] and I've had to find the peak on every single cluster and then segment using nearest neighbor algorithm.
My algorithm was very simple. If your data is gaussian, even better !
1. Smoothing - 2-D Median filter + Boxcar filter. You can play with this to suit your data.
2. Find Peak - Find the raw peak [max point] on the smoothed image
3. Keep drawing concentric circles around the peak and mask it [Zero] till the gradient goes in opposite direction
4. Go to step 2 and repeat till all peaks found. Since you masked in step 3, it'll find the next highest peak in the next iteration
5. Use the peak positions, segment your map where pixels closest to peak belong to that peak or region
6. Histogram all the points in a region, and fit it to a gaussian and there you go. You have your peak, and sigma
I don't have the code for it with me, but it's very simple. Hopefully it helps ! Good luck !!!
01-18-2013 06:12 PM
I see. Thank you very much for your help!!!
01-31-2013 07:37 PM
Hi, Altenbach,
In your 2DGaussianFit, just for verification, did you set width to be sqrt(2)*standard deviation? I'm trying to understand the parameter better. Thank you very much for your help!
Best,
Charles
02-04-2013 05:20 PM
soljiang wrote:In your 2DGaussianFit, just for verification, did you set width to be sqrt(2)*standard deviation? I'm trying to understand the parameter better. Thank you very much for your help!
Yes, I think this is right.
(I typically use widths defined as width at half height and never use standard deviations, so there could be some scaling problem. Modify as needed).