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