CR2RE Pipeline Reference Manual 1.7.0
hdrl_fringe-test.c
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#ifndef HDRL_USE_PRIVATE
25/* Make sure we pull in private functions like hdrl_mime_fringe_amplitudes. */
26#define HDRL_USE_PRIVATE
27#endif
28
29#include "hdrl_fringe.h"
30#include "hdrl_prototyping.h"
31#include "hdrl_random.h"
32
33#include <cpl.h>
34#include <math.h>
35
36/*----------------------------------------------------------------------------*/
40/*----------------------------------------------------------------------------*/
41
42/*-----------------------------------------------------------------------------
43 Functions prototypes
44 -----------------------------------------------------------------------------*/
45void test_hermite_sum(void);
46void hdrl_fringe_compute_test_input(void);
47void hdrl_fringe_correct_test_input(void);
48void hdrl_fringe_hermite_test(void);
49void hdrl_mime_fringe_amplitudes_test(void);
50void hdrl_mime_fringe_amplitudes_ls_test(void);
51
52static cpl_matrix * hdrl_mime_hermite_functions_create(int n, double center,
53 double scale, const cpl_matrix * x);
54
55
56void hdrl_fringe_hermite_test(void)
57{
58 cpl_matrix *x;
59 cpl_matrix *f;
60 cpl_matrix *funs;
61 cpl_matrix *coeffs;
62 cpl_matrix *hseries;
63
64 double w, a, b;
65 double center, scale;
66 int i, n;
67 int nfun;
68
69
70 /* setting parameters:
71 n number of equispaced nodes
72 a, b endpoints of the interval of integration
73 nfun number of the Hermite functions
74 center center of the Hermite functions
75 scale scaling of the Hermite functions
76 */
77 n = 10000;
78 a = -50.0;
79 b = 50.0;
80
81 nfun = 20;
82 center = 0.1;
83 scale = 1.3;
84
85 /* creating the equispaced nodes and weights */
87 cpl_test_nonnull(x);
88 w = (b - a) / (n - 1);
89
90 /* creating the values of a test function */
91 f = cpl_matrix_new(n, 1);
92 cpl_test_nonnull(f);
93 for (i = 0; i < n; i++)
94 {
95 double xi = (cpl_matrix_get_data(x))[i];
96 (cpl_matrix_get_data(f))[i] = (1.0 + xi) * exp(-0.5 * xi * xi);
97 }
98
99 /* test improper inputs are properly handled */
100 funs = hdrl_mime_hermite_functions_create(nfun, center, scale, NULL);
101 cpl_test_null(funs);
102 cpl_test_error(CPL_ERROR_NULL_INPUT);
103 funs = hdrl_mime_hermite_functions_create(0, center, scale, x);
104 cpl_test_null(funs);
105 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
106 funs = hdrl_mime_hermite_functions_create(nfun, center, 0.0, x);
107 cpl_test_null(funs);
108 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
109 funs = hdrl_mime_hermite_functions_create(nfun, center, -1.0, x);
110 cpl_test_null(funs);
111 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
112
113 /* test functionality is working */
114 funs = hdrl_mime_hermite_functions_create(nfun, center, scale, x);
115 cpl_test_nonnull(funs);
116 cpl_test_error(CPL_ERROR_NONE);
117
118 /* computing the Hermite coefficients of the function */
120 cpl_test_nonnull(coeffs);
121 cpl_test_error(CPL_ERROR_NONE);
122 cpl_test_eq(cpl_matrix_multiply_scalar(coeffs, w), CPL_ERROR_NONE);
123
124
125 /* Test error handling of hdrl_mime_hermite_series_create. */
126 hseries = hdrl_mime_hermite_series_create(nfun, center, scale, NULL, x);
127 cpl_test_null(hseries);
128 cpl_test_error(CPL_ERROR_NULL_INPUT);
129 hseries = hdrl_mime_hermite_series_create(nfun, center, scale, coeffs, NULL);
130 cpl_test_null(hseries);
131 cpl_test_error(CPL_ERROR_NULL_INPUT);
132 hseries = hdrl_mime_hermite_series_create(nfun, center, scale, NULL, NULL);
133 cpl_test_null(hseries);
134 cpl_test_error(CPL_ERROR_NULL_INPUT);
135 hseries = hdrl_mime_hermite_series_create(0, center, scale, coeffs, x);
136 cpl_test_null(hseries);
137 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
138 hseries = hdrl_mime_hermite_series_create(nfun, center, -1.0, coeffs, x);
139 cpl_test_null(hseries);
140 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
141 hseries = hdrl_mime_hermite_series_create(nfun, center, 0.0, coeffs, x);
142 cpl_test_null(hseries);
143 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
144
145 /* comparing with the last partial sum */
146 hseries = hdrl_mime_hermite_series_create(nfun, center, scale, coeffs, x);
147 cpl_test_nonnull(hseries);
148 cpl_test_error(CPL_ERROR_NONE);
149 cpl_test_eq(cpl_matrix_subtract(hseries, f), CPL_ERROR_NONE);
150
151 /* cleaning up */
152 cpl_matrix_delete(x);
153 cpl_matrix_delete(f);
154 cpl_matrix_delete(funs);
155 cpl_matrix_delete(coeffs);
156 cpl_matrix_delete(hseries);
157}
158
159
160void test_fringe_mime_gmx1(void)
161{
162 double x[1];
163 double params[6];
164 double result[6];
165 double y;
166
167/* setting parameters */
168 params[0] = 1.0;
169 params[1] = 2.0;
170 params[2] = sqrt(0.5);
171
172 params[3] = 0.0;
173 params[4] = 2.0;
174 params[5] = sqrt(0.5);
175
176/* testing the values */
177 x[0] = 1.0;
178 hdrl_mime_gmix1(x, params, &y);
179 cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15);
180
181 x[0] = 2.0;
182 hdrl_mime_gmix1(x, params, &y);
183 cpl_test_leq(fabs(y - 1.0), 1e-15);
184
185 x[0] = 3.0;
186 hdrl_mime_gmix1(x, params, &y);
187 cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15);
188
189 hdrl_mime_gmix_derivs1(x, params, result);
190 cpl_test_leq(fabs(result[0] - 3.678794411714423e-01), 1e-15);
191 cpl_test_leq(fabs(result[1] - 7.357588823428847e-01), 1e-15);
192 cpl_test_leq(fabs(result[2] - 1.040520190045778e+00), 1e-15);
193 cpl_test_leq(fabs(result[3] - 3.678794411714423e-01), 1e-15);
194 cpl_test_zero(result[4]);
195 cpl_test_zero(result[5]);
196
197/* setting another set of parameters */
198 params[0] = 0.0;
199 params[1] = 2.0;
200 params[2] = sqrt(0.5);
201
202 params[3] = 1.0;
203 params[4] = 2.0;
204 params[5] = sqrt(0.5);
205
206/* testing the values */
207 x[0] = 1.0;
208 hdrl_mime_gmix1(x, params, &y);
209 cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15);
210
211 x[0] = 2.0;
212 hdrl_mime_gmix1(x, params, &y);
213 cpl_test_leq(fabs(y - 1.0), 1e-15);
214
215 x[0] = 3.0;
216 hdrl_mime_gmix1(x, params, &y);
217 cpl_test_leq(fabs(y - 3.678794411714423e-01), 1e-15);
218
219 hdrl_mime_gmix_derivs1(x, params, result);
220 cpl_test_leq(fabs(result[0] - 3.678794411714423e-01), 1e-15);
221 cpl_test_zero(result[1]);
222 cpl_test_zero(result[2]);
223 cpl_test_leq(fabs(result[3] - 3.678794411714423e-01), 1e-15);
224 cpl_test_leq(fabs(result[4] - 7.357588823428847e-01), 1e-15);
225 cpl_test_leq(fabs(result[5] - 1.040520190045778e+00), 1e-15);
226
227}
228
229/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248static cpl_matrix * hdrl_mime_hermite_functions_create(int n, double center,
249 double scale, const cpl_matrix * x)
250{
251 cpl_matrix *funs;
252 double *m;
253 const double *mx;
254 double rt, xi;
255 int i, j, nr;
256
257
258 /* testing input */
259 cpl_ensure(x, CPL_ERROR_NULL_INPUT, NULL);
260
261 if (n < 1 || scale <= 0.0)
262 {
263 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
264 return NULL;
265 }
266
267/* The specific dimensions of the matrix x are not used, only its size. */
268 nr = cpl_matrix_get_nrow(x) * cpl_matrix_get_ncol(x);
269
270/* allocating memory */
271 funs = cpl_matrix_new(nr, n);
272
273/* computing the normalization constant */
274 rt = 1.0 / sqrt(sqrt(CPL_MATH_PI));
275
276/* filling the first column */
277 m = cpl_matrix_get_data(funs);
278 mx = cpl_matrix_get_data_const(x);
279 for (i = 0; i < nr; i++, m += n)
280 {
281 xi = (mx[i] - center) / scale;
282 m[0] = rt * exp(-0.5 * xi * xi);
283 }
284
285/* filling the second column */
286 m = cpl_matrix_get_data(funs);
287 mx = cpl_matrix_get_data_const(x);
288
289 for (i = 0; i < nr; i++, m += n)
290 {
291 xi = (mx[i] - center) / scale;
292 m[1] = rt * sqrt(2.0) * xi * exp(-0.5 * xi * xi);
293 }
294
295/* filling the remaining columns by recursion */
296 m = cpl_matrix_get_data(funs);
297 for (i = 0; i < nr; i++, m += n)
298 {
299 xi = (mx[i] - center) / scale;
300 for (j = 2; j < n; j++)
301 {
302 m[j] = sqrt(2.0) * xi * m[j - 1] - sqrt(j - 1) * m[j - 2];
303 m[j] = m[j] / sqrt(j);
304 }
305 }
306
307/* normalizing */
308 cpl_matrix_multiply_scalar(funs, 1 / sqrt(scale));
309
310 return funs;
311}
312
313
314void test_hermite_sum(void)
315{
316 cpl_matrix *x;
317 cpl_matrix *sums;
318
319 double a, b;
320 double center, scale;
321 int n, nfun;
322
323 /* setting parameters:
324 n number of equispaced nodes
325 a, b endpoints of the sampled interval
326 nfun number of the Hermite functions
327 center center of the Hermite functions
328 scale scaling of the Hermite functions
329 */
330 n = 6;
331 a = 0.0;
332 b = 5.0;
333
334 nfun = 5;
335 center = 0.5;
336 scale = 1.3;
337
338 /* creating the equispaced nodes and weights */
340 cpl_test_nonnull(x);
341
342 /* Test error handling. */
343 sums = hdrl_mime_hermite_functions_sums_create(nfun, center, scale, NULL);
344 cpl_test_null(sums);
345 cpl_test_error(CPL_ERROR_NULL_INPUT);
346 sums = hdrl_mime_hermite_functions_sums_create(0, center, scale, x);
347 cpl_test_null(sums);
348 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
349 sums = hdrl_mime_hermite_functions_sums_create(nfun, center, 0.0, x);
350 cpl_test_null(sums);
351 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
352 sums = hdrl_mime_hermite_functions_sums_create(nfun, center, -1.0, x);
353 cpl_test_null(sums);
354 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
355
356 /* creating sums of the Hermite functions */
357 sums = hdrl_mime_hermite_functions_sums_create(nfun, center, scale, x);
358 cpl_test_nonnull(sums);
359 cpl_test_error(CPL_ERROR_NONE);
360
361 cpl_test_leq(fabs(cpl_matrix_get(sums, 0, 0) - 1.685081590066050e+00),
362 1e-15);
363 cpl_test_leq(fabs(cpl_matrix_get(sums, 1, 0) - 9.093843925414908e-01),
364 1e-15);
365 cpl_test_leq(fabs(cpl_matrix_get(sums, 2, 0) - 4.521636055506448e-01),
366 1e-15);
367 cpl_test_leq(fabs(cpl_matrix_get(sums, 3, 0) - 8.130124958110769e-01),
368 1e-15);
369 cpl_test_leq(fabs(cpl_matrix_get(sums, 4, 0) - 8.013868548156017e-01),
370 1e-15);
371
372 /* cleaning up */
373 cpl_matrix_delete(x);
374 cpl_matrix_delete(sums);
375
376
377}
378
379
380void hdrl_fringe_compute_test_input(void)
381{
382 cpl_size nx = 21;
383 cpl_size ny= 32;
384 hdrl_parameter * collapse_params;
385 collapse_params = hdrl_collapse_mean_parameter_create();
386
387 hdrl_imagelist * ilist_fringe = hdrl_imagelist_new();
388 cpl_imagelist * ilist_obj = cpl_imagelist_new();
389 cpl_mask * stat_mask = cpl_mask_new(nx, ny);
390
391 hdrl_image * master;
392 cpl_image * contrib_map;
393
394 hdrl_image * hima1 = hdrl_image_new(nx, ny);
395 hdrl_image * hima2 = hdrl_image_new(nx, ny);
396 hdrl_image * hima_dimen1 = hdrl_image_new(nx+5, ny+10);
397 hdrl_image * hima_dimen2 = hdrl_image_new(nx+5, ny+10);
398
399 cpl_image * cima1 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
400 cpl_image * cima2 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
401
402 hdrl_image_add_scalar(hima1, (hdrl_value){1., 0.1});
403 hdrl_image_add_scalar(hima2, (hdrl_value){10., 1.});
404 cpl_image_add_scalar(cima1, 1.);
405 cpl_image_add_scalar(cima2, 10.);
406
407
408 hdrl_fringe_compute(NULL, ilist_obj, stat_mask, collapse_params,
409 &master, &contrib_map, NULL);
410 cpl_test_error(CPL_ERROR_NULL_INPUT);
411 cpl_test_null(master);
412 cpl_test_null(contrib_map);
413
414 cpl_table *qctable = (cpl_table*)0xbadbeef;
415 hdrl_fringe_compute(NULL, ilist_obj, stat_mask, collapse_params,
416 &master, &contrib_map, &qctable);
417 cpl_test_error(CPL_ERROR_NULL_INPUT);
418 cpl_test_null(master);
419 cpl_test_null(contrib_map);
420
421 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, NULL,
422 &master, &contrib_map, NULL);
423 cpl_test_error(CPL_ERROR_NULL_INPUT);
424 cpl_test_null(master);
425 cpl_test_null(contrib_map);
426
427 hdrl_imagelist_set(ilist_fringe, hima1, 0);
428 hdrl_imagelist_set(ilist_fringe, hima2, 1);
429 cpl_imagelist_set(ilist_obj, cima1, 0);
430 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params,
431 &master, &contrib_map, NULL);
432 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
433 cpl_test_null(master);
434 cpl_test_null(contrib_map);
435 cpl_imagelist_set(ilist_obj, cima2, 1);
436
437
438 hima2 = hdrl_imagelist_unset(ilist_fringe, 1);
439 hima1 = hdrl_imagelist_unset(ilist_fringe, 0);
440 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params,
441 &master, &contrib_map, NULL);
442 cpl_test_error(CPL_ERROR_NULL_INPUT);
443 cpl_test_null(master);
444 cpl_test_null(contrib_map);
445
446 /* Images in ilist_fringe and ilist_obj have now different dimensions */
447 hdrl_imagelist_set(ilist_fringe, hima_dimen1, 0);
448 hdrl_imagelist_set(ilist_fringe, hima_dimen2, 1);
449
450 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params,
451 &master, &contrib_map, NULL);
452 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
453 cpl_test_null(master);
454 cpl_test_null(contrib_map);
455
456 hima_dimen2 = hdrl_imagelist_unset(ilist_fringe, 1);
457 hima_dimen1 = hdrl_imagelist_unset(ilist_fringe, 0);
458
459 /*
460 cpl_msg_warning(cpl_func,"ilist_fringe=%p",ilist_fringe);
461 cpl_msg_warning(cpl_func,"ilist_obj=%p",ilist_obj);
462 cpl_msg_warning(cpl_func,"stat mask=%p",stat_mask);
463 cpl_msg_warning(cpl_func,"collapse params=%p",collapse_params);
464 cpl_msg_warning(cpl_func,"master=%p",master);
465 cpl_msg_warning(cpl_func,"contrib map=%p",contrib_map);
466 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params,
467 &master, &contrib_map);
468 cpl_test_error(CPL_ERROR_NONE);
469 cpl_test_nonnull(master);
470 cpl_test_nonnull(contrib_map);
471 hdrl_image_delete(master);
472 cpl_image_delete(contrib_map);
473 */
474
475 /* Test for success when computing a master fringe just from two frames
476 without any object or static masks. */
477 hdrl_imagelist_set(ilist_fringe, hima1, 0);
478 hdrl_imagelist_set(ilist_fringe, hima2, 1);
479 hdrl_fringe_compute(ilist_fringe, NULL, NULL, collapse_params,
480 &master, &contrib_map, NULL);
481 cpl_test_error(CPL_ERROR_NONE);
482 cpl_test_nonnull(master);
483 cpl_test_nonnull(contrib_map);
484 hdrl_image_delete(master);
485 cpl_image_delete(contrib_map);
486
487 /* Final cleanup */
488 hdrl_image_delete(hima_dimen1);
489 hdrl_image_delete(hima_dimen2);
490 hdrl_imagelist_delete(ilist_fringe);
491 cpl_imagelist_delete(ilist_obj);
492 hdrl_parameter_delete(collapse_params);
493 cpl_mask_delete(stat_mask);
494}
495
496
497void hdrl_fringe_correct_test_input(void)
498{
499 cpl_size nx = 21;
500 cpl_size ny= 32;
501
502 hdrl_imagelist * ilist_fringe = hdrl_imagelist_new();
503 cpl_imagelist * ilist_obj = cpl_imagelist_new();
504 cpl_mask * stat_mask = cpl_mask_new(nx, ny);
505
506 hdrl_image * masterfringe = hdrl_image_new(nx, ny);;
507
508
509 hdrl_image * hima1 = hdrl_image_new(nx, ny);
510 hdrl_image * hima2 = hdrl_image_new(nx, ny);
511
512 hdrl_image * hima_dimen1 = hdrl_image_new(nx+5, ny+10);
513 hdrl_image * hima_dimen2 = hdrl_image_new(nx+5, ny+10);
514
515 cpl_image * cima1 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
516 cpl_image * cima2 = cpl_image_new(nx, ny, CPL_TYPE_FLOAT);
517
518 hdrl_image_add_scalar(hima1, (hdrl_value){1., 0.1});
519 hdrl_image_add_scalar(hima2, (hdrl_value){10., 1.});
520 cpl_image_add_scalar(cima1, 1.);
521 cpl_image_add_scalar(cima2, 10.);
522
523
524 hdrl_fringe_correct(NULL, ilist_obj, stat_mask, masterfringe, NULL);
525 cpl_test_error(CPL_ERROR_NULL_INPUT);
526
527 hdrl_imagelist_set(ilist_fringe, hima1, 0);
528 hdrl_imagelist_set(ilist_fringe, hima2, 1);
529 cpl_imagelist_set(ilist_obj, cima1, 0);
530 hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL);
531 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
532 cpl_imagelist_set(ilist_obj, cima2, 1);
533
534
535 hima2 = hdrl_imagelist_unset(ilist_fringe, 1);
536 hima1 = hdrl_imagelist_unset(ilist_fringe, 0);
537 hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL);
538 cpl_test_error(CPL_ERROR_NULL_INPUT);
539
540 /* Images in ilist_fringe and ilist_obj have now different dimensions */
541 hdrl_imagelist_set(ilist_fringe, hima_dimen1, 0);
542 hdrl_imagelist_set(ilist_fringe, hima_dimen2, 1);
543
544 hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL);
545 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
546
547 hima_dimen2 = hdrl_imagelist_unset(ilist_fringe, 1);
548 hima_dimen1 = hdrl_imagelist_unset(ilist_fringe, 0);
549
550 hdrl_imagelist_set(ilist_fringe, hima1, 0);
551 hdrl_imagelist_set(ilist_fringe, hima2, 1);
552
553 hdrl_fringe_correct(ilist_fringe, ilist_obj, stat_mask, masterfringe, NULL);
554 cpl_test_error(CPL_ERROR_NONE);
555
556 hdrl_fringe_correct(ilist_fringe, ilist_obj, NULL, masterfringe, NULL);
557 cpl_test_error(CPL_ERROR_NONE);
558
559 hdrl_fringe_correct(ilist_fringe, NULL, NULL, masterfringe, NULL);
560 cpl_test_error(CPL_ERROR_NONE);
561
562
563 /* now we add real data: two frames with Poisson noise centred at different levels */
564 cpl_size sizex = hdrl_image_get_size_x(hima1);
565 cpl_size sizey = hdrl_image_get_size_y(hima1);
566 hdrl_random_state * rng = hdrl_random_state_new(1, NULL);
567
568 cpl_image *cplima1 = hdrl_image_get_image(hima1);
569 cpl_image *cplima2 = hdrl_image_get_image(hima2);
570
571 for(cpl_size i = 1; i <= sizex; i++) {
572 for(cpl_size j = 1; j <= sizey; j++) {
573 cpl_image_set(cplima1, i, j, (double)hdrl_random_poisson(rng, 100.));
574 cpl_image_set(cplima2, i, j, (double)hdrl_random_poisson(rng, 200.));
575 }
576 }
577
578 hdrl_random_state_delete(rng);
579 float* pobj = cpl_image_get_data_float(cima1);
580 int sx = cpl_image_get_size_x(cima1);
581 int sy = cpl_image_get_size_y(cima1);
582 int i_min = 0.25 * sx;
583 int i_max = 0.75 * sx;
584 int j_min = 0.25 * sy;
585 int j_max = 0.75 * sy;
586
587 for(int j = j_min; j < j_max; j++) {
588 for(int i = i_min; i < i_max; i++) {
589 pobj[j*sx+i] = 0;
590 }
591 }
592
593 pobj = cpl_image_get_data_float(cima2);
594 for(int j = j_min; j < j_max; j++) {
595 for(int i = i_min; i < i_max; i++) {
596 pobj[j*sx+i] = 0;
597 }
598 }
599 i_min = 0.1 * sx;
600 i_max = 0.2 * sx;
601 j_min = 0.1 * sy;
602 j_max = 0.2 * sy;
603
604 cpl_binary* pmask = cpl_mask_get_data(stat_mask);
605
606 for(int j = j_min; j < j_max; j++) {
607 for(int i = i_min; i < i_max; i++) {
608 pmask[j*sx+i] = 0;
609 }
610 }
611
612
613 cpl_image* contrib_map=NULL;
614 hdrl_parameter * collapse_params;
615 collapse_params = hdrl_collapse_mean_parameter_create();
616 hdrl_image_delete(masterfringe);
617 hdrl_fringe_compute(ilist_fringe, ilist_obj, stat_mask, collapse_params,
618 &masterfringe, &contrib_map, NULL);
619 hdrl_fringe_correct(ilist_fringe, NULL, NULL, masterfringe, NULL);
620 cpl_test_error(CPL_ERROR_NONE);
621
622 /* Final cleanup */
623 hdrl_image_delete(hima_dimen1);
624 hdrl_image_delete(hima_dimen2);
625 hdrl_imagelist_delete(ilist_fringe);
626 cpl_imagelist_delete(ilist_obj);
627 hdrl_parameter_delete(collapse_params);
628 cpl_image_delete(contrib_map);
629
630 cpl_mask_delete(stat_mask);
631 hdrl_image_delete(masterfringe);
632
633}
634
635
636void hdrl_mime_fringe_amplitudes_test(void)
637{
638 cpl_matrix * matrix;
639 cpl_image * image_double = cpl_image_new(10, 10, CPL_TYPE_DOUBLE);
640 cpl_image * image_float = cpl_image_new(10, 10, CPL_TYPE_FLOAT);
641 cpl_mask * mask = cpl_mask_new(10, 10);
642
643 /* The following test are to check correct error handling for invalid
644 input. */
645 matrix = hdrl_mime_fringe_amplitudes(NULL, NULL);
646 cpl_test_error(CPL_ERROR_NULL_INPUT);
647 cpl_test_null(matrix);
648
649 matrix = hdrl_mime_fringe_amplitudes(image_double, NULL);
650 cpl_test_error(CPL_ERROR_NULL_INPUT);
651 cpl_test_null(matrix);
652
653 matrix = hdrl_mime_fringe_amplitudes(NULL, mask);
654 cpl_test_error(CPL_ERROR_NULL_INPUT);
655 cpl_test_null(matrix);
656
657 /* Check handling of input images that are not doubles. */
658 matrix = hdrl_mime_fringe_amplitudes(image_float, mask);
659 cpl_test_error(CPL_ERROR_INVALID_TYPE);
660 cpl_test_null(matrix);
661
662 /* Check handling of input when nothing is marked in the mask. */
663 cpl_mask_not(mask);
664 cpl_test_error(CPL_ERROR_NONE);
665 matrix = hdrl_mime_fringe_amplitudes(image_double, mask);
666 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
667 cpl_test_null(matrix);
668
669 cpl_mask_delete(mask);
670 cpl_image_delete(image_float);
671 cpl_image_delete(image_double);
672}
673
674
675void hdrl_mime_fringe_amplitudes_ls_test(void)
676{
677 cpl_matrix * matrix;
678 cpl_image * image_double1 = cpl_image_new(10, 10, CPL_TYPE_DOUBLE);
679 cpl_image * image_double2 = cpl_image_new(10, 10, CPL_TYPE_DOUBLE);
680 cpl_image * image_float = cpl_image_new(10, 10, CPL_TYPE_FLOAT);
681 cpl_mask * mask = cpl_mask_new(10, 10);
682
683 /* The following test are to check correct error handling for invalid
684 input. */
685 matrix = hdrl_mime_fringe_amplitudes_ls(NULL, NULL, NULL);
686 cpl_test_error(CPL_ERROR_NULL_INPUT);
687 cpl_test_null(matrix);
688
689 matrix = hdrl_mime_fringe_amplitudes_ls(NULL, mask, image_double2);
690 cpl_test_error(CPL_ERROR_NULL_INPUT);
691 cpl_test_null(matrix);
692
693 matrix = hdrl_mime_fringe_amplitudes_ls(image_double1, NULL, image_double2);
694 cpl_test_error(CPL_ERROR_NULL_INPUT);
695 cpl_test_null(matrix);
696
697 matrix = hdrl_mime_fringe_amplitudes_ls(image_double1, mask, NULL);
698 cpl_test_error(CPL_ERROR_NULL_INPUT);
699 cpl_test_null(matrix);
700
701 /* Check handling of input images that are not doubles. */
702 matrix = hdrl_mime_fringe_amplitudes_ls(image_float, mask, image_double2);
703 cpl_test_error(CPL_ERROR_INVALID_TYPE);
704 cpl_test_null(matrix);
705
706 matrix = hdrl_mime_fringe_amplitudes_ls(image_double1, mask, image_float);
707 cpl_test_error(CPL_ERROR_INVALID_TYPE);
708 cpl_test_null(matrix);
709
710 /* Check handling of input when nothing is marked in the mask. */
711 cpl_mask_not(mask);
712 cpl_test_error(CPL_ERROR_NONE);
713 matrix = hdrl_mime_fringe_amplitudes_ls(image_double1, mask, image_double2);
714 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
715 cpl_test_null(matrix);
716
717 cpl_mask_delete(mask);
718 cpl_image_delete(image_float);
719 cpl_image_delete(image_double2);
720 cpl_image_delete(image_double1);
721}
722
723
724
725/*----------------------------------------------------------------------------*/
729/*----------------------------------------------------------------------------*/
730int main(void)
731{
732 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
733
734 hdrl_fringe_hermite_test();
735 test_fringe_mime_gmx1();
736 test_hermite_sum();
737 hdrl_fringe_compute_test_input(); //problem testing proper inputs
738 hdrl_fringe_correct_test_input(); //problem testing proper inputs
739 hdrl_mime_fringe_amplitudes_test();
740 hdrl_mime_fringe_amplitudes_ls_test();
741
742 test_hermite_sum();
743 return cpl_test_end(0);
744
745}
hdrl_parameter * hdrl_collapse_mean_parameter_create(void)
create a parameter object for mean
cpl_error_code hdrl_fringe_correct(hdrl_imagelist *ilist_fringe, const cpl_imagelist *ilist_obj, const cpl_mask *stat_mask, const hdrl_image *masterfringe, cpl_table **qctable)
Scales and subtracts the master fringe from the images.
cpl_error_code hdrl_fringe_compute(hdrl_imagelist *ilist_fringe, const cpl_imagelist *ilist_obj, const cpl_mask *stat_mask, const hdrl_parameter *collapse_params, hdrl_image **master, cpl_image **contrib_map, cpl_table **qctable)
Calculates the master fringe and contribution map based on the.
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
cpl_size hdrl_image_get_size_y(const hdrl_image *self)
return size of Y dimension of image
Definition hdrl_image.c:540
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
Definition hdrl_image.c:525
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition hdrl_image.c:105
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
Definition hdrl_image.c:311
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition hdrl_image.c:379
hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *himlist, cpl_size pos)
Remove an image from an imagelist.
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
cpl_matrix * hdrl_mime_matrix_product_left_transpose_create(const cpl_matrix *mat1, const cpl_matrix *mat2)
Create the product of the transpose of a matrix with another matrix.
cpl_matrix * hdrl_mime_matrix_linspace_create(int n, double a, double b)
Create equally spaced nodes.