03-15-2024 11:58 AM
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.
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
Solved! Go to Solution.
03-15-2024 01:05 PM - edited 03-15-2024 01:17 PM
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)
03-26-2024 07:53 AM - edited 03-26-2024 07:54 AM
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
03-26-2024 09:54 AM
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.
03-26-2024 10:21 AM - edited 03-26-2024 10:23 AM
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
03-26-2024 12:51 PM - edited 03-26-2024 12:54 PM
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...
03-26-2024 01:10 PM - edited 03-26-2024 02:29 PM
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.
03-27-2024 04:24 AM
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
03-27-2024 04:26 AM
Hi jjohn!
Thanks - exactly what I was looking for!
Solved.