it outputs an image like this when clicking the mouse a few times.
but it needs a regular grid of color data to interpolate.
does anyone know how to do this kind of 2d interpolation of 1d data (color) in an unregular grid. in other words at a random x/y location i want to add a new color and have the interpolation adjust accordingly.
Hello,
I did similar things last year, the purpose was to interpolate randomly scattered anemometer’s value. The basic idea is TIN (Triangulated Irregular Network).
So
triangulate each xy position
divide it’s member side
then make contour line to get interpolated value
it is difficult to explain the code but there is repo https://github.com/Akira-Hayasaka/InterpScatterdVectorField
The app is on oF084, depends on ofxDelaunay & ofxMSACore & ofxMSAInterpolator.
i found this interesting thread about Scattered Data Interpolation, which ideally what i would need. Collect random points on a grid, give them a Z value that represents for example a temperature value and have the rest of the data be interpolated.
hey all
yes this type of usage is exactly suited to ofxPolyFit
Initialise a training dataset (in this case input is 2D, output is 1D) pfitDataSetf
Initialise a polynomial fit (2D input, 1D output, bicubic would be order = 3) ofxPolyFit
Fill your dataset with your points
Perform correlate on your ofxPolyFit
Use that correlation to evaluate new 1D outputs given 2D inputs (this can be performed on a grid of 2D points if you want to create a height graph like above)
polynomial fit (2D input, 1D output, bicubic would be order = 3) ofxPolyFit
but init asks for 4 values. i guess i am missing the order info?
///allocate local data ofxPolyFit
void init(int order, int dimensionsIn, int dimensionsOut, pfitBasisType basisType = BASIS_SHAPE_TRIANGLE);
i am able to pass 2d points at a 1d value, evaluate and get data back.
the data i get back does not seem to make much sense if the input data is not even.
@elliotwoods it would be so great if you could take a quick look. if i get this to work in the next couple of days than things would become so much more interesting.
here my code:
You’re doing a 3rd order fit (i.e. a cubic fit)
But your data input is random
So you’re trying to fit a curve surface which is only defined by 10 numbers (triangular bases, 3rd order, 2 inputs) to 25 random points. It just won’t be a good fit in that case.
If your points follow a smooth curve like in the image you posted before, then the fit will follow accurately.
You might be looking for something more like a B-Spline mesh which makes itself more complicated as you add more control points. A polyfit is more about finding a global pattern (which then can be defined simply mathematically).
i thought that might be the case, that my random values are the reason for the non-matching output.
i am planning to fit pan+tilt angles for an axis PTZ camera to x/y locations seen by a wide angle USB camera.
so, i think the relation between x/y and angles will be less random and nPolyfit will give me better results.
ah ok. yes then this should be a pretty good approximation
really interested to see how it goes, i’m really interested in using PTZ cameras as high res camera devices
as long as your training data is pretty good, then you’ll also be able to up the order of the polynomial fit (e.g. 4th order)
for Lit Tree, I did a 4D input -> 3D output triangular basis polyfit with ofxPolyfit, to create a stereo (2 points in 2D space of 2 cameras) to 3D point in world space, which worked pretty well.
you mean i can get pan and tilt as outputs from the same nPolyfit?
i thought i will have to do 2 separate nPolyfits one for x/y input and pan output and and other one for x/y input and tilt output.
it sounds like your ofxNonLinearFit code already does what i am planning todo, only that i am feeding it 2d data while you are feeding it 3d data. cool. will have to poke around it.
ok. now that i have real life data the pan and tilt angles seem to give me better nPolyfit results.
i am noticing that sometimes no fitting is being found or performed. even if i do not change the code, a restart of the app can result in proper fitting values or no fitting at all.
next test is trying the 4th order thing you mentioned; i.e. pan and tilt angles as a 2d output. ?
interesting. sounds like some kind of bad initialization in the code (i.e. likely in the addon not your code), if it’s returning different fits each time.
3rd order = using terms in x^3, x^2, x, y^3, y^2, y and combinations of these
4th order = using terms in x^4, x^3, x^2, x, y^4, y^3, y^2, y and combinations of these
(i.e. it doesn’t change the dimensionality of the inputs or outputs, but changes how complex the model is which goes between the inputs and outputs)
if you just call fit multiple times in the same session what happens?