CR2RE Pipeline Reference Manual 1.6.2
hdrl_image-test.c
1/* $Id: hdrl_image-test.c,v 1.5 2013-10-23 09:13:56 jtaylor Exp $
2 *
3 * This file is part of the HDRL
4 * Copyright (C) 2013 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: jtaylor $
23 * $Date: 2013-10-23 09:13:56 $
24 * $Revision: 1.5 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*-----------------------------------------------------------------------------
33 Includes
34 -----------------------------------------------------------------------------*/
35
36#include "hdrl_image.h"
37#include "hdrl_test.h"
38#include "hdrl_imagelist.h"
39#include "hdrl_buffer.h"
40#include "hdrl_types.h"
41
42#include <cpl.h>
43
44#include <math.h>
45#include <float.h>
46#include <stdlib.h>
47#include <stdio.h>
48
49#include <limits.h>
50
51#ifndef ARRAY_LEN
52#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
53#endif
54
55/*----------------------------------------------------------------------------*/
60/*----------------------------------------------------------------------------*/
61
62static void test_basic(void)
63{
64 hdrl_image * img;
65 cpl_image * cimg, * cerr;
66 cpl_error_code error;
67
69
70 /* empty creation */
71
72 img = hdrl_image_new(5, 5);
73 cpl_test_nonnull(img);
74 cpl_test_error(CPL_ERROR_NONE);
76
77 img = hdrl_image_new(0, 5);
78 cpl_test_null(img);
79 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
80
81 img = hdrl_image_new(5, 0);
82 cpl_test_null(img);
83 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
84
85 img = hdrl_image_new(0, 0);
86 cpl_test_null(img);
87 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
88
89 img = hdrl_image_create(NULL, NULL);
90 cpl_test_null(img);
91 cpl_test_error(CPL_ERROR_NULL_INPUT);
92
93 /* creation with cpl image */
94
95 cimg = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
96 cerr = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
97
98 img = hdrl_image_create(NULL, cerr);
99 cpl_test_null(img);
100 cpl_test_error(CPL_ERROR_NULL_INPUT);
101
102 img = hdrl_image_create(cimg, NULL);
103 cpl_test_nonnull(img);
105
106 img = hdrl_image_create(cimg, cerr);
107 cpl_test_nonnull(img);
108
109 /* dump the structure */
110 error = hdrl_image_dump_structure(img, stderr);
111 cpl_test_eq_error(error, CPL_ERROR_NONE);
112
113 error = hdrl_image_dump_window(img, 1, 1, 3, 3, stderr);
114 cpl_test_eq_error(error, CPL_ERROR_NONE);
115
117
118 /* with bpm */
119
120 cpl_image_reject(cimg, 2, 3);
121 img = hdrl_image_create(cimg, cerr);
122 cpl_test_nonnull(img);
123 cpl_test_eq(hdrl_image_count_rejected(img), 1);
125
126 cpl_image_reject(cerr, 2, 3);
127 img = hdrl_image_create(cimg, cerr);
128 cpl_test_eq(hdrl_image_count_rejected(img), 1);
129 cpl_test_nonnull(img);
131
132 /* incompatible bpm (emits warning) */
133 cpl_image_reject(cerr, 2, 4);
134 img = hdrl_image_create(cimg, cerr);
135 cpl_test_eq(hdrl_image_count_rejected(img), 1);
136 cpl_test_nonnull(img);
138
139 cpl_image_accept_all(cimg);
140 img = hdrl_image_create(cimg, cerr);
141 cpl_test_eq(hdrl_image_count_rejected(img), 0);
142 cpl_test_nonnull(img);
144
145 cpl_image_delete(cerr);
146 cerr = cpl_image_new(2, 6, CPL_TYPE_DOUBLE);
147 img = hdrl_image_create(cimg, cerr);
148 cpl_test_null(img);
149 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
150
151 cpl_image_delete(cerr);
152 cerr = cpl_image_new(5, 2, CPL_TYPE_DOUBLE);
153 img = hdrl_image_create(cimg, cerr);
154 cpl_test_null(img);
155 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
156
157 /* reject/accept */
158 img = hdrl_image_new(5, 5);
159 hdrl_image_reject(img, 4, 5);
160 cpl_test(hdrl_image_is_rejected(img, 4, 5));
161 hdrl_image_accept(img, 4, 5);
162 cpl_test(!hdrl_image_is_rejected(img, 4, 5));
163
164 hdrl_image_reject(img, 5, 6);
165 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
166 hdrl_image_reject(img, 0, 6);
167 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
168 hdrl_image_accept(img, 6, 5);
169 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
170 hdrl_image_accept(img, 0, 5);
171 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
172
173 hdrl_image_reject(img, 4, 5);
175 cpl_test(!hdrl_image_is_rejected(img, 4, 5));
177
178 cpl_image_delete(cimg);
179 cpl_image_delete(cerr);
180}
181
182static void test_extract(void)
183{
184 cpl_size nx = 5;
185 cpl_size ny = 13;
186 hdrl_image * himg = hdrl_image_new(nx, ny);
187 hdrl_image * ex;
188 hdrl_image_add_scalar(himg, (hdrl_value){1., 1.});
189
190 ex = hdrl_image_extract(himg, 1, 1, nx, ny);
191 cpl_test_nonnull(ex);
192 hdrl_test_image_abs(himg, ex, 0);
194
195 ex = hdrl_image_extract(himg, 1, 1, 0, 0);
196 cpl_test_nonnull(ex);
197 hdrl_test_image_abs(himg, ex, 0);
199
200 ex = hdrl_image_extract(himg, 0, 0, 0, 0);
201 cpl_test_nonnull(ex);
202 cpl_test_eq(hdrl_image_get_size_x(ex), 1);
203 cpl_test_eq(hdrl_image_get_size_y(ex), 1);
205
206 ex = hdrl_image_extract(himg, 2, 2, -1, -1);
207 cpl_test_nonnull(ex);
208 cpl_test_eq(hdrl_image_get_size_x(ex), nx - 2);
209 cpl_test_eq(hdrl_image_get_size_y(ex), ny - 2);
211
212 ex = hdrl_image_extract(himg, 2, 2, -1, 2 * ny);
213 cpl_test_null(ex);
214 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
215
216 ex = hdrl_image_extract(himg, 2, 2, -1, -2 * ny);
217 cpl_test_null(ex);
218 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
219
220 ex = hdrl_image_extract(himg, 2, 2, -2 * nx, -2);
221 cpl_test_null(ex);
222 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
223
224 ex = hdrl_image_extract(himg, 2, -2 * ny, -2, -2);
225 cpl_test_null(ex);
226 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
227
228 ex = hdrl_image_extract(himg, -2 * nx, -2, -2, -2);
229 cpl_test_null(ex);
230 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
231
232 hdrl_image_delete(himg);
233}
234
235static void test_power(void)
236{
237 hdrl_value v;
238 hdrl_image * himg = hdrl_image_new(1, 1);
239 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5});
240 hdrl_image_pow_scalar(himg, (hdrl_value){2., 0.});
241 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
242 cpl_test_rel(v.data, 4., HDRL_EPS_DATA);
243 cpl_test_rel(v.error, 2.0, HDRL_EPS_ERROR);
244
245 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5});
246 hdrl_image_pow_scalar(himg, (hdrl_value){4., 0.});
247 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
248 cpl_test_rel(v.data, 16, HDRL_EPS_DATA);
249 cpl_test_rel(v.error, 16, HDRL_EPS_ERROR);
250
251 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5});
252 hdrl_image_pow_scalar(himg, (hdrl_value){-1., 0.});
253 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
254 cpl_test_rel(v.data, 0.5, HDRL_EPS_DATA);
255 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
256
257 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5});
258 hdrl_image_pow_scalar(himg, (hdrl_value){-2., 0.});
259 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
260 cpl_test_rel(v.data, 0.25, HDRL_EPS_DATA);
261 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR); /* yes the same as ^-1 */
262
263 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.5});
264 hdrl_image_pow_scalar(himg, (hdrl_value){-4., 0.});
265 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
266 cpl_test_rel(v.data, 0.0625, HDRL_EPS_DATA);
267 cpl_test_rel(v.error, 0.0625, HDRL_EPS_ERROR);
268
269 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.3});
270 hdrl_image_pow_scalar(himg, (hdrl_value){-3., 0.0});
271 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
272 cpl_test_rel(v.data, 1.0/8.0, HDRL_EPS_DATA);
273 cpl_test_rel(v.error, 0.05625, HDRL_EPS_ERROR);
274
275 hdrl_image_delete(himg);
276}
277
278static void test_exp(void)
279{
280 hdrl_value v;
281 hdrl_image * himg = hdrl_image_new(1, 1);
282 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){2., 0.0});
283 hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5});
284 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
285 cpl_test_rel(v.data, 4., HDRL_EPS_DATA);
286 cpl_test_rel(v.error, 2.0, HDRL_EPS_ERROR);
287
288
289 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){4., 0.});
290 hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5});
291 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
292 cpl_test_rel(v.data, 16, HDRL_EPS_DATA);
293 cpl_test_rel(v.error, 16, HDRL_EPS_ERROR);
294
295 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-1., 0.});
296 hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5});
297 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
298 cpl_test_rel(v.data, 0.5, HDRL_EPS_DATA);
299 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
300
301 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-2., 0.});
302 hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5});
303 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
304 cpl_test_rel(v.data, 0.25, HDRL_EPS_DATA);
305 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
306
307 hdrl_image_set_pixel(himg, 1, 1, (hdrl_value){-4., 0.});
308 hdrl_image_exp_scalar(himg, (hdrl_value){2., 0.5});
309 v = hdrl_image_get_pixel(himg, 1, 1, NULL);
310 cpl_test_rel(v.data, 0.0625, HDRL_EPS_DATA);
311 cpl_test_rel(v.error, 0.0625, HDRL_EPS_ERROR);
312
313 hdrl_image_delete(himg);
314}
315
316
317static void test_copy(void)
318{
319 hdrl_image * dst = hdrl_image_new(50, 50);
320 hdrl_image * src = hdrl_image_new(30, 30);
321 hdrl_image * expected = hdrl_image_new(50, 50);
322
323 hdrl_image_copy(dst, src, 10, 10);
324 hdrl_test_image_abs(dst, expected, 0);
325
326 hdrl_image_reject(expected, 1, 1);
327 /* bypass hdrl_image functions */
328 cpl_image_reject(hdrl_image_get_image(src), 1, 1);
329
330 hdrl_image_copy(dst, src, 10, 10);
331 hdrl_test_image_abs(dst, expected, 0);
332
335 hdrl_image_delete(expected);
336}
337
338static void test_insert(void)
339{
340 hdrl_image * dst = hdrl_image_new(50, 50);
341 hdrl_image * dst2 = hdrl_image_new(50, 50);
342 cpl_image * im1 = cpl_image_new(50, 50, HDRL_TYPE_DATA);
343 cpl_image * im2 = cpl_image_new(50, 50, HDRL_TYPE_ERROR);
344 hdrl_image * him = hdrl_image_create(im1, im2);
345 cpl_image_reject(im1, 1, 1);
346 hdrl_image_reject(him, 1, 1);
347
348 hdrl_image_copy(dst2, him, 1, 1);
349 hdrl_image_insert(dst, im1, im2, 1, 1);
350 hdrl_test_image_abs(dst, dst2, 0);
351
352 hdrl_image_insert(dst, im1, NULL, 1, 1);
353 hdrl_test_image_abs(dst, dst2, 0);
354
356 hdrl_image_delete(dst2);
358 cpl_image_delete(im1);
359 cpl_image_delete(im2);
360}
361
362static void test_reduce(void)
363{
364 {
365 size_t nx = 53, ny = 2310;
366 hdrl_value m;
367 hdrl_image * a = hdrl_image_new(nx, ny);
368 hdrl_image * b = hdrl_image_new(nx, ny);
369 hdrl_image * c = hdrl_image_new(nx, ny);
370 hdrl_imagelist * hl = hdrl_imagelist_new();
371 hdrl_image_add_scalar(a, (hdrl_value){5., 3.2});
372 hdrl_image_add_scalar(b, (hdrl_value){7., 1.2});
373 hdrl_image_add_scalar(b, (hdrl_value){-3., .2});
374
375 m = hdrl_image_get_mean(a);
376 cpl_test_abs(m.data, 5., HDRL_EPS_DATA);
377 cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny);
378
380 cpl_test_abs(m.data, 5., HDRL_EPS_DATA);
381 cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny);
382
383 m = hdrl_image_get_sigclip_mean(a, 3., 3., 100);
384 cpl_test_abs(m.data, 5., HDRL_EPS_DATA);
385 cpl_test_abs(m.error, 3.2 / sqrt(nx * ny), HDRL_EPS_ERROR * nx * ny);
386
387 hdrl_imagelist_set(hl, a, 0);
388 hdrl_imagelist_set(hl, b, 1);
389 hdrl_imagelist_set(hl, c, 2);
390 hdrl_image * r;
391 cpl_image * con;
392
393 /* must be equivalent */
394 hdrl_imagelist_collapse_mean(hl, &r, &con);
397 hdrl_image_div_scalar(a, (hdrl_value){3., 0.});
398 hdrl_test_image_abs(a, r, HDRL_EPS_DATA);
399
401 cpl_image_delete(con);
403 }
404 { /* Test sigmaclipped mean */
405 hdrl_value m;
406 /* gauss mean 100 sigma 3.5 and 2 outliers */
407 double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97,
408 97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
409 99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
410 102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
411 104, 105, 105, 106, 106, 107, 108, 500, 600 };
412
413 cpl_image * data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values);
414 cpl_image * errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE);
415 cpl_image_add_scalar(errors, 1);
416
417 cpl_image_set(errors, 7, 7, 100000.);
418 cpl_image_set(errors, 6, 7, 10000.);
419
420 hdrl_image * sigimage = hdrl_image_create(data, errors);
421
422 m = hdrl_image_get_sigclip_mean(sigimage, 3., 3., 100);
423 cpl_test_rel(m.data, 100., HDRL_EPS_DATA * 49);
424 cpl_test_rel(m.error, 1 / sqrt(7 * 7 - 2), HDRL_EPS_ERROR * 49);
425 cpl_image_unwrap(data);
426 cpl_image_delete(errors);
427 hdrl_image_delete(sigimage);
428 }
429 { /* Test minmax rejected mean */
430 hdrl_value m;
431 /* gauss mean 100 sigma 3.5 and 2 outliers */
432 double values[] = {-100000, 93, 94, 94, 95, 95, 96, 96, 96, 97,
433 97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
434 99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
435 102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
436 104, 105, 105, 106, 106, 107, 108, 100000, 500000 };
437
438 cpl_image * data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values);
439 cpl_image * errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE);
440 cpl_image_add_scalar(errors, 1);
441
442 cpl_image_set(errors, 7, 7,100000.);
443 cpl_image_set(errors, 6, 7,10000.);
444 cpl_image_set(errors, 1, 1,1000.);
445
446 /*cpl_image_save(data,"data.fits", CPL_TYPE_FLOAT, NULL,
447 CPL_IO_CREATE);
448 cpl_image_save(errors,"errors.fits", CPL_TYPE_FLOAT, NULL,
449 CPL_IO_CREATE);*/
450
451 hdrl_image * minmaximage = hdrl_image_create(data, errors);
452
453 m = hdrl_image_get_minmax_mean(minmaximage, 0, 0);
454 cpl_test_rel(m.data, 10298.122448979591, HDRL_EPS_DATA * 49);
455 m = hdrl_image_get_minmax_mean(minmaximage, 0, 1);
456 cpl_test_rel(m.data, 96.0, 0.005);
457 m = hdrl_image_get_minmax_mean(minmaximage, 0, 2);
458 cpl_test_rel(m.data, -2029.6170212765958, HDRL_EPS_DATA * 49);
459 m = hdrl_image_get_minmax_mean(minmaximage, 1, 2);
460 cpl_test_rel(m.data, 100.17391304347827, HDRL_EPS_DATA * 49);
461
462 hdrl_image_delete(minmaximage);
463 cpl_image_delete(errors);
464 cpl_image_unwrap(data);
465 }
466 /* test sum, sqsum */
467 {
468 size_t nx = 3, ny = 1;
469 hdrl_value m;
470 hdrl_image * a = hdrl_image_new(nx, ny);
471 hdrl_image_set_pixel(a, 1, 1, (hdrl_value){1 , 0.5});
472 hdrl_image_set_pixel(a, 2, 1, (hdrl_value){2., 1.5});
473 hdrl_image_set_pixel(a, 3, 1, (hdrl_value){3., 2.5});
474 hdrl_image_reject(a, 1, 1);
475
476 m = hdrl_image_get_sum(NULL);
477 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
478 cpl_test(isnan(m.data) && isnan(m.error));
479
480 m = hdrl_image_get_sum(a);
481 cpl_test_error(CPL_ERROR_NONE);
482 cpl_test(!isnan(m.data) && !isnan(m.error));
483
484 cpl_test_abs(m.data, 5., HDRL_EPS_DATA);
485 cpl_test_abs(m.error, sqrt(1.5 * 1.5 + 2.5 * 2.5), HDRL_EPS_ERROR * 3);
486
488 cpl_test_abs(m.data, 4. + 9., HDRL_EPS_DATA);
489 cpl_test_abs(m.error, 16.15549442140351, HDRL_EPS_ERROR * 6);
491 }
492}
493
494static inline void test_buffer(void)
495{
496 hdrl_buffer *buf = hdrl_buffer_new();
497 hdrl_imagelist *hl = hdrl_imagelist_new();
498
499#if (__WORDSIZE == 64)
500
501 cpl_size iMax = 100; /* Previously = 900 */
502 cpl_size sizeImg = 64; /* Previously = 500 */
503
504 for (cpl_size i = 0; i < iMax; i++) {
505 hdrl_image * img = hdrl_image_new_from_buffer(sizeImg, sizeImg, buf);
506 hdrl_imagelist_set(hl, img, i);
507 hdrl_image_add_scalar(img, (hdrl_value){1, 1});
508 }
509 cpl_msg_warning(cpl_func, "alloc done");
510
511 hdrl_image *m;
512 cpl_image *c;
515 cpl_image_delete(c);
516 cpl_msg_warning(cpl_func, "collapse done");
517
518
519#endif
520
521
523
524 hdrl_buffer_delete(buf);
525}
526
527static void test_create(void)
528{
529 /* Create reference images */
530 size_t nx = 10;
531 size_t ny = 100;
532 hdrl_image *a = hdrl_image_new(nx, ny);
533 hdrl_image *b = hdrl_image_new(nx, ny);
534
535 /* Reject value */
536 hdrl_image_reject_value(a, CPL_VALUE_NAN);
537 hdrl_image_reject_value(b, CPL_VALUE_NAN);
538
539 /* Add information */
540 hdrl_value hValue = {2., 0.5};
541 hdrl_image_add_scalar(a, hValue);
542 hdrl_image_add_scalar(b, hValue);
543
544 hdrl_image *new1;
545 hdrl_image *new2;
546 hdrl_image *new3;
547 hdrl_image *new4;
548 hdrl_image *new5;
549 hdrl_image *new6;
550
551 /* Basic operations */
552
553 new1 = hdrl_image_add_image_create(NULL, b);
554 cpl_test_error(CPL_ERROR_NULL_INPUT);
555 cpl_test_null(new1);
556 new1 = hdrl_image_add_image_create(a, NULL);
557 cpl_test_error(CPL_ERROR_NULL_INPUT);
558 cpl_test_null(new1);
559 new1 = hdrl_image_add_image_create(a, b);
560 cpl_test_error(CPL_ERROR_NONE);
561 cpl_test_nonnull(new1);
562
563 new2 = hdrl_image_sub_image_create(NULL, b);
564 cpl_test_error(CPL_ERROR_NULL_INPUT);
565 cpl_test_null(new2);
566 new2 = hdrl_image_sub_image_create(a, NULL);
567 cpl_test_error(CPL_ERROR_NULL_INPUT);
568 cpl_test_null(new2);
569 new2 = hdrl_image_sub_image_create(a, b);
570 cpl_test_error(CPL_ERROR_NONE);
571 cpl_test_nonnull(new2);
572
573
574 new3 = hdrl_image_mul_image_create(NULL, b);
575 cpl_test_error(CPL_ERROR_NULL_INPUT);
576 cpl_test_null(new3);
577 new3 = hdrl_image_mul_image_create(a, NULL);
578 cpl_test_error(CPL_ERROR_NULL_INPUT);
579 cpl_test_null(new3);
580 new3 = hdrl_image_mul_image_create(a, b);
581 cpl_test_error(CPL_ERROR_NONE);
582 cpl_test_nonnull(new3);
583
584
585 new4 = hdrl_image_div_image_create(NULL, b);
586 cpl_test_error(CPL_ERROR_NULL_INPUT);
587 cpl_test_null(new4);
588 new4 = hdrl_image_div_image_create(a, NULL);
589 cpl_test_error(CPL_ERROR_NULL_INPUT);
590 cpl_test_null(new4);
591 new4 = hdrl_image_div_image_create(a, b);
592 cpl_test_error(CPL_ERROR_NONE);
593 cpl_test_nonnull(new4);
594
595
596 /* Pow and Exp operations */
597
598 new5 = hdrl_image_pow_scalar_create(NULL, hValue);
599 cpl_test_error(CPL_ERROR_NULL_INPUT);
600 cpl_test_null(new5);
601 new5 = hdrl_image_pow_scalar_create(a, hValue);
602 cpl_test_error(CPL_ERROR_NONE);
603 cpl_test_nonnull(new5);
604
605 new6 = hdrl_image_exp_scalar_create(NULL, hValue);
606 cpl_test_error(CPL_ERROR_NULL_INPUT);
607 cpl_test_null(new6);
608 new6 = hdrl_image_exp_scalar_create(a, hValue);
609 cpl_test_error(CPL_ERROR_NONE);
610 cpl_test_nonnull(new6);
611
612
613 /* Clean up */
616
617 hdrl_image_delete(new1);
618 hdrl_image_delete(new2);
619 hdrl_image_delete(new3);
620 hdrl_image_delete(new4);
621
622 hdrl_image_delete(new5);
623 hdrl_image_delete(new6);
624}
625
626
627/*----------------------------------------------------------------------------*/
631/*----------------------------------------------------------------------------*/
632int main(void)
633{
634 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
635
636 test_basic();
637 test_power();
638 test_exp();
639 test_copy();
640 test_insert();
641 test_extract();
642 test_reduce();
643
644 test_create();
645
646 test_buffer();
647
648 return cpl_test_end(0);
649}
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
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 * hdrl_image_pow_scalar_create(const hdrl_image *self, const hdrl_value exponent)
computes the power of an image by a scalar creating a new image
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
cpl_error_code hdrl_image_reject_value(hdrl_image *self, cpl_value mode)
Reject pixels with the specified special value(s)
Definition: hdrl_image.c:477
cpl_error_code hdrl_image_div_scalar(hdrl_image *self, hdrl_value value)
Elementwise division of an image with a scalar.
hdrl_value hdrl_image_get_sqsum(const hdrl_image *self)
computes the sum of all pixel values and the error of a squared image.
hdrl_image * hdrl_image_sub_image_create(const hdrl_image *self, const hdrl_image *other)
Subtract two images.
cpl_error_code hdrl_image_pow_scalar(hdrl_image *self, const hdrl_value exponent)
computes the power of an image by a scalar
cpl_error_code hdrl_image_add_image(hdrl_image *self, const hdrl_image *other)
Add two images, store the result in the first image.
hdrl_value hdrl_image_get_minmax_mean(const hdrl_image *self, double nlow, double nhigh)
computes the minmax rejected mean and the associated error of an image.
hdrl_value hdrl_image_get_sigclip_mean(const hdrl_image *self, double kappa_low, double kappa_high, int niter)
computes the sigma-clipped mean and associated error of an image.
cpl_error_code hdrl_image_copy(hdrl_image *dst, const hdrl_image *src, cpl_size xpos, cpl_size ypos)
Copy one image into another.
Definition: hdrl_image.c:686
hdrl_image * hdrl_image_extract(const hdrl_image *self, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
extract copy of window from image
Definition: hdrl_image.c:625
hdrl_image * hdrl_image_div_image_create(const hdrl_image *self, const hdrl_image *other)
Divide two images and return the resulting image.
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
cpl_error_code hdrl_image_dump_window(const hdrl_image *himg, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, FILE *stream)
Dump pixel values in a HDRL image.
Definition: hdrl_image.c:793
hdrl_value hdrl_image_get_sum(const hdrl_image *self)
computes the sum of all pixel values and the associated error of an image.
cpl_error_code hdrl_image_exp_scalar(hdrl_image *self, const hdrl_value base)
computes the exponential of an image by a scalar
hdrl_value hdrl_image_get_mean(const hdrl_image *self)
computes mean pixel value and associated error of 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
hdrl_value hdrl_image_get_weighted_mean(const hdrl_image *self)
computes the weighted mean and associated error of an image.
cpl_error_code hdrl_image_insert(hdrl_image *self, const cpl_image *image, const cpl_image *error, cpl_size xpos, cpl_size ypos)
Copy cpl images into an hdrl image.
Definition: hdrl_image.c:715
cpl_size hdrl_image_count_rejected(const hdrl_image *self)
return number of rejected pixels
Definition: hdrl_image.c:461
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
Definition: hdrl_image.c:295
hdrl_image * hdrl_image_add_image_create(const hdrl_image *self, const hdrl_image *other)
Add two images.
hdrl_image * hdrl_image_mul_image_create(const hdrl_image *self, const hdrl_image *other)
Multiply two images.
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
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 * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
Definition: hdrl_image.c:311
cpl_error_code hdrl_image_dump_structure(const hdrl_image *himg, FILE *stream)
Dump structural information of a HDRL image.
Definition: hdrl_image.c:767
hdrl_image * hdrl_image_exp_scalar_create(const hdrl_image *self, const hdrl_value base)
computes the exponential of an image by a scalar creating a new image
cpl_error_code hdrl_image_accept(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as good
Definition: hdrl_image.c:493
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
cpl_error_code hdrl_image_accept_all(hdrl_image *self)
Accept all pixels in an image.
Definition: hdrl_image.c:508
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
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.