Developers of machine vision applications often require extra functionality that is not directly related to image processing. One frequent task, for example, is curve fitting.
MVTec’s HALCON 12 provides linear algebra functions that make this relatively easy. The following code fits a parabola to a given set of points:
* input points
X := [0,1,2,3,4,5]
Y := [0.1,0.95, 4.2,8.7,15.3,26.4]
* left hand side
create_matrix(3, |X|, [gen_tuple_const(|X|,1),X,X*X], MatrixID)
transpose_matrix(MatrixID, MatrixLHS)
*right hand side
create_matrix(|X|, 1, Y, MatrixLHS)
solve_matrix(MatrixLHS, ‘general’, 0, MatrixRHS, MatrixResultID)
* get result
get_full_matrix(MatrixResultID, Param)
* plot as function
XVal := [0:0.1:6]
YVal := XVal*XVal*Param[2] + XVal*Param[1] + Param[0]
create_funct_1d_pairs(XVal, YVal, Function)
Here the problem is formulated as a matrix equation which is solved in the least squares sense. Of course this technique can be applied to arbitrary curves.
Read more on HALCON 12. Contact support@multipix with your queries.