39 #include "isaac_fit.h"
79 const cpl_imagelist * ilist,
83 cpl_imagelist * fitres;
84 const cpl_image * image;
98 cpl_ensure(ilist != NULL, CPL_ERROR_NULL_INPUT, NULL);
99 cpl_ensure(dit != NULL, CPL_ERROR_NULL_INPUT, NULL);
100 cpl_ensure(deg > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
102 ni = cpl_imagelist_get_size(ilist);
103 cpl_ensure(ni >= deg, CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
105 image = cpl_imagelist_get_const(ilist, 0);
107 nx = cpl_image_get_size_x(image);
108 ny = cpl_image_get_size_y(image);
111 fitres = cpl_imagelist_new();
112 for (i=0; i < deg+1; i++) {
113 cpl_imagelist_set(fitres, cpl_image_new(nx, ny, CPL_TYPE_DOUBLE),
118 pv = cpl_malloc(ni * deg *
sizeof(
double));
119 mv = cpl_matrix_wrap(ni, deg, pv);
123 mb = cpl_matrix_wrap(ni, 1, (
double*)dit);
126 for (i=0; i < nx*ny; i++) {
128 for (j=0; j < ni; j++) {
129 pi=cpl_image_get_data_float_const(cpl_imagelist_get_const(ilist,j));
130 f_prod = f = (double)pi[i];
132 for (k=1; k < deg; k++) {
134 pv[deg * j + k] = f_prod;
141 mx = cpl_matrix_solve_normal(mv, mb);
144 for (k=0; k < deg+1; k++) {
146 cpl_image_get_data_double(cpl_imagelist_get(fitres,k));
152 const double * px = cpl_matrix_get_data(mx);
155 for (k=0; k < deg; k++) {
156 pimad = cpl_image_get_data_double(
157 cpl_imagelist_get(fitres, k));
163 for (j=0; j < ni; j++) {
167 for (k=0; k < deg; k++)
168 err -= px[k] * pv[deg * j + k];
171 sq_err /= (double)ni;
172 pimad=cpl_image_get_data_double(cpl_imagelist_get(fitres, deg));
174 cpl_matrix_delete(mx);
178 cpl_matrix_delete(mv);
179 (void)cpl_matrix_unwrap(mb);
181 if (nsing == nx*ny) {
182 cpl_imagelist_delete(fitres);
183 cpl_ensure(0, CPL_ERROR_SINGULAR_MATRIX, NULL);
cpl_imagelist * isaac_imagelist_fit_polynomial(const cpl_imagelist *ilist, const double *dit, int deg)
Compute the non linearity of the detector.