28#include "hdrl_imagelist.h"
29#include "hdrl_imagelist_view.h"
30#include "hdrl_imagelist_defs.h"
31#include "hdrl_image.h"
32#include "hdrl_collapse.h"
61 HDRL_IMLIST_BASIC_IMLIST = 0,
62 HDRL_IMLIST_BASIC_IMAGE,
63 HDRL_IMLIST_BASIC_SCALAR
66typedef cpl_error_code (*hdrl_f_image)(hdrl_image *,
const hdrl_image *);
67typedef cpl_error_code (*hdrl_f_scalar)(hdrl_image *, hdrl_value);
72 hdrl_f_scalar f_scalar;
79static cpl_error_code hdrl_imagelist_basic_operation(
82 hdrl_imagelist *himlist1,
83 const hdrl_imagelist *himlist2,
84 const hdrl_image *himg,
87static cpl_error_code hdrl_imagelist_collapse_interface(
88 const hdrl_imagelist *himlist,
89 hdrl_collapse_imagelist_to_image_t *collapse_method,
115 hdrl_imagelist * himlist1,
116 const hdrl_imagelist * himlist2)
118 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST,
133 hdrl_imagelist * himlist1,
134 const hdrl_imagelist * himlist2)
136 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST,
151 hdrl_imagelist * himlist1,
152 const hdrl_imagelist * himlist2)
154 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST,
169 hdrl_imagelist * himlist1,
170 const hdrl_imagelist * himlist2)
172 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMLIST,
192 hdrl_imagelist * himlist,
193 const hdrl_image * himg)
195 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE,
215 hdrl_imagelist * himlist,
216 const hdrl_image * himg)
218 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE,
238 hdrl_imagelist * himlist,
239 const hdrl_image * himg)
241 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE,
261 hdrl_imagelist * himlist,
262 const hdrl_image * himg)
264 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_IMAGE,
283 hdrl_imagelist * himlist,
286 const cpl_error_code code =
287 hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR,
289 himlist, NULL, NULL, &value);
290 return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
307 hdrl_imagelist * himlist,
310 const cpl_error_code code =
311 hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR,
313 himlist, NULL, NULL, &value);
314 return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
331 hdrl_imagelist * himlist,
334 const cpl_error_code code =
335 hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR,
337 himlist, NULL, NULL, &value);
338 return code ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE;
355 hdrl_imagelist * himlist,
358 return hdrl_imagelist_basic_operation(HDRL_IMLIST_BASIC_SCALAR,
377 hdrl_imagelist * himlist,
380 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
383 for (cpl_size i = 0 ; i<nima ; i++) {
385 exponent), cpl_error_get_code());
387 return CPL_ERROR_NONE;
414 const hdrl_imagelist * himlist,
415 const hdrl_parameter * param,
417 cpl_image ** contrib)
419 cpl_ensure_code(himlist, CPL_ERROR_NULL_INPUT);
420 cpl_ensure_code(param, CPL_ERROR_NULL_INPUT);
421 cpl_ensure_code(out, CPL_ERROR_NULL_INPUT);
422 cpl_ensure_code(contrib, CPL_ERROR_NULL_INPUT);
438 out, contrib, NULL, NULL);
444 out, contrib, NULL, NULL);
456 return cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
457 "Invalid parameter input for "
458 "hdrl_imagelist_collapse");
461 return cpl_error_get_code();
477 const hdrl_imagelist * himlist,
479 cpl_image ** contrib)
481 hdrl_collapse_imagelist_to_image_t * method =
482 hdrl_collapse_imagelist_to_image_mean();
483 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, NULL) ;
484 hdrl_collapse_imagelist_to_image_delete(method) ;
485 return cpl_error_get_code();
501 const hdrl_imagelist * himlist,
503 cpl_image ** contrib)
505 hdrl_collapse_imagelist_to_image_t * method =
506 hdrl_collapse_imagelist_to_image_weighted_mean();
507 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, NULL) ;
508 hdrl_collapse_imagelist_to_image_delete(method) ;
509 return cpl_error_get_code();
525 const hdrl_imagelist * himlist,
527 cpl_image ** contrib)
529 hdrl_collapse_imagelist_to_image_t * method =
530 hdrl_collapse_imagelist_to_image_median();
531 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, NULL) ;
532 hdrl_collapse_imagelist_to_image_delete(method) ;
533 return cpl_error_get_code();
555 const hdrl_imagelist * himlist,
560 cpl_image ** contrib,
561 cpl_image ** reject_low,
562 cpl_image ** reject_high)
564 hdrl_sigclip_image_output * sigclipout;
565 hdrl_collapse_imagelist_to_image_t * method =
566 hdrl_collapse_imagelist_to_image_sigclip(kappa_low, kappa_high, niter);
567 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, (
void**)&sigclipout);
569 if (cpl_error_get_code() != CPL_ERROR_NONE) {
571 hdrl_collapse_imagelist_to_image_delete(method);
581 return cpl_error_get_code();
585 *reject_low = sigclipout->reject_low;
587 cpl_image_delete(sigclipout->reject_low);
591 *reject_high = sigclipout->reject_high;
593 cpl_image_delete(sigclipout->reject_high);
596 hdrl_collapse_imagelist_to_image_unwrap_eout(method, sigclipout);
597 hdrl_collapse_imagelist_to_image_delete(method);
599 return cpl_error_get_code();
620 const hdrl_imagelist * himlist,
624 cpl_image ** contrib,
625 cpl_image ** reject_low,
626 cpl_image ** reject_high)
628 hdrl_minmax_image_output * minmaxout;
629 hdrl_collapse_imagelist_to_image_t * method =
630 hdrl_collapse_imagelist_to_image_minmax(nlow, nhigh);
631 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, (
void**)&minmaxout);
633 if (cpl_error_get_code() != CPL_ERROR_NONE) {
635 hdrl_collapse_imagelist_to_image_delete(method);
645 return cpl_error_get_code();
649 *reject_low = minmaxout->reject_low;
651 cpl_image_delete(minmaxout->reject_low);
655 *reject_high = minmaxout->reject_high;
657 cpl_image_delete(minmaxout->reject_high);
660 hdrl_collapse_imagelist_to_image_unwrap_eout(method, minmaxout);
661 hdrl_collapse_imagelist_to_image_delete(method);
663 return cpl_error_get_code();
690 hdrl_mode_type mode_method,
691 cpl_size error_niter,
693 cpl_image ** contrib)
695 hdrl_collapse_imagelist_to_image_t * method =
696 hdrl_collapse_imagelist_to_image_mode(histo_min, histo_max, bin_size,
697 mode_method, error_niter );
698 hdrl_imagelist_collapse_interface(himlist, method, out, contrib, NULL) ;
699 hdrl_collapse_imagelist_to_image_delete(method) ;
700 return cpl_error_get_code();
726static cpl_error_code hdrl_imagelist_collapse_interface(
727 const hdrl_imagelist * himlist,
728 hdrl_collapse_imagelist_to_image_t * collapse_method,
730 cpl_image ** contrib,
733 cpl_error_code fail = CPL_ERROR_NONE;
736 cpl_ensure_code(himlist != NULL, CPL_ERROR_NULL_INPUT);
737 cpl_ensure_code(out != NULL, CPL_ERROR_NULL_INPUT);
738 cpl_ensure_code(contrib != NULL, CPL_ERROR_NULL_INPUT);
743 if (cpl_error_get_code() != CPL_ERROR_NONE) {
744 return cpl_error_get_code();
748 *contrib = cpl_image_new( nx, ny, CPL_TYPE_INT);
751 cpl_image_get_bpm(*contrib);
756 *eout = hdrl_collapse_imagelist_to_image_create_eout(
763 cpl_size blocksize = 16ul * (1ul<<20ul) / (nz * nx *
sizeof(
double));
764 hdrl_iter *it = hdrl_imagelist_get_iter_row_slices(himlist, blocksize, 0, HDRL_ITER_CONST);
766 cpl_size nit = hdrl_iter_length(it);
767 hdrl_imagelist *vl[nit];
773 for (hdrl_imagelist * v = hdrl_iter_next(it);
775 v = hdrl_iter_next(it)) {
782 hdrl_iter_delete(it);
784 if (cpl_error_get_code() != CPL_ERROR_NONE) {
785 for (cpl_size i = 0; i < nit; i++) {
788 return cpl_error_get_code();
791 HDRL_OMP(omp parallel
for)
792 for (cpl_size i = 0; i < nit; i++) {
795 cpl_image *out_errors;
796 cpl_image *out_contrib;
799 cpl_imagelist *errors;
803 hdrl_imagelist *v = vl[i];
807 hdrl_imagelist_to_cplwrap(v, &data, &errors);
810 hdrl_collapse_imagelist_to_image_call(collapse_method, data, errors,
811 &out_data, &out_errors,
812 &out_contrib, &out_eout);
814 if (cpl_error_get_code() != CPL_ERROR_NONE) {
816 fail = cpl_error_get_code();
817 cpl_imagelist_unwrap(data) ;
818 cpl_imagelist_unwrap(errors) ;
823 cpl_msg_debug(cpl_func,
"Collapsed block %lld to %lld", y,
824 y + cpl_image_get_size_y(out_data) - 1);
828 assert(cpl_image_get_bpm_const(*contrib));
830 cpl_image_copy(*contrib, out_contrib, 1, y);
834 hdrl_collapse_imagelist_to_image_move_eout(collapse_method,
839 cpl_image_delete(out_data);
840 cpl_image_delete(out_errors);
841 cpl_image_delete(out_contrib);
842 cpl_imagelist_unwrap(data) ;
843 cpl_imagelist_unwrap(errors) ;
848 if (fail != CPL_ERROR_NONE) {
851 hdrl_collapse_imagelist_to_image_delete_eout(collapse_method, *eout);
855 cpl_image_delete(*contrib);
857 return cpl_error_set_message(cpl_func, fail,
"hdrl_imagelist_collapse failed");
860 return cpl_error_get_code();
878static cpl_error_code hdrl_imagelist_basic_operation(
881 hdrl_imagelist *himlist1,
882 const hdrl_imagelist *himlist2,
883 const hdrl_image *himg,
887 cpl_ensure_code(himlist1, CPL_ERROR_NULL_INPUT);
890 case HDRL_IMLIST_BASIC_IMLIST:
891 cpl_ensure_code(func.f_image, CPL_ERROR_NULL_INPUT);
892 cpl_ensure_code(himlist2, CPL_ERROR_NULL_INPUT);
893 cpl_ensure_code(himlist1->ni == himlist2->ni,
894 CPL_ERROR_INCOMPATIBLE_INPUT);
896 case HDRL_IMLIST_BASIC_IMAGE:
897 cpl_ensure_code(func.f_image, CPL_ERROR_NULL_INPUT);
898 cpl_ensure_code(himg, CPL_ERROR_NULL_INPUT);
900 case HDRL_IMLIST_BASIC_SCALAR:
901 cpl_ensure_code(func.f_scalar, CPL_ERROR_NULL_INPUT);
902 cpl_ensure_code(value, CPL_ERROR_NULL_INPUT);
907 for (cpl_size i = 0; i < himlist1->ni; i++) {
908 cpl_error_code err = CPL_ERROR_NONE;
910 case HDRL_IMLIST_BASIC_IMLIST:
912 err = func.f_image(himlist1->images[i], himlist2->images[i]);
915 case HDRL_IMLIST_BASIC_IMAGE:
917 err = func.f_image(himlist1->images[i], himg);
920 case HDRL_IMLIST_BASIC_SCALAR:
921 err = func.f_scalar(himlist1->images[i], *value);
924 cpl_ensure_code(err == CPL_ERROR_NONE, err);
927 return CPL_ERROR_NONE;
double hdrl_collapse_mode_parameter_get_bin_size(const hdrl_parameter *p)
get size of the histogram bins
double hdrl_collapse_mode_parameter_get_histo_min(const hdrl_parameter *p)
get min value
cpl_boolean hdrl_collapse_parameter_is_weighted_mean(const hdrl_parameter *self)
check if parameter is a weighted mean parameter
double hdrl_collapse_sigclip_parameter_get_kappa_low(const hdrl_parameter *p)
get low kappa
cpl_boolean hdrl_collapse_parameter_is_mean(const hdrl_parameter *self)
check if parameter is a mean parameter
cpl_boolean hdrl_collapse_parameter_is_median(const hdrl_parameter *self)
check if parameter is a median parameter
double hdrl_collapse_mode_parameter_get_histo_max(const hdrl_parameter *p)
get high value
int hdrl_collapse_sigclip_parameter_get_niter(const hdrl_parameter *p)
get maximum number of clipping iterations
cpl_size hdrl_collapse_mode_parameter_get_error_niter(const hdrl_parameter *p)
get the error type of the mode
cpl_boolean hdrl_collapse_parameter_is_minmax(const hdrl_parameter *self)
check if parameter is a minmax mean parameter
cpl_boolean hdrl_collapse_parameter_is_mode(const hdrl_parameter *self)
check if parameter is a mode parameter
cpl_boolean hdrl_collapse_parameter_is_sigclip(const hdrl_parameter *self)
check if parameter is a sigclip mean parameter
double hdrl_collapse_sigclip_parameter_get_kappa_high(const hdrl_parameter *p)
get high kappa
double hdrl_collapse_minmax_parameter_get_nlow(const hdrl_parameter *p)
get low value
hdrl_mode_type hdrl_collapse_mode_parameter_get_method(const hdrl_parameter *p)
get the mode determination method
double hdrl_collapse_minmax_parameter_get_nhigh(const hdrl_parameter *p)
get high value
cpl_error_code hdrl_image_sub_image(hdrl_image *self, const hdrl_image *other)
Subtract two images, store the result in the first image.
cpl_error_code hdrl_image_div_scalar(hdrl_image *self, hdrl_value value)
Elementwise division of an image with a scalar.
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.
cpl_error_code hdrl_image_div_image(hdrl_image *self, const hdrl_image *other)
Divide two images, store the result in the first image.
cpl_error_code hdrl_image_mul_scalar(hdrl_image *self, hdrl_value value)
Elementwise multiplication of an image with a scalar.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from 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_mul_image(hdrl_image *self, const hdrl_image *other)
Multiply two images, store the result in the first image.
const cpl_mask * hdrl_image_get_mask_const(const hdrl_image *himg)
get cpl bad pixel mask from 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_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_image_sub_scalar(hdrl_image *self, hdrl_value value)
Elementwise subtraction of a scalar from an image.
cpl_error_code hdrl_imagelist_collapse_sigclip(const hdrl_imagelist *himlist, double kappa_low, double kappa_high, int niter, hdrl_image **out, cpl_image **contrib, cpl_image **reject_low, cpl_image **reject_high)
Sigma-clipped collapsing of image list.
cpl_error_code hdrl_imagelist_div_imagelist(hdrl_imagelist *himlist1, const hdrl_imagelist *himlist2)
Divide two image lists, the first one is replaced by the result.
cpl_error_code hdrl_imagelist_add_scalar(hdrl_imagelist *himlist, hdrl_value value)
Elementwise addition of a scalar to each image in the himlist.
cpl_error_code hdrl_imagelist_collapse_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Mean collapsing of image list.
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
cpl_error_code hdrl_imagelist_add_image(hdrl_imagelist *himlist, const hdrl_image *himg)
Add an image to an image list.
cpl_error_code hdrl_imagelist_pow_scalar(hdrl_imagelist *himlist, hdrl_value exponent)
Compute the elementwise power of each image in the himlist.
hdrl_imagelist_basic_type
Define the kind of operation to apply.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
cpl_error_code hdrl_imagelist_div_scalar(hdrl_imagelist *himlist, hdrl_value value)
Elementwise division by a scalar to each image in the himlist.
cpl_error_code hdrl_imagelist_sub_image(hdrl_imagelist *himlist, const hdrl_image *himg)
Subtract an image from an image list.
cpl_error_code hdrl_imagelist_sub_scalar(hdrl_imagelist *himlist, hdrl_value value)
Elementwise subtraction of a scalar to each image in the himlist.
cpl_error_code hdrl_imagelist_collapse(const hdrl_imagelist *himlist, const hdrl_parameter *param, hdrl_image **out, cpl_image **contrib)
collapsing of image list
cpl_error_code hdrl_imagelist_mul_scalar(hdrl_imagelist *himlist, hdrl_value value)
Elementwise multiplication of a scalar to each image in the himlist.
cpl_error_code hdrl_imagelist_collapse_median(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Median collapsing of image list.
cpl_error_code hdrl_imagelist_mul_imagelist(hdrl_imagelist *himlist1, const hdrl_imagelist *himlist2)
Multiply two image lists, the first one is replaced by the result.
cpl_error_code hdrl_imagelist_add_imagelist(hdrl_imagelist *himlist1, const hdrl_imagelist *himlist2)
Add two image lists, the first one is replaced by the result.
cpl_error_code hdrl_imagelist_collapse_mode(const hdrl_imagelist *himlist, double histo_min, double histo_max, double bin_size, hdrl_mode_type mode_method, cpl_size error_niter, hdrl_image **out, cpl_image **contrib)
Mode collapsing of image list.
cpl_error_code hdrl_imagelist_sub_imagelist(hdrl_imagelist *himlist1, const hdrl_imagelist *himlist2)
Subtract two image lists, the first one is replaced by the result.
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
cpl_error_code hdrl_imagelist_collapse_minmax(const hdrl_imagelist *himlist, double nlow, double nhigh, hdrl_image **out, cpl_image **contrib, cpl_image **reject_low, cpl_image **reject_high)
Minmax-clipped collapsing of image list.
cpl_error_code hdrl_imagelist_collapse_weighted_mean(const hdrl_imagelist *himlist, hdrl_image **out, cpl_image **contrib)
Weighted Mean collapsing of image list.
cpl_error_code hdrl_imagelist_mul_image(hdrl_imagelist *himlist, const hdrl_image *himg)
Multiply an image by an image list.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_error_code hdrl_imagelist_div_image(hdrl_imagelist *himlist, const hdrl_image *himg)
Divide an image from an image list.