CR2RE Pipeline Reference Manual 1.6.8
hdrl_bpm_2d-test.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2013 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
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include "hdrl_bpm_2d.h"
29#include "hdrl_bpm_2d.c"
30#include "hdrl_image.h"
31
32#include <cpl.h>
33#include <math.h>
34
35/*----------------------------------------------------------------------------*/
39/*----------------------------------------------------------------------------*/
40
41void test_parlist(void)
42{
43 /* parameter parsing smoketest */
44 hdrl_parameter * hpar;
45
46 /* Create hdrl_parameter of filter and legendre */
47 hdrl_parameter * fil_def =
49 CPL_FILTER_MEDIAN,
50 CPL_BORDER_NOP,
51 7, 9);
52
53 hdrl_parameter * leg_def =
55 20, 21,
56 11, 12, 2, 10);
57
58 /* Check parameters */
59 cpl_test(hdrl_bpm_2d_parameter_check(fil_def));
60 cpl_test(hdrl_bpm_2d_parameter_check(leg_def));
61
62
63 /* Verify hdrl_parameter */
64 hdrl_parameter *pErr;
65
67 cpl_test_error(CPL_ERROR_NULL_INPUT);
68
70 cpl_test_error(CPL_ERROR_NONE);
71
73 cpl_test_error(CPL_ERROR_NONE);
74
75
76 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(-1., 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9);
77 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
78 cpl_test_null(pErr);
79
80 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, -1., 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9);
81 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
82 cpl_test_null(pErr);
83
84 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, -1, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 9);
85 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
86 cpl_test_null(pErr);
87
88 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_STDEV, CPL_BORDER_NOP, 7, 9);
89 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
90 cpl_test_null(pErr);
91
92 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, -1, 9);
93 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
94 cpl_test_null(pErr);
95
96 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, -1);
97 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
98 cpl_test_null(pErr);
99
100 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 0, 9);
101 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
102 cpl_test_null(pErr);
103
104 pErr = hdrl_bpm_2d_parameter_create_filtersmooth(4, 5, 6, CPL_FILTER_MEDIAN, CPL_BORDER_NOP, 7, 0);
105 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
106 cpl_test_null(pErr);
107
108 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(-1., 5, 6, 20, 21, 11, 12, 2, 10);
109 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
110 cpl_test_null(pErr);
111
112 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, -1., 6, 20, 21, 11, 12, 2, 10);
113 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
114 cpl_test_null(pErr);
115
116 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, -1, 20, 21, 11, 12, 2, 10);
117 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
118 cpl_test_null(pErr);
119
120 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 12, -1, 10);
121 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
122 cpl_test_null(pErr);
123
124 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 12, 2, -1);
125 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
126 cpl_test_null(pErr);
127
128 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 0, 12, 2, 10);
129 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
130 cpl_test_null(pErr);
131
132 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 21, 11, 0, 2, 10);
133 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
134 cpl_test_null(pErr);
135
136 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 0, 21, 11, 12, 2, 10);
137 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
138 cpl_test_null(pErr);
139
140 pErr = hdrl_bpm_2d_parameter_create_legendresmooth(4, 5, 6, 20, 0, 11, 12, 2, 10);
141 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
142 cpl_test_null(pErr);
143
144
145
146 cpl_parameterlist *plErr;
147 hdrl_parameter *parseErr;
148
149 /* Create parlist: hdrl_bpm_2d_filtersmooth_parameter_create_parlist */
150
151 plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist(NULL, "filter", fil_def);
152 cpl_test_error(CPL_ERROR_NULL_INPUT);
153 cpl_test_null(plErr);
154
155 plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", NULL, fil_def);
156 cpl_test_error(CPL_ERROR_NULL_INPUT);
157 cpl_test_null(plErr);
158
159 plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", "filter", NULL);
160 cpl_test_error(CPL_ERROR_NULL_INPUT);
161 cpl_test_null(plErr);
162
163 plErr = hdrl_bpm_2d_filtersmooth_parameter_create_parlist("test", "filter", fil_def);
164 cpl_test_error(CPL_ERROR_NONE);
165 cpl_test_nonnull(plErr);
166
167 parseErr = hdrl_bpm_2d_parameter_parse_parlist(NULL, "filter");
168 cpl_test_error(CPL_ERROR_NULL_INPUT);
169 cpl_test_null(parseErr);
170
171 parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, NULL);
172 cpl_test_error(CPL_ERROR_NULL_INPUT);
173 cpl_test_null(parseErr);
174
175 parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, "filter");
176 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
177 cpl_test_null(parseErr);
178
179 cpl_parameterlist_delete(plErr);
180
181
182
183 /* Create parlist: hdrl_bpm_2d_legendresmooth_parameter_create_parlist */
184
185 plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist(NULL, "legendre", leg_def);
186 cpl_test_error(CPL_ERROR_NULL_INPUT);
187 cpl_test_null(plErr);
188
189 plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", NULL, leg_def);
190 cpl_test_error(CPL_ERROR_NULL_INPUT);
191 cpl_test_null(plErr);
192
193 plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", "legendre", NULL);
194 cpl_test_error(CPL_ERROR_NULL_INPUT);
195 cpl_test_null(plErr);
196
197 plErr = hdrl_bpm_2d_legendresmooth_parameter_create_parlist("test", "legendre", leg_def);
198 cpl_test_error(CPL_ERROR_NONE);
199 cpl_test_nonnull(plErr);
200
201 parseErr = hdrl_bpm_2d_parameter_parse_parlist(NULL, "legendre");
202 cpl_test_error(CPL_ERROR_NULL_INPUT);
203 cpl_test_null(parseErr);
204
205 parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, NULL);
206 cpl_test_error(CPL_ERROR_NULL_INPUT);
207 cpl_test_null(parseErr);
208
209 parseErr = hdrl_bpm_2d_parameter_parse_parlist(plErr, "legendre");
210 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
211 cpl_test_null(parseErr);
212
213 cpl_parameterlist_delete(plErr);
214
215
216
217
218 /* Create parlist: hdrl_bpm_2d_parameter_create_parlist */
219 plErr = hdrl_bpm_2d_parameter_create_parlist(NULL, "bpm", "FILTER", fil_def, leg_def);
220 cpl_test_error(CPL_ERROR_NULL_INPUT);
221 cpl_test_null(plErr);
222
223 plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", NULL, "FILTER", fil_def, leg_def);
224 cpl_test_error(CPL_ERROR_NULL_INPUT);
225 cpl_test_null(plErr);
226
227 plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", NULL, fil_def, leg_def);
228 cpl_test_error(CPL_ERROR_NULL_INPUT);
229 cpl_test_null(plErr);
230
231 plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", NULL, leg_def);
232 cpl_test_error(CPL_ERROR_NULL_INPUT);
233 cpl_test_null(plErr);
234
235 plErr = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", fil_def, NULL);
236 cpl_test_error(CPL_ERROR_NULL_INPUT);
237 cpl_test_null(plErr);
238
239 cpl_parameterlist * pos = hdrl_bpm_2d_parameter_create_parlist("RECIPE", "bpm", "FILTER", fil_def, leg_def);
240 cpl_test_error(CPL_ERROR_NONE);
241 cpl_test_eq(cpl_parameterlist_get_size(pos), 17);
242
243
244
245
246
247
248
249 hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.invalid");
250 cpl_test_null(hpar);
251 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
252
253 hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.bpm");
254 cpl_parameterlist_delete(pos);
255 cpl_test_error(CPL_ERROR_NONE);
256
257 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(NULL), CPL_FILTER_EROSION);
258 cpl_test_error(CPL_ERROR_NULL_INPUT);
259 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(hpar), CPL_FILTER_MEDIAN);
260 cpl_test_error(CPL_ERROR_NONE);
261
262 cpl_test_eq(hdrl_bpm_2d_parameter_get_border(NULL), CPL_BORDER_FILTER);
263 cpl_test_error(CPL_ERROR_NULL_INPUT);
264 cpl_test_eq(hdrl_bpm_2d_parameter_get_border(hpar), CPL_BORDER_NOP);
265 cpl_test_error(CPL_ERROR_NONE);
266
267 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(NULL), -1.);
268 cpl_test_error(CPL_ERROR_NULL_INPUT);
269 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(hpar), 4);
270 cpl_test_error(CPL_ERROR_NONE);
271
272 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(NULL), -1.);
273 cpl_test_error(CPL_ERROR_NULL_INPUT);
274 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(hpar), 5);
275 cpl_test_error(CPL_ERROR_NONE);
276
277 cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(NULL), -1);
278 cpl_test_error(CPL_ERROR_NULL_INPUT);
279 cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(hpar), 6);
280 cpl_test_error(CPL_ERROR_NONE);
281
282 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(NULL), -1);
283 cpl_test_error(CPL_ERROR_NULL_INPUT);
284 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(hpar), 7);
285 cpl_test_error(CPL_ERROR_NONE);
286
287 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(NULL), -1);
288 cpl_test_error(CPL_ERROR_NULL_INPUT);
289 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(hpar), 9);
290 cpl_test_error(CPL_ERROR_NONE);
291
292 /* TODO wrong par error? */
293 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(NULL), -1);
294 cpl_test_error(CPL_ERROR_NULL_INPUT);
295 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(hpar), 0);
296 cpl_test_error(CPL_ERROR_NONE);
297
298 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(NULL), -1);
299 cpl_test_error(CPL_ERROR_NULL_INPUT);
300 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(hpar), 0);
301 cpl_test_error(CPL_ERROR_NONE);
302
303 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(NULL), -1);
304 cpl_test_error(CPL_ERROR_NULL_INPUT);
305 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(hpar), 0);
306 cpl_test_error(CPL_ERROR_NONE);
307
308 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(NULL), -1);
309 cpl_test_error(CPL_ERROR_NULL_INPUT);
310 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(hpar), 0);
311 cpl_test_error(CPL_ERROR_NONE);
312
313 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(NULL), -1);
314 cpl_test_error(CPL_ERROR_NULL_INPUT);
315 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(hpar), 0);
316 cpl_test_error(CPL_ERROR_NONE);
317
318 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(NULL), -1);
319 cpl_test_error(CPL_ERROR_NULL_INPUT);
320 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(hpar), 0);
321 cpl_test_error(CPL_ERROR_NONE);
322
324
326 "RECIPE", "bpm", "LEGENDRE", fil_def, leg_def);
327 cpl_test_error(CPL_ERROR_NONE);
328
329 hpar = hdrl_bpm_2d_parameter_parse_parlist(pos, "RECIPE.bpm");
330 cpl_parameterlist_delete(pos);
331 cpl_test_error(CPL_ERROR_NONE);
332
333 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_low(hpar), 4);
334 cpl_test_eq(hdrl_bpm_2d_parameter_get_kappa_high(hpar), 5);
335 cpl_test_eq(hdrl_bpm_2d_parameter_get_maxiter(hpar), 6);
336 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_x(hpar), 20);
337 cpl_test_eq(hdrl_bpm_2d_parameter_get_steps_y(hpar), 21);
338 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_x(hpar), 11);
339 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter_size_y(hpar), 12);
340 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_x(hpar), 2);
341 cpl_test_eq(hdrl_bpm_2d_parameter_get_order_y(hpar), 10);
342 /* TODO wrong par error? */
343 cpl_test_eq(hdrl_bpm_2d_parameter_get_filter(hpar), CPL_FILTER_MEDIAN);
344 cpl_test_eq(hdrl_bpm_2d_parameter_get_border(hpar), CPL_BORDER_FILTER);
345 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_x(hpar), 0);
346 cpl_test_eq(hdrl_bpm_2d_parameter_get_smooth_y(hpar), 0);
347
349 cpl_test_error(CPL_ERROR_NULL_INPUT);
350 cpl_test_eq(hdrl_bpm_2d_parameter_get_method(hpar), HDRL_BPM_2D_LEGENDRESMOOTH);
351 cpl_test_error(CPL_ERROR_NONE);
352
354
355
356 cpl_test(!strcmp(filter_to_string(CPL_FILTER_EROSION), "EROSION"));
357 cpl_test(!strcmp(filter_to_string(CPL_FILTER_DILATION), "DILATION"));
358 cpl_test(!strcmp(filter_to_string(CPL_FILTER_OPENING), "OPENING"));
359 cpl_test(!strcmp(filter_to_string(CPL_FILTER_CLOSING), "CLOSING"));
360 cpl_test(!strcmp(filter_to_string(CPL_FILTER_LINEAR), "LINEAR"));
361 cpl_test(!strcmp(filter_to_string(CPL_FILTER_LINEAR_SCALE), "LINEAR_SCALE"));
362 cpl_test(!strcmp(filter_to_string(CPL_FILTER_AVERAGE), "AVERAGE"));
363 cpl_test(!strcmp(filter_to_string(CPL_FILTER_AVERAGE_FAST), "AVERAGE_FAST"));
364 cpl_test(!strcmp(filter_to_string(CPL_FILTER_MEDIAN), "MEDIAN"));
365 cpl_test(!strcmp(filter_to_string(CPL_FILTER_STDEV), "STDEV"));
366 cpl_test(!strcmp(filter_to_string(CPL_FILTER_STDEV_FAST), "STDEV_FAST"));
367 cpl_test(!strcmp(filter_to_string(CPL_FILTER_MORPHO), "MORPHO"));
368 cpl_test(!strcmp(filter_to_string(CPL_FILTER_MORPHO_SCALE), "MORPHO_SCALE"));
369
370 cpl_test(!strcmp(border_to_string(CPL_BORDER_FILTER), "FILTER"));
371 cpl_test(!strcmp(border_to_string(CPL_BORDER_ZERO), "ZERO"));
372 cpl_test(!strcmp(border_to_string(CPL_BORDER_CROP), "CROP"));
373 cpl_test(!strcmp(border_to_string(CPL_BORDER_NOP), "NOP"));
374 cpl_test(!strcmp(border_to_string(CPL_BORDER_COPY), "COPY"));
375
376
377 hdrl_parameter_delete(leg_def);
378 hdrl_parameter_delete(fil_def);
379}
380
381/*----------------------------------------------------------------------------*/
386/*----------------------------------------------------------------------------*/
387static cpl_error_code hdrl_bpm_2d_test_compute(void)
388{
389 cpl_image * data = NULL;
390 cpl_image * errors = NULL;
391 cpl_mask * mask_out = NULL;
392 hdrl_parameter * bpm_param;
393
394 /* Create BPM parameters */
395 bpm_param = hdrl_bpm_2d_parameter_create_filtersmooth(3., 3., 2,
396 CPL_FILTER_MEDIAN, CPL_BORDER_FILTER, 3, 3) ;
397 cpl_test(hdrl_bpm_2d_parameter_check(bpm_param));
398
399 { /* Test sigmaclipped mean */
400 /* gauss mean 100 sigma 3.5 and 2 outliers */
401 double values[] = {92, 93, 94, 94, 95, 95, 96, 96, 96, 97,
402 97, 97, 97, 98, 98, 98, 98, 99, 99, 99,
403 99, 100, 100, 100, 100, 100, 101, 101, 101, 101,
404 102, 102, 102, 102, 103, 103, 103, 103, 104, 104,
405 104, 105, 105, 106, 106, 107, 108, 500, 600 };
406
407 data = cpl_image_wrap(7, 7, CPL_TYPE_DOUBLE, values);
408 errors = cpl_image_new(7, 7, CPL_TYPE_DOUBLE);
409 cpl_image_add_scalar(errors, 1);
410
411 cpl_image_set(errors, 7, 7, 100000.);
412 cpl_image_set(errors, 6, 7, 10000.);
413
414 hdrl_image * sigimage = hdrl_image_create(data, errors);
415
416 mask_out = hdrl_bpm_2d_compute(NULL, bpm_param);
417 cpl_test_error(CPL_ERROR_NULL_INPUT);
418 cpl_test_null(mask_out);
419
420 mask_out = hdrl_bpm_2d_compute(sigimage, NULL);
421 cpl_test_error(CPL_ERROR_NULL_INPUT);
422 cpl_test_null(mask_out);
423
424
425 mask_out = hdrl_bpm_2d_compute(sigimage, bpm_param);
426 cpl_test_error(CPL_ERROR_NONE);
427 cpl_test_nonnull(mask_out);
428
429 cpl_mask_delete(mask_out);
430
431 hdrl_parameter_delete(bpm_param) ;
433 2, 20, 20, 11, 11, 3, 3);
434 cpl_test(hdrl_bpm_2d_parameter_check(bpm_param));
435
436
437 mask_out = hdrl_bpm_2d_compute(sigimage, bpm_param) ;
438
439 //cpl_mask_save(mask_out, "bpm1.fits", NULL, CPL_IO_CREATE);
440
441 cpl_mask_delete(mask_out);
442 cpl_image_unwrap(data);
443 cpl_image_delete(errors);
444 hdrl_image_delete(sigimage);
445 }
446
447 {
448 cpl_mask * data_bpm = cpl_mask_new(200, 300);
449 data = cpl_image_new(200, 300, CPL_TYPE_FLOAT);
450
451 cpl_image_fill_noise_uniform(data, 90, 110);
452 cpl_image_set(data, 50, 50, 300.);
453 cpl_image_set(data, 100, 100, 300.);
454 cpl_image_set(data, 150, 150, 300.);
455 cpl_image_set(data, 110, 260, 300.);
456
457 cpl_mask_set(data_bpm, 120,120, CPL_BINARY_1);
458 cpl_mask_set(data_bpm, 120,121, CPL_BINARY_1);
459 cpl_mask_set(data_bpm, 120,122, CPL_BINARY_1);
460 cpl_mask_set(data_bpm, 121,120, CPL_BINARY_1);
461 cpl_mask_set(data_bpm, 121,121, CPL_BINARY_1);
462 cpl_mask_set(data_bpm, 121,122, CPL_BINARY_1);
463 cpl_mask_set(data_bpm, 122,120, CPL_BINARY_1);
464 cpl_mask_set(data_bpm, 122,121, CPL_BINARY_1);
465 cpl_mask_set(data_bpm, 122,122, CPL_BINARY_1);
466 /*set one outlier on a bad pixel*/
467 cpl_image_set(data, 122, 122, 300.);
468
469 cpl_image_reject_from_mask(data, data_bpm);
470
471 errors=cpl_image_power_create(data, 0.5);
472 hdrl_image * image = hdrl_image_create(data, errors);
473
474 /* Note that for CPL_FILTER_STDEV one gets more false positives!! */
475 hdrl_parameter_delete(bpm_param) ;
476 bpm_param = hdrl_bpm_2d_parameter_create_filtersmooth(3., 3., 5,
477 CPL_FILTER_MEDIAN, CPL_BORDER_FILTER, 3, 3) ;
478 cpl_test(hdrl_bpm_2d_parameter_check(bpm_param));
479 mask_out = hdrl_bpm_2d_compute(image, bpm_param) ;
480 cpl_test_eq(cpl_mask_get(mask_out, 50, 50), CPL_BINARY_1);
481 cpl_test_eq(cpl_mask_get(mask_out, 100, 100), CPL_BINARY_1);
482 cpl_test_eq(cpl_mask_get(mask_out, 150, 150), CPL_BINARY_1);
483 cpl_test_eq(cpl_mask_get(mask_out, 110, 260), CPL_BINARY_1);
484 cpl_test_eq(cpl_mask_get(mask_out, 122, 122), CPL_BINARY_0);
485 cpl_mask_delete(mask_out);
486
487 hdrl_parameter_delete(bpm_param) ;
489 5, 20, 20, 11, 11, 3, 3);
490 cpl_test(hdrl_bpm_2d_parameter_check(bpm_param));
491 mask_out = hdrl_bpm_2d_compute(image, bpm_param) ;
492 cpl_test_eq(cpl_mask_get(mask_out, 50, 50), CPL_BINARY_1);
493 cpl_test_eq(cpl_mask_get(mask_out, 100, 100), CPL_BINARY_1);
494 cpl_test_eq(cpl_mask_get(mask_out, 150, 150), CPL_BINARY_1);
495 cpl_test_eq(cpl_mask_get(mask_out, 110, 260), CPL_BINARY_1);
496 cpl_test_eq(cpl_mask_get(mask_out, 122, 122), CPL_BINARY_0);
497
498 cpl_mask_delete(data_bpm);
499 cpl_mask_delete(mask_out);
500 cpl_image_delete(data);
501 cpl_image_delete(errors);
502 hdrl_image_delete(image);
503 }
504 hdrl_parameter_delete(bpm_param) ;
505 return cpl_error_get_code();
506}
507
508/*----------------------------------------------------------------------------*/
512/*----------------------------------------------------------------------------*/
513int main(void)
514{
515 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
516 hdrl_bpm_2d_test_compute();
517 test_parlist();
518 cpl_test_error(CPL_ERROR_NONE);
519 return cpl_test_end(0);
520}
cpl_mask * hdrl_bpm_2d_compute(const hdrl_image *img_in, const hdrl_parameter *params)
Detect bad pixels on a single image with an iterative process.
Definition: hdrl_bpm_2d.c:1136
hdrl_bpm_2d_method hdrl_bpm_2d_parameter_get_method(const hdrl_parameter *p)
Access the method in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:495
double hdrl_bpm_2d_parameter_get_kappa_high(const hdrl_parameter *p)
Access the kappa_high in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:355
int hdrl_bpm_2d_parameter_get_maxiter(const hdrl_parameter *p)
Access the maxiter in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:369
cpl_border_mode hdrl_bpm_2d_parameter_get_border(const hdrl_parameter *p)
Access the border in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:327
int hdrl_bpm_2d_parameter_get_filter_size_y(const hdrl_parameter *p)
Access the filter_size_y in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:425
int hdrl_bpm_2d_parameter_get_smooth_y(const hdrl_parameter *p)
Access the smooth_y in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:467
int hdrl_bpm_2d_parameter_get_order_y(const hdrl_parameter *p)
Access the order_y in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:453
hdrl_parameter * hdrl_bpm_2d_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *prefix)
Parse parameter list to create input parameters for the BPM_2D.
Definition: hdrl_bpm_2d.c:896
int hdrl_bpm_2d_parameter_get_filter_size_x(const hdrl_parameter *p)
Access the filter_size_x in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:411
hdrl_parameter * hdrl_bpm_2d_parameter_create_filtersmooth(double kappa_low, double kappa_high, int maxiter, cpl_filter_mode filter, cpl_border_mode border, int smooth_x, int smooth_y)
Creates BPM_2D Parameters object for HDRL_BPM_2D_FILTERSMOOTH.
Definition: hdrl_bpm_2d.c:137
int hdrl_bpm_2d_parameter_get_smooth_x(const hdrl_parameter *p)
Access the smooth_x in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:481
int hdrl_bpm_2d_parameter_get_steps_x(const hdrl_parameter *p)
Access the steps_x in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:383
cpl_filter_mode hdrl_bpm_2d_parameter_get_filter(const hdrl_parameter *p)
Access the filter in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:313
cpl_error_code hdrl_bpm_2d_parameter_verify(const hdrl_parameter *param)
Verify basic correctness of the BPM_2D parameters.
Definition: hdrl_bpm_2d.c:232
cpl_parameterlist * hdrl_bpm_2d_parameter_create_parlist(const char *base_context, const char *prefix, const char *method_def, const hdrl_parameter *filtersmooth_def, const hdrl_parameter *legendresmooth_def)
Create parameter list for the BPM_2D computation.
Definition: hdrl_bpm_2d.c:798
int hdrl_bpm_2d_parameter_get_order_x(const hdrl_parameter *p)
Access the order_x in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:439
int hdrl_bpm_2d_parameter_get_steps_y(const hdrl_parameter *p)
Access the steps_y in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:397
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.
Definition: hdrl_bpm_2d.c:191
cpl_boolean hdrl_bpm_2d_parameter_check(const hdrl_parameter *self)
Check that the parameter is a BPM_2D parameter.
Definition: hdrl_bpm_2d.c:301
double hdrl_bpm_2d_parameter_get_kappa_low(const hdrl_parameter *p)
Access the kappa_low in the BPM_2D parameter.
Definition: hdrl_bpm_2d.c:341
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
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter