High-Level Data Reduction Library: hdrl_fit.c Source File

High-Level Data Reduction Library 1.6.0 High-Level data reduction routines for ESO pipelines

Loading...
Searching...
No Matches
hdrl_fit.c
Go to the documentation of this file.
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2014 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26-----------------------------------------------------------------------------*/
27
28#include "hdrl_types.h"
29#include "hdrl_image.h"
30#include "hdrl_imagelist.h"
31#include "hdrl_utils.h"
32#include "hdrl_fit.h"
33
34#include <cpl.h>
35#include <math.h>
36#include <assert.h>
37
38/*----------------------------------------------------------------------------*/
42/*----------------------------------------------------------------------------*/
43
47/*-----------------------------------------------------------------------------
48 Static
49 -----------------------------------------------------------------------------*/
50
53#if CPL_VERSION_CODE > CPL_VERSION(6, 6, 255)
54 static cpl_matrix * matrix_product_normal_create(const cpl_matrix * self)
55{
56 const size_t m = cpl_matrix_get_nrow(self);
57 cpl_matrix * product = cpl_matrix_wrap((cpl_size)m, (cpl_size)m,
58 cpl_malloc(m * m * sizeof(double)));
59
60 if (cpl_matrix_product_normal(product, self)) {
61 cpl_matrix_delete(product);
62 product = NULL;
63 }
64
65 return product;
66}
67#else
68cpl_matrix * cpl_matrix_product_normal_create(const cpl_matrix * self);
69cpl_error_code cpl_matrix_product_transpose(cpl_matrix * self,
70 const cpl_matrix * ma,
71 const cpl_matrix * mb);
72 static cpl_matrix * matrix_product_normal_create(const cpl_matrix * self)
73{
74
75 return cpl_matrix_product_normal_create(self);
76}
77#endif
78
79
80 typedef struct {
81 /* input design matrix of fit */
82 cpl_matrix * design;
83 /* coefficient row matrix */
84 cpl_matrix * coef;
85 /* covariance matrix of coefficients */
86 cpl_matrix * cov;
87} hdrl_ls_fit_result;
88
89
90/* ---------------------------------------------------------------------------*/
95/* ---------------------------------------------------------------------------*/
96 static hdrl_ls_fit_result * hdrl_ls_fit_result_create(void)
97{
98 return cpl_calloc(1, sizeof(hdrl_ls_fit_result));
99}
100
101/* ---------------------------------------------------------------------------*/
106/* ---------------------------------------------------------------------------*/
107 static void hdrl_ls_fit_result_delete(hdrl_ls_fit_result * r)
108{
109 if (r == NULL)
110 return;
111 cpl_matrix_delete(r->design);
112 cpl_matrix_delete(r->coef);
113 cpl_matrix_delete(r->cov);
114 cpl_free(r);
115}
116
117/* ---------------------------------------------------------------------------*/
123/* ---------------------------------------------------------------------------*/
124 static cpl_vector * hdrl_ls_fit_result_get_fitted_values(
125 const hdrl_ls_fit_result * r)
126{
127 cpl_matrix * fvalues = cpl_matrix_product_create(r->design, r->coef);
128 cpl_vector * res = cpl_vector_wrap(cpl_matrix_get_nrow(fvalues),
129 cpl_matrix_get_data(fvalues));
130 cpl_matrix_unwrap(fvalues);
131 return res;
132}
133
134/* ---------------------------------------------------------------------------*/
141/* ---------------------------------------------------------------------------*/
142 static cpl_vector * hdrl_ls_fit_result_get_residuals(
143 const hdrl_ls_fit_result * r,
144 const cpl_vector * data)
145{
146 cpl_vector * fval = hdrl_ls_fit_result_get_fitted_values(r);
147 cpl_vector * res = cpl_vector_duplicate(data);
148 cpl_vector_subtract(res, fval);
149 cpl_vector_delete(fval);
150 return res;
151}
152
153
154/* ---------------------------------------------------------------------------*/
165/* ---------------------------------------------------------------------------*/
166 static double hdrl_ls_fit_result_get_chi2(
167 const hdrl_ls_fit_result * r,
168 const cpl_vector * data,
169 cpl_vector * errors)
170{
171 cpl_vector * fval = hdrl_ls_fit_result_get_residuals(r, data);
172 /* mse = sum(sqrt(weights) * residuals ** 2) / df */
173 cpl_vector_divide(fval, errors);
174 cpl_vector_multiply(fval, fval);
175 double mswd = cpl_vector_get_sum(fval);
176
177 cpl_vector_delete(fval);
178 return mswd;
179}
180
181/* ---------------------------------------------------------------------------*/
187/* ---------------------------------------------------------------------------*/
188 static cpl_size hdrl_ls_fit_result_get_residual_dof(const hdrl_ls_fit_result * r)
189{
190 return cpl_matrix_get_nrow(r->design) - cpl_matrix_get_ncol(r->design);
191}
192
193/* ---------------------------------------------------------------------------*/
203/* ---------------------------------------------------------------------------*/
204 static cpl_matrix * vander1d(
205 const cpl_vector * sample,
206 cpl_size degree,
207 void (*func)(double, double *, size_t))
208{
209 const size_t nr = cpl_vector_get_size(sample);
210 const size_t nc = degree + 1;
211 cpl_matrix * V = cpl_matrix_new(nr, nc);
212 double * v = cpl_matrix_get_data(V);
213 const double * d = cpl_vector_get_data_const(sample);
214 for (size_t i = 0; i < nr; i++) {
215 func(d[i], &v[i*nc], nc);
216 }
217
218 return V;
219}
220
221 static void polynomial(double x, double * p, size_t ncoefs)
222{
223 p[0] = 1.;
224 for (size_t i = 1; i < ncoefs; i++) {
225 p[i] = pow(x, i);
226 }
227}
228
229/* ---------------------------------------------------------------------------*/
237/* ---------------------------------------------------------------------------*/
238 static cpl_matrix * polyvander1d(
239 const cpl_vector * sample,
240 cpl_size degree)
241{
242 return vander1d(sample, degree, &polynomial);
243}
244
245/* ---------------------------------------------------------------------------*/
255/* ---------------------------------------------------------------------------*/
256 static hdrl_ls_fit_result * fit(
257 const cpl_matrix * design,
258 const cpl_vector * values,
259 const cpl_vector * errors)
260{
261 hdrl_ls_fit_result * r = hdrl_ls_fit_result_create();
262 r->design = cpl_matrix_duplicate(design);
263 if (errors) {
264 assert(cpl_matrix_get_nrow(design) == cpl_vector_get_size(errors));
265 /* weight response and design */
266 cpl_vector * vrhs = cpl_vector_duplicate(errors);
267 cpl_vector_power(vrhs, -1);
268 cpl_matrix * wdesign = cpl_matrix_duplicate(design);
269 for (size_t i = 0; i < (size_t)cpl_vector_get_size(errors); i++) {
270 double w = cpl_vector_get(vrhs, i);
271 for (size_t j = 0; j < (size_t)cpl_matrix_get_ncol(wdesign); j++) {
272 cpl_matrix_set(wdesign, i, j,
273 cpl_matrix_get(wdesign, i, j) * w);
274 }
275 }
276
277 cpl_vector_multiply(vrhs, values);
278 cpl_matrix * rhs = cpl_matrix_wrap(cpl_vector_get_size(vrhs), 1,
279 cpl_vector_get_data(vrhs));
280
281 /* solve Ax = b */
282 /* cpl_matrix_solve_normal(design, rhs) + covariance */
283 {
284 cpl_matrix * At = cpl_matrix_transpose_create(wdesign);
285 cpl_matrix * AtA = matrix_product_normal_create(At);
286
287 /* RRt = AtA */
288 cpl_matrix_decomp_chol(AtA);
289 /* solve for pseudo inverse: (RRt)P=At*/
290 cpl_matrix_solve_chol(AtA, At);
291 /* compute solution to system Ax=b -> x=Pb */
292 r->coef = cpl_matrix_product_create(At, rhs);
293 /* compute covariance matrix cov(b) = PPt */
294 r->cov = cpl_matrix_new(cpl_matrix_get_ncol(At),
295 cpl_matrix_get_ncol(At));
296 cpl_matrix_product_transpose(r->cov, At, At);
297
298 cpl_matrix_delete(At);
299 cpl_matrix_delete(AtA);
300 }
301
302 cpl_matrix_unwrap(rhs);
303 cpl_vector_delete(vrhs);
304 cpl_matrix_delete(wdesign);
305 }
306 else {
307 cpl_vector * vrhs = cpl_vector_duplicate(values);
308 cpl_matrix * rhs = cpl_matrix_wrap(cpl_vector_get_size(vrhs), 1,
309 cpl_vector_get_data(vrhs));
310 r->coef = cpl_matrix_solve_normal(design, rhs);
311 cpl_matrix_unwrap(rhs);
312 cpl_vector_delete(vrhs);
313 }
314 return r;
315}
316
317/* ---------------------------------------------------------------------------*/
330/* ---------------------------------------------------------------------------*/
331 static hdrl_ls_fit_result * polyfit1d(
332 const cpl_vector * sample,
333 const cpl_vector * values,
334 const cpl_vector * errors,
335 int degree)
336{
337 cpl_matrix * design = polyvander1d(sample, degree);
338 hdrl_ls_fit_result * r = fit(design, values, errors);
339 cpl_matrix_delete(design);
340 return r;
341}
344/* ---------------------------------------------------------------------------*/
365/* ---------------------------------------------------------------------------*/
366cpl_error_code
367 hdrl_fit_polynomial_imagelist(const hdrl_imagelist * list,
368 const cpl_vector * samplepos,
369 const int degree,
370 hdrl_imagelist ** coef,
371 cpl_image ** chi2,
372 cpl_image ** dof)
373{
374 cpl_ensure_code(degree >= 0, CPL_ERROR_INCOMPATIBLE_INPUT);
375 cpl_ensure_code(list && samplepos && coef, CPL_ERROR_NULL_INPUT);
376 // TODO test
377 cpl_ensure_code(cpl_vector_get_size(samplepos) ==
378 hdrl_imagelist_get_size(list),
379 CPL_ERROR_INCOMPATIBLE_INPUT);
380 cpl_ensure_code(cpl_vector_get_size(samplepos) ==
381 hdrl_imagelist_get_size(list),
382 CPL_ERROR_INCOMPATIBLE_INPUT);
383 cpl_ensure_code(hdrl_imagelist_get_size(list) > 0,
384 CPL_ERROR_INCOMPATIBLE_INPUT);
385 cpl_ensure_code(hdrl_imagelist_get_size(list) >= degree + 1,
386 CPL_ERROR_INCOMPATIBLE_INPUT);
387 intptr_t nx = hdrl_imagelist_get_size_x(list);
388 intptr_t ny = hdrl_imagelist_get_size_y(list);
389 size_t noz = degree + 1;
390
391 /* make sure image has a mask to avoid creation race later */
392 if (coef) {
393 *coef = hdrl_imagelist_new();
394 }
395 if (chi2) {
396 *chi2 = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
397 cpl_image_get_bpm(*chi2);
398 }
399 if (dof) {
400 *dof = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
401 cpl_image_get_bpm(*dof);
402 }
403 for (size_t z = 0; z < noz; z++) {
404 hdrl_image * img = hdrl_image_new(nx, ny);
405 hdrl_image_get_mask(img);
406 hdrl_imagelist_set(*coef, img, z);
407 }
408 cpl_imagelist * datal, *errorl;
409 if (hdrl_imagelist_to_cplwrap(list, &datal, &errorl)) {
410 goto fail;
411 }
412 HDRL_OMP(omp parallel shared(coef, chi2, dof))
413 {
414 hdrl_vector_cache * cache =
415 hdrl_vector_cache_new(cpl_imagelist_get_size(datal), nx * 2);
416 /* copy to store bad pixel cleaned positions in */
417 cpl_vector * nsamppos = cpl_vector_duplicate(samplepos);
418 HDRL_OMP(omp for)
419 for (intptr_t y = 0; y < ny; y++) {
420 cpl_vector * datav[nx];
421 cpl_vector * errsv[nx];
422 hdrl_imagelist_to_vector_row(datal, y + 1, datav, cache);
423 hdrl_imagelist_to_vector_row(errorl, y + 1, errsv, cache);
424 for (intptr_t x = 0; x < nx; x++) {
425 /* all bad or less good than fit degrees */
426 cpl_vector * data = datav[x];
427 cpl_vector * errs = errsv[x];
428 if (data == NULL || (size_t)cpl_vector_get_size(data) < noz) {
429 for (size_t z = 0; z < noz; z++) {
430 hdrl_image * oimg = hdrl_imagelist_get(*coef, z);
431 hdrl_image_set_pixel(oimg, x + 1, y + 1,
432 (hdrl_value){NAN, NAN});
433 hdrl_image_reject(oimg, x + 1, y + 1);
434 }
435 if (chi2) {
436 cpl_image_set(*chi2, x + 1, y + 1, NAN);
437 cpl_image_reject(*chi2, x + 1, y + 1);
438 }
439 if (dof) {
440 int n = data ? cpl_vector_get_size(data) - noz : -noz;
441 cpl_image_set(*dof, x + 1, y + 1, n);
442 cpl_image_reject(*dof, x + 1, y + 1);
443 }
444 hdrl_cplvector_delete_to_cache(cache, data);
445 hdrl_cplvector_delete_to_cache(cache, errs);
446 continue;
447 }
448
449 hdrl_ls_fit_result * r;
450
451 /* remove bad pixels from sample positions and fit */
452 if (cpl_vector_get_size(data) != cpl_vector_get_size(samplepos)) {
453 size_t j = 0;
454 cpl_vector_set_size(nsamppos, cpl_vector_get_size(data));
455 for (size_t i = 0; i < (size_t)hdrl_imagelist_get_size(list); i++) {
456 hdrl_image * img = hdrl_imagelist_get(list, i);
457 if (hdrl_image_is_rejected(img, x + 1, y + 1))
458 continue;
459 cpl_vector_set(nsamppos, j++, cpl_vector_get(samplepos, i));
460 }
461
462 r = polyfit1d(nsamppos, data, errs, degree);
463 }
464 else {
465 r = polyfit1d(samplepos, data, errs, degree);
466 }
467
468 // TODO handle failure
469 for (size_t z = 0; z < noz; z++) {
470 hdrl_image * oimg = hdrl_imagelist_get(*coef, z);
471 hdrl_image_set_pixel(oimg, x + 1, y + 1,
472 (hdrl_value){cpl_matrix_get(r->coef, z, 0),
473 sqrt(cpl_matrix_get(r->cov, z, z))});
474 }
475 if (chi2) {
476 cpl_image_set(*chi2, x + 1, y + 1,
477 hdrl_ls_fit_result_get_chi2(r, data, errs));
478 }
479 if (dof) {
480 cpl_image_set(*dof, x + 1, y + 1,
481 hdrl_ls_fit_result_get_residual_dof(r));
482 }
483 hdrl_ls_fit_result_delete(r);
484 hdrl_cplvector_delete_to_cache(cache, data);
485 hdrl_cplvector_delete_to_cache(cache, errs);
486 }
487 }
488 hdrl_vector_cache_delete(cache);
489 cpl_vector_delete(nsamppos);
490 }
491
492 cpl_imagelist_unwrap(datal);
493 cpl_imagelist_unwrap(errorl);
494
495 return cpl_error_get_code();
496fail:
497 hdrl_imagelist_delete(*coef);
498 *coef = NULL;
499 if (chi2) {
500 cpl_image_delete(*chi2);
501 *chi2 = NULL;
502 }
503 if (dof) {
504 cpl_image_delete(*dof);
505 *dof = NULL;
506 }
507 return cpl_error_get_code();
508}
509
510
511/* ---------------------------------------------------------------------------*/
538/* ---------------------------------------------------------------------------*/
539cpl_error_code
540 hdrl_fit_polynomial_imagelist2(const hdrl_imagelist * list,
541 const cpl_imagelist * samplepos,
542 const int degree,
543 hdrl_imagelist ** coef,
544 cpl_image ** chi2,
545 cpl_image ** dof)
546{
547 cpl_ensure_code(degree >= 0, CPL_ERROR_INCOMPATIBLE_INPUT);
548 cpl_ensure_code(list && samplepos && coef, CPL_ERROR_NULL_INPUT);
549 cpl_ensure_code(cpl_imagelist_get_size(samplepos) ==
550 hdrl_imagelist_get_size(list),
551 CPL_ERROR_INCOMPATIBLE_INPUT);
552 cpl_ensure_code(cpl_imagelist_get_size(samplepos) ==
553 hdrl_imagelist_get_size(list),
554 CPL_ERROR_INCOMPATIBLE_INPUT);
555 cpl_ensure_code(hdrl_imagelist_get_size(list) > 0,
556 CPL_ERROR_INCOMPATIBLE_INPUT);
557 cpl_ensure_code(hdrl_imagelist_get_size(list) >= degree + 1,
558 CPL_ERROR_INCOMPATIBLE_INPUT);
559 cpl_ensure_code(hdrl_image_get_size_x(hdrl_imagelist_get_const(list, 0)) ==
560 cpl_image_get_size_x(cpl_imagelist_get_const(samplepos, 0)),
561 CPL_ERROR_INCOMPATIBLE_INPUT);
562 cpl_ensure_code(hdrl_image_get_size_y(hdrl_imagelist_get_const(list, 0)) ==
563 cpl_image_get_size_y(cpl_imagelist_get_const(samplepos, 0)),
564 CPL_ERROR_INCOMPATIBLE_INPUT);
565 intptr_t nx = hdrl_imagelist_get_size_x(list);
566 intptr_t ny = hdrl_imagelist_get_size_y(list);
567 size_t noz = degree + 1;
568
569 /* make sure image has a mask to avoid creation race later */
570 if(coef) {
571 *coef = hdrl_imagelist_new();
572 }
573 if (chi2) {
574 *chi2 = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
575 cpl_image_get_bpm(*chi2);
576 }
577 if (dof) {
578 *dof = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
579 cpl_image_get_bpm(*dof);
580 }
581 for (size_t z = 0; z < noz; z++) {
582 hdrl_image * img = hdrl_image_new(nx, ny);
583 hdrl_image_get_mask(img);
584 hdrl_imagelist_set(*coef, img, z);
585 }
586 cpl_imagelist * datal, *errorl;
587 if (hdrl_imagelist_to_cplwrap(list, &datal, &errorl)) {
588 goto fail;
589 }
590 HDRL_OMP(omp parallel shared(coef, chi2, dof))
591 {
592 hdrl_vector_cache * cache =
593 hdrl_vector_cache_new(cpl_imagelist_get_size(datal), nx * 3);
594 HDRL_OMP(omp for)
595 for (intptr_t y = 0; y < ny; y++) {
596 cpl_vector * datav[nx];
597 cpl_vector * errsv[nx];
598 cpl_vector * samplev[nx];
599 hdrl_imagelist_to_vector_row(datal, y + 1, datav, cache);
600 hdrl_imagelist_to_vector_row(errorl, y + 1, errsv, cache);
601 hdrl_imagelist_to_vector_row(samplepos, y + 1, samplev, cache);
602 for (intptr_t x = 0; x < nx; x++) {
603 cpl_vector * data = datav[x];
604 cpl_vector * errs = errsv[x];
605 cpl_vector * samp = samplev[x];
606 /* all bad or less good than fit degrees */
607 if (data == NULL || samp == NULL ||
608 (size_t)cpl_vector_get_size(data) < noz ||
609 (size_t)cpl_vector_get_size(samp) < noz) {
610 for (size_t z = 0; z < noz; z++) {
611 hdrl_image * oimg = hdrl_imagelist_get(*coef, z);
612 hdrl_image_set_pixel(oimg, x + 1, y + 1,
613 (hdrl_value){NAN, NAN});
614 hdrl_image_reject(oimg, x + 1, y + 1);
615 }
616 if (chi2) {
617 cpl_image_set(*chi2, x + 1, y + 1, NAN);
618 cpl_image_reject(*chi2, x + 1, y + 1);
619 }
620 if (dof) {
621 int n = data ? cpl_vector_get_size(data) - noz : -noz;
622 cpl_image_set(*dof, x + 1, y + 1, n);
623 cpl_image_reject(*dof, x + 1, y + 1);
624 }
625 hdrl_cplvector_delete_to_cache(cache, data);
626 hdrl_cplvector_delete_to_cache(cache, errs);
627 hdrl_cplvector_delete_to_cache(cache, samp);
628 continue;
629 }
630
631 /* remove bad pixels from vectors */
632 if (cpl_vector_get_size(data) != hdrl_imagelist_get_size(list) ||
633 cpl_vector_get_size(samp) != hdrl_imagelist_get_size(list)) {
634 size_t j = 0;
635 for (size_t i = 0; i < (size_t)hdrl_imagelist_get_size(list); i++) {
636 int dump;
637 hdrl_image * himg = hdrl_imagelist_get(list, i);
638 const cpl_image * img = cpl_imagelist_get_const(samplepos, i);
639 /* if any entry is bad skip */
640 if (hdrl_image_is_rejected(himg, x + 1, y + 1) ||
641 cpl_image_is_rejected(img, x + 1, y + 1))
642 continue;
643 /* refill vector with non bad pixels in order */
644 hdrl_value val = hdrl_image_get_pixel(himg, x + 1, y + 1, NULL);
645 cpl_vector_set(data, j, val.data);
646 cpl_vector_set(errs, j, val.error);
647 cpl_vector_set(samp, j, cpl_image_get(img, x + 1, y + 1, &dump));
648 j++;
649 }
650 cpl_vector_set_size(data, j);
651 cpl_vector_set_size(errs, j);
652 cpl_vector_set_size(samp, j);
653 }
654
655 hdrl_ls_fit_result * r = polyfit1d(samp, data, errs, degree);
656 // TODO handle failure
657 for (size_t z = 0; z < noz; z++) {
658 hdrl_image * oimg = hdrl_imagelist_get(*coef, z);
659 hdrl_image_set_pixel(oimg, x + 1, y + 1,
660 (hdrl_value){cpl_matrix_get(r->coef, z, 0),
661 sqrt(cpl_matrix_get(r->cov, z, z))});
662 }
663 if (chi2) {
664 cpl_image_set(*chi2, x + 1, y + 1,
665 hdrl_ls_fit_result_get_chi2(r, data, errs));
666 }
667 if (dof) {
668 cpl_image_set(*dof, x + 1, y + 1,
669 hdrl_ls_fit_result_get_residual_dof(r));
670 }
671 hdrl_ls_fit_result_delete(r);
672 hdrl_cplvector_delete_to_cache(cache, data);
673 hdrl_cplvector_delete_to_cache(cache, errs);
674 hdrl_cplvector_delete_to_cache(cache, samp);
675 }
676 }
677 hdrl_vector_cache_delete(cache);
678 }
679
680 cpl_imagelist_unwrap(datal);
681 cpl_imagelist_unwrap(errorl);
682
683 return cpl_error_get_code();
684fail:
685 hdrl_imagelist_delete(*coef);
686 *coef = NULL;
687 if (chi2) {
688 cpl_image_delete(*chi2);
689 *chi2 = NULL;
690 }
691 if (dof) {
692 cpl_image_delete(*dof);
693 *dof = NULL;
694 }
695 return cpl_error_get_code();
696}
hdrl_types.h
HDRL_TYPE_DATA
#define HDRL_TYPE_DATA
Definition hdrl_types.h:63
HDRL_OMP
#define HDRL_OMP(x)
Definition hdrl_cat_def.h:35
hdrl_image.h
hdrl_imagelist.h
hdrl_fit.h
hdrl_utils.h
hdrl_fit_polynomial_imagelist2
cpl_error_code hdrl_fit_polynomial_imagelist2(const hdrl_imagelist *list, const cpl_imagelist *samplepos, const int degree, hdrl_imagelist **coef, cpl_image **chi2, cpl_image **dof)
weighted least squares polynomial fit of each pixel of a imagelist
Definition hdrl_fit.c:540
hdrl_fit_polynomial_imagelist
cpl_error_code hdrl_fit_polynomial_imagelist(const hdrl_imagelist *list, const cpl_vector *samplepos, const int degree, hdrl_imagelist **coef, cpl_image **chi2, cpl_image **dof)
weighted least squares polynomial fit of each pixel of a imagelist
Definition hdrl_fit.c:367
hdrl_image_get_pixel
hdrl_value hdrl_image_get_pixel(const hdrl_image *self, cpl_size xpos, cpl_size ypos, int *pis_rejected)
get pixel values of hdrl_image
Definition hdrl_image.c:559
hdrl_image_is_rejected
int hdrl_image_is_rejected(hdrl_image *self, cpl_size xpos, cpl_size ypos)
return if pixel is marked bad
Definition hdrl_image.c:445
hdrl_image_set_pixel
cpl_error_code hdrl_image_set_pixel(hdrl_image *self, cpl_size xpos, cpl_size ypos, hdrl_value value)
set pixel values of hdrl_image
Definition hdrl_image.c:594
hdrl_image_get_mask
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
Definition hdrl_image.c:157
hdrl_image_get_size_y
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
Definition hdrl_image.c:540
hdrl_image_get_size_x
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
Definition hdrl_image.c:525
hdrl_image_reject
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
Definition hdrl_image.c:427
hdrl_image_new
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
Definition hdrl_image.c:311
hdrl_imagelist_set
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
Definition hdrl_imagelist_io.c:274
hdrl_imagelist_get_size_y
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
Definition hdrl_imagelist_io.c:188
hdrl_imagelist_delete
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
Definition hdrl_imagelist_io.c:384
hdrl_imagelist_get_const
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
Definition hdrl_imagelist_io.c:229
hdrl_imagelist_get_size
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
Definition hdrl_imagelist_io.c:148
hdrl_imagelist_new
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
Definition hdrl_imagelist_io.c:84
hdrl_imagelist_get_size_x
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
Definition hdrl_imagelist_io.c:168
hdrl_imagelist_get
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
Definition hdrl_imagelist_io.c:210
_hdrl_image_
Definition hdrl_image_defs.h:40
_hdrl_imagelist_
Definition hdrl_imagelist_defs.h:42
hdrl_value
Definition hdrl_types.h:77
hdrl_value::error
hdrl_error_t error
Definition hdrl_types.h:79
hdrl_value::data
hdrl_data_t data
Definition hdrl_types.h:78