21#define TYPE_ADD(a) CONCAT2X(a, CPL_TYPE)
22#define TYPE_ADD_CONST(a) CONCAT2X(TYPE_ADD(a),const)
23#define IMAGE_GET_DATA TYPE_ADD(cpl_image_get_data)
45 const cpl_matrix * mh,
46 const cpl_matrix * mv,
47 const cpl_vector * x_pos,
48 const cpl_imagelist * values,
49 const cpl_vector * xpow,
50 double xnmean,
int np,
int nc,
54 const cpl_image * value = cpl_imagelist_get_const(values, 0);
55 const int nx = cpl_image_get_size_x(value);
56 const int ny = cpl_image_get_size_y(value);
60 double * px = cpl_malloc(
nx * nc *
sizeof(
double));
61 double * pbw = cpl_malloc(
nx * np *
sizeof(
double));
64 cpl_matrix * mx = cpl_matrix_wrap(
nx, nc, px);
66 cpl_matrix * mb = cpl_matrix_wrap(
nx, np, pbw);
67 const cpl_image* image = NULL;
73 for (jj = 0; jj <
ny; jj++) {
76 for (j=0; j < np; j++) {
77 image = cpl_imagelist_get_const( values, j);
83 for (i=0; i <
nx; i++) {
84 pbw[np * i + j] = (double)pi[
nx * jj + i];
96 for (i=0; i <
nx; i++) {
103 for (k=0; k < nc; k++) {
104 pdest = cpl_image_get_data_double(cpl_imagelist_get(self, k));
108 for (i=0; i <
nx; i++) {
109 pdest[
nx * jj + i] = px[nc * i + k];
113 if (fiterror != NULL) {
114 switch (cpl_image_get_type(fiterror)) {
115 case CPL_TYPE_DOUBLE:
133 cpl_matrix_delete(mx);
134 cpl_matrix_delete(mb);
157 const cpl_vector * x_pos,
158 const cpl_vector * xpow,
159 const cpl_matrix * mx,
160 const cpl_matrix * mb)
164 int nx = cpl_matrix_get_nrow(mx);
165 int nc = cpl_matrix_get_ncol(mx);
166 int np = cpl_vector_get_size(x_pos);
171 const double * pp = cpl_vector_get_data_const(x_pos);
174 const double * pm = xpow != NULL ? cpl_vector_get_data_const(xpow) : NULL;
175 const double * px = cpl_matrix_get_data_const(mx);
176 const double * pb = cpl_matrix_get_data_const(mb);
181 for (i=0; i <
nx; i++, pb += np, px += nc) {
183 for (j=0; j < np; j++) {
190 while (k) err = pp[j] * err + px[--k];
195 err = err * pm[j] - pb[j];
202 pself[i] = (
CPL_TYPE)(sq_err/(
double)np);
static cpl_error_code irplib_matrix_product_transpose(cpl_matrix *, const cpl_matrix *, const cpl_matrix *)
Fill a matrix with the product of A * B'.
static void irplib_fit_imagelist_residual_float(cpl_image *, int, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *)
static cpl_error_code irplib_matrix_solve_chol_transpose(const cpl_matrix *, cpl_matrix *)
Solve a L*transpose(L)-system with a transposed Right Hand Side.
static void irplib_polynomial_shift_double(double *, int, double)
Given p and u, modify the polynomial to p(x) := p(x+u)
static void irplib_fit_imagelist_residual_double(cpl_image *, int, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *)
static void irplib_fit_imagelist_residual_int(cpl_image *, int, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *)
static void TYPE_ADD() irplib_fit_imagelist_residual(cpl_image *self, int jj, const cpl_vector *x_pos, const cpl_vector *xpow, const cpl_matrix *mx, const cpl_matrix *mb)
Compute the residual of a polynomial fit to an imagelist.
#define TYPE_ADD_CONST(a)
static void TYPE_ADD() irplib_fit_imagelist_polynomial(cpl_imagelist *self, const cpl_matrix *mh, const cpl_matrix *mv, const cpl_vector *x_pos, const cpl_imagelist *values, const cpl_vector *xpow, double xnmean, int np, int nc, cpl_image *fiterror)
Fit a polynomial to each pixel in a list of images.