28#include "hdrl_lacosmics.h"
29#include "hdrl_bpm_2d.h"
41cpl_error_code test_lacosmic_inputs(
void)
45 4., 5., 6, 20, 21, 11, 12, 2, 10);
50 cpl_test_error(CPL_ERROR_NONE);
60 cpl_test_error(CPL_ERROR_NULL_INPUT);
63 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
66 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
69 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
72 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
75 cpl_test_error(CPL_ERROR_NONE);
81 cpl_test_error(CPL_ERROR_NULL_INPUT);
83 cpl_test_error(CPL_ERROR_NONE);
86 cpl_test_error(CPL_ERROR_NULL_INPUT);
88 cpl_test_error(CPL_ERROR_NONE);
91 cpl_test_error(CPL_ERROR_NULL_INPUT);
93 cpl_test_error(CPL_ERROR_NONE);
97 cpl_parameterlist *pl;
100 cpl_test_error(CPL_ERROR_NULL_INPUT);
104 cpl_test_error(CPL_ERROR_NULL_INPUT);
108 cpl_test_error(CPL_ERROR_NULL_INPUT);
111 cpl_parameterlist *plFake;
113 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
114 cpl_test_null(plFake);
117 cpl_test_error(CPL_ERROR_NONE);
118 cpl_test_nonnull(pl);
122 hdrl_parameter *check;
125 cpl_test_error(CPL_ERROR_NULL_INPUT);
126 cpl_test_null(check);
129 cpl_test_error(CPL_ERROR_NULL_INPUT);
130 cpl_test_null(check);
133 cpl_test_error(CPL_ERROR_NONE);
134 cpl_test_nonnull(check);
140 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
148 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
154 cpl_parameterlist_delete(pl);
162 return cpl_error_get_code();
165cpl_error_code test_lacosmic_edgedetect(
void)
167 cpl_image * img_data = NULL;
168 cpl_mask * img_mask = NULL;
169 cpl_image * img_error = NULL;
170 cpl_mask * result_mask = NULL;
173 img_data = cpl_image_new(200, 300, CPL_TYPE_DOUBLE);
174 img_mask = cpl_mask_new(200, 300);
175 cpl_image_fill_noise_uniform(img_data, 90, 110);
176 double error = (110 - 90) / sqrt(12);
177 cpl_image_set(img_data, 50, 50, 300.);
178 cpl_image_set(img_data, 100, 100, 300.);
179 cpl_image_set(img_data, 150, 150, 300.);
180 cpl_image_set(img_data, 100, 250, 300.);
182 img_error = cpl_image_new(cpl_image_get_size_x(img_data),
183 cpl_image_get_size_y(img_data),
185 cpl_image_add_scalar(img_error, error);
187 cpl_mask_set(img_mask, 120,120, CPL_BINARY_1);
188 cpl_mask_set(img_mask, 120,121, CPL_BINARY_1);
189 cpl_mask_set(img_mask, 120,122, CPL_BINARY_1);
190 cpl_mask_set(img_mask, 121,120, CPL_BINARY_1);
191 cpl_mask_set(img_mask, 121,121, CPL_BINARY_1);
192 cpl_mask_set(img_mask, 121,122, CPL_BINARY_1);
193 cpl_mask_set(img_mask, 122,120, CPL_BINARY_1);
194 cpl_mask_set(img_mask, 122,121, CPL_BINARY_1);
195 cpl_mask_set(img_mask, 122,122, CPL_BINARY_1);
197 cpl_image_set(img_data, 122, 122, 300.);
199 cpl_image_reject_from_mask(img_data, img_mask);
201 hdrl_parameter * params =
214 cpl_test_eq(cpl_mask_get(result_mask, 50, 50), CPL_BINARY_1);
215 cpl_test_eq(cpl_mask_get(result_mask, 100, 100), CPL_BINARY_1);
216 cpl_test_eq(cpl_mask_get(result_mask, 150, 150), CPL_BINARY_1);
217 cpl_test_eq(cpl_mask_get(result_mask, 100, 250), CPL_BINARY_1);
218 cpl_test_eq(cpl_mask_get(result_mask, 122, 122), CPL_BINARY_0);
220 cpl_test_eq(cpl_mask_get(result_mask, 110, 260), CPL_BINARY_0);
223 cpl_image_delete(img_data);
224 cpl_mask_delete(img_mask);
225 cpl_image_delete(img_error);
226 cpl_mask_delete(result_mask);
232 img_data = cpl_image_new(150, 200, CPL_TYPE_DOUBLE);
233 img_mask = cpl_mask_new(150, 200);
234 cpl_image_fill_noise_uniform(img_data, 90, 110);
235 double error = (110 - 90) / sqrt(12);
237 for (
int varx = 50; varx < 75; ++varx) {
238 for (
int vary = 60; vary < 130; ++vary) {
239 cpl_image_set(img_data, varx, vary, 5000);
242 for (
int varx = 20; varx < 120; ++varx) {
243 for (
int vary = 20; vary < 40; ++vary) {
244 cpl_image_set(img_data, varx, vary, 5000);
247 img_error = cpl_image_new(cpl_image_get_size_x(img_data),
248 cpl_image_get_size_y(img_data),
250 cpl_image_add_scalar(img_error, error);
255 hdrl_parameter * params =
268 cpl_test_eq(cpl_mask_count(result_mask), 100*20+25*70);
270 cpl_image_delete(img_data);
271 cpl_mask_delete(img_mask);
272 cpl_image_delete(img_error);
273 cpl_mask_delete(result_mask);
278 img_data = cpl_image_new(150, 200, CPL_TYPE_DOUBLE);
279 img_mask = cpl_mask_new(150, 200);
280 cpl_image_fill_noise_uniform(img_data, 90, 110);
281 double error = (110 - 90) / sqrt(12);
283 for (
int varx = 50; varx < 75; ++varx) {
284 for (
int vary = 60; vary < 130; ++vary) {
285 cpl_image_set(img_data, varx, vary, 5000);
288 for (
int varx = 20; varx < 120; ++varx) {
289 for (
int vary = 20; vary < 40; ++vary) {
290 cpl_image_set(img_data, varx, vary, 5000);
295 for (
int varx = 65; varx < 68; ++varx) {
296 for (
int vary = 1; vary < 150; ++vary) {
297 cpl_mask_set(img_mask, varx, vary, CPL_BINARY_1);
300 img_error = cpl_image_new(cpl_image_get_size_x(img_data),
301 cpl_image_get_size_y(img_data),
303 cpl_image_add_scalar(img_error, error);
304 cpl_image_reject_from_mask(img_data, img_mask);
310 hdrl_parameter * params =
324 cpl_test_eq(cpl_mask_count(result_mask), 100*20 + 25*70 - 3*70 - 3*20);
326 cpl_image_delete(img_data);
327 cpl_mask_delete(img_mask);
328 cpl_image_delete(img_error);
329 cpl_mask_delete(result_mask);
332 return cpl_error_get_code();
342 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
344 test_lacosmic_inputs();
346 test_lacosmic_edgedetect();
348 return cpl_test_end(0);
hdrl_parameter * hdrl_bpm_2d_parameter_create_legendresmooth(double kappa_low, double kappa_high, int maxiter, int steps_x, int steps_y, int filter_size_x, int filter_size_y, int order_x, int order_y)
Creates BPM_2D Parameters object for HDRL_BPM_2D_LEGENDRESMOOTH.
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_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_parameterlist * hdrl_lacosmic_parameter_create_parlist(const char *base_context, const char *prefix, const hdrl_parameter *defaults)
Create parameter list for the LaCosmic computation.
double hdrl_lacosmic_parameter_get_sigma_lim(const hdrl_parameter *p)
Access the sigma_lim in the LaCosmic parameter.
cpl_mask * hdrl_lacosmic_edgedetect(const hdrl_image *ima_in, const hdrl_parameter *params)
Detect bad-pixels / cosmic-rays on a single image.
int hdrl_lacosmic_parameter_get_max_iter(const hdrl_parameter *p)
Access the max_iter in the LaCosmic parameter.
cpl_error_code hdrl_lacosmic_parameter_verify(const hdrl_parameter *param)
Verify basic correctness of the LaCosmic parameters.
hdrl_parameter * hdrl_lacosmic_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse parameterlist to create input parameters for the LaCosmic.
double hdrl_lacosmic_parameter_get_f_lim(const hdrl_parameter *p)
Access the f_lim in the LaCosmic parameter.
cpl_boolean hdrl_lacosmic_parameter_check(const hdrl_parameter *self)
Check that the parameter is an LaCosmic parameter.
hdrl_parameter * hdrl_lacosmic_parameter_create(double sigma_lim, double f_lim, int max_iter)
Creates LaCosmic parameters object.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter