LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Request for help - Line of best fit using first derivative on XY Graph

Solved!
Go to solution

Hi,

 

I'm trying to find a best fit for a graph built of an array of pixel values. When I apply a 2nd order polynomial, this fits well until the shift in pixel values.

 

Jee_with_a_J_0-1710521480486.png

What I'm hoping for is a fit like the purple line I've added. 

 

My maths skills are perhaps more dysfunctional and functional. I've tried using the derivative function to find the slope of the curve, but I'm getting myself in a spin. From memory it needs to be a first order derivative but I've tried various similar approaches from the forums and getting nowhere fast.

 

If anyone can help me out with this one it'd be greatly appreciated!

 

Thanks,


J

0 Kudos
Message 1 of 9
(982 Views)

Please fill "Array 2" with reasonable default values. An empty array is not useful to demonstrate the problem. (It almost seems you made the value of element zero the default for the elements instead of setting the default for the array. Big difference! When setting value to default, make sure to select the array, not the array element!)

 

Also the poly order control should be an integer (there is no 2.5th order, for example!) and should have a value of 2 by default.

 

Also, since the x values are spaced equally, you don't need xy-graphs. Much less effort!

 

Please pick a reasonable connector pattern. Nobody needs 28 connectors! (and if you think you do, something else is wrong)

 

And please don't maximize front panel and diagram to the screen! I don't like to stare at a code that is 90% whitespace)

0 Kudos
Message 2 of 9
(953 Views)

Hi altenbach,

 

Thanks for taking the time to review my post and thanks for your feedback. Stupidly, I had forgotten to set the values as default for the array - this has been corrected.

 

I've also taken on your other points of feedback and have corrected these to reflect best practice. 

 

If you have a moment to assist in my original issue now these have been resolved, it would be appreciated!

 

Thanks,

 

J

0 Kudos
Message 3 of 9
(220 Views)

A second order fit would be trying to fit a parabola to your data.  I think this  is what your fit shows, but it did not fit well.  I would think this would show a high fit residual.  A higher order fit might be better, but may not fit well either.

What problem are you trying to solve at a higher level? Some form of image correction?

I do not have the latest LabVIEW version, so I cannot see your code.

0 Kudos
Message 4 of 9
(197 Views)

Hi,

 

I've reattached in for LV2010 and later, whilst including my source image.

 

I've made progress in converting the values to 'NaN' so they no longer plot, but now the polynomial calculations don't work with the 'NaN' entries.

 

 

The problem:

 

What I have is a linescan camera that when unrolled, is causing some image warping, as the paper is moving left/right. I need to realign these so I'm able to analyse the image.

 

I have a solid block of colour which I can use to track first pixel, but there is a region of whitespace where I can no longer track the edge of the print, so I'm not able to do this in this region. The markers in this area are variable too, so I can't use them to align the image, as these themselves won't be aligned.

 

Ideally, I'd just change the source image to get a solid black line - which would make the analysis easy. But of course, I can't do that!

 

So what I'm trying to achieve at present, is to get the average column pixel values and a line of best fit so I'm then able to take the values and use them to build a spline for the image adjustment.

 

I'm just struggling to get that line of best fit.

 

Thanks,


J

 

 

 

 

 

 

0 Kudos
Message 5 of 9
(192 Views)
Solution
Accepted by topic author Jee_with_a_J

Not sure if this is what you are looking for...

I eliminated the points marked as NaN from the fit, and then evaluated the polynomial at all points after it was fit.

Has a few typos in the comments...

 

0 Kudos
Message 6 of 9
(175 Views)
Solution
Accepted by topic author Jee_with_a_J

See if this can give you some ideas.... (Since X is no longer equally spaced, we need an xy graph). It would be easy to detect the transition points automatically or select them with cursors.

 

altenbach_0-1711476607071.png

 

 

0 Kudos
Message 7 of 9
(172 Views)

Hi altenbach,

 

Thanks so much for your help. Exactly what I needed and does the job perfectly, I also like the compactified for loop with the coerce, I'll definitely be using that again in the future.


Solved.

 

Aidan

0 Kudos
Message 8 of 9
(141 Views)

Hi jjohn!

 

Thanks - exactly what I was looking for! 


Solved.

 

0 Kudos
Message 9 of 9
(140 Views)