36#include "hdrl_image.h"
38#include "hdrl_imagelist.h"
39#include "hdrl_buffer.h"
40#include "hdrl_types.h"
52#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
62static void test_basic(
void)
65 cpl_image * cimg, * cerr;
73 cpl_test_nonnull(img);
74 cpl_test_error(CPL_ERROR_NONE);
79 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
83 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
87 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
91 cpl_test_error(CPL_ERROR_NULL_INPUT);
95 cimg = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
96 cerr = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
100 cpl_test_error(CPL_ERROR_NULL_INPUT);
103 cpl_test_nonnull(img);
107 cpl_test_nonnull(img);
111 cpl_test_eq_error(error, CPL_ERROR_NONE);
114 cpl_test_eq_error(error, CPL_ERROR_NONE);
120 cpl_image_reject(cimg, 2, 3);
122 cpl_test_nonnull(img);
126 cpl_image_reject(cerr, 2, 3);
129 cpl_test_nonnull(img);
133 cpl_image_reject(cerr, 2, 4);
136 cpl_test_nonnull(img);
139 cpl_image_accept_all(cimg);
142 cpl_test_nonnull(img);
145 cpl_image_delete(cerr);
146 cerr = cpl_image_new(2, 6, CPL_TYPE_DOUBLE);
149 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
151 cpl_image_delete(cerr);
152 cerr = cpl_image_new(5, 2, CPL_TYPE_DOUBLE);
155 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
165 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
167 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
169 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
171 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
178 cpl_image_delete(cimg);
179 cpl_image_delete(cerr);
182static void test_extract(
void)
191 cpl_test_nonnull(ex);
192 hdrl_test_image_abs(himg, ex, 0);
196 cpl_test_nonnull(ex);
197 hdrl_test_image_abs(himg, ex, 0);
201 cpl_test_nonnull(ex);
207 cpl_test_nonnull(ex);
214 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
218 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
222 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
226 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
230 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
235static void test_power(
void)
242 cpl_test_rel(v.data, 4., HDRL_EPS_DATA);
243 cpl_test_rel(v.error, 2.0, HDRL_EPS_ERROR);
248 cpl_test_rel(v.data, 16, HDRL_EPS_DATA);
249 cpl_test_rel(v.error, 16, HDRL_EPS_ERROR);
254 cpl_test_rel(v.data, 0.5, HDRL_EPS_DATA);
255 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
260 cpl_test_rel(v.data, 0.25, HDRL_EPS_DATA);
261 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
266 cpl_test_rel(v.data, 0.0625, HDRL_EPS_DATA);
267 cpl_test_rel(v.error, 0.0625, HDRL_EPS_ERROR);
272 cpl_test_rel(v.data, 1.0/8.0, HDRL_EPS_DATA);
273 cpl_test_rel(v.error, 0.05625, HDRL_EPS_ERROR);
278static void test_exp(
void)
285 cpl_test_rel(v.data, 4., HDRL_EPS_DATA);
286 cpl_test_rel(v.error, 2.0, HDRL_EPS_ERROR);
292 cpl_test_rel(v.data, 16, HDRL_EPS_DATA);
293 cpl_test_rel(v.error, 16, HDRL_EPS_ERROR);
298 cpl_test_rel(v.data, 0.5, HDRL_EPS_DATA);
299 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
304 cpl_test_rel(v.data, 0.25, HDRL_EPS_DATA);
305 cpl_test_rel(v.error, 0.125, HDRL_EPS_ERROR);
310 cpl_test_rel(v.data, 0.0625, HDRL_EPS_DATA);
311 cpl_test_rel(v.error, 0.0625, HDRL_EPS_ERROR);
317static void test_copy(
void)
324 hdrl_test_image_abs(dst, expected, 0);
331 hdrl_test_image_abs(dst, expected, 0);
338static void test_insert(
void)
342 cpl_image * im1 = cpl_image_new(50, 50, HDRL_TYPE_DATA);
343 cpl_image * im2 = cpl_image_new(50, 50, HDRL_TYPE_ERROR);
345 cpl_image_reject(im1, 1, 1);
350 hdrl_test_image_abs(dst, dst2, 0);
353 hdrl_test_image_abs(dst, dst2, 0);
358 cpl_image_delete(im1);
359 cpl_image_delete(im2);
362static void test_reduce(
void)
365 size_t nx = 53, ny = 2310;
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);
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);
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);
398 hdrl_test_image_abs(a, r, HDRL_EPS_DATA);
401 cpl_image_delete(con);
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 };
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);
417 cpl_image_set(errors, 7, 7, 100000.);
418 cpl_image_set(errors, 6, 7, 10000.);
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);
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 };
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);
442 cpl_image_set(errors, 7, 7,100000.);
443 cpl_image_set(errors, 6, 7,10000.);
444 cpl_image_set(errors, 1, 1,1000.);
454 cpl_test_rel(m.data, 10298.122448979591, HDRL_EPS_DATA * 49);
456 cpl_test_rel(m.data, 96.0, 0.005);
458 cpl_test_rel(m.data, -2029.6170212765958, HDRL_EPS_DATA * 49);
460 cpl_test_rel(m.data, 100.17391304347827, HDRL_EPS_DATA * 49);
463 cpl_image_delete(errors);
464 cpl_image_unwrap(data);
468 size_t nx = 3, ny = 1;
477 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
478 cpl_test(isnan(m.data) && isnan(m.error));
481 cpl_test_error(CPL_ERROR_NONE);
482 cpl_test(!isnan(m.data) && !isnan(m.error));
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);
488 cpl_test_abs(m.data, 4. + 9., HDRL_EPS_DATA);
489 cpl_test_abs(m.error, 16.15549442140351, HDRL_EPS_ERROR * 6);
494static inline void test_buffer(
void)
496 hdrl_buffer *buf = hdrl_buffer_new();
499#if (__WORDSIZE == 64)
502 cpl_size sizeImg = 64;
504 for (cpl_size i = 0; i < iMax; i++) {
505 hdrl_image * img = hdrl_image_new_from_buffer(sizeImg, sizeImg, buf);
509 cpl_msg_warning(cpl_func,
"alloc done");
516 cpl_msg_warning(cpl_func,
"collapse done");
524 hdrl_buffer_delete(buf);
527static void test_create(
void)
540 hdrl_value hValue = {2., 0.5};
554 cpl_test_error(CPL_ERROR_NULL_INPUT);
557 cpl_test_error(CPL_ERROR_NULL_INPUT);
560 cpl_test_error(CPL_ERROR_NONE);
561 cpl_test_nonnull(new1);
564 cpl_test_error(CPL_ERROR_NULL_INPUT);
567 cpl_test_error(CPL_ERROR_NULL_INPUT);
570 cpl_test_error(CPL_ERROR_NONE);
571 cpl_test_nonnull(new2);
575 cpl_test_error(CPL_ERROR_NULL_INPUT);
578 cpl_test_error(CPL_ERROR_NULL_INPUT);
581 cpl_test_error(CPL_ERROR_NONE);
582 cpl_test_nonnull(new3);
586 cpl_test_error(CPL_ERROR_NULL_INPUT);
589 cpl_test_error(CPL_ERROR_NULL_INPUT);
592 cpl_test_error(CPL_ERROR_NONE);
593 cpl_test_nonnull(new4);
599 cpl_test_error(CPL_ERROR_NULL_INPUT);
602 cpl_test_error(CPL_ERROR_NONE);
603 cpl_test_nonnull(new5);
606 cpl_test_error(CPL_ERROR_NULL_INPUT);
609 cpl_test_error(CPL_ERROR_NONE);
610 cpl_test_nonnull(new6);
634 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
648 return cpl_test_end(0);
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
int hdrl_image_is_rejected(hdrl_image *self, cpl_size xpos, cpl_size ypos)
return if pixel is marked bad
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
cpl_error_code hdrl_image_reject_value(hdrl_image *self, cpl_value mode)
Reject pixels with the specified special value(s)
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.
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
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.
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
cpl_size hdrl_image_get_size_x(const hdrl_image *self)
return size of X dimension of image
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.
cpl_size hdrl_image_count_rejected(const hdrl_image *self)
return number of rejected pixels
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
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
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
cpl_error_code hdrl_image_dump_structure(const hdrl_image *himg, FILE *stream)
Dump structural information of a HDRL image.
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
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_image_accept_all(hdrl_image *self)
Accept all pixels in an image.
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.