CR2RE Pipeline Reference Manual 1.7.0
cr2res_calib.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 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 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <math.h>
29#include <float.h>
30#include <cpl.h>
31#include "cr2res_calib.h"
32#include "cr2res_bpm.h"
33#include "cr2res_pfits.h"
34#include "cr2res_io.h"
35#include "cr2res_detlin.h"
36#include "cr2res_utils.h"
37
38/*-----------------------------------------------------------------------------
39 Functions prototypes
40 -----------------------------------------------------------------------------*/
41
42int cr2res_add_shotnoise(hdrl_image * in, double dit, int ndit, int ndsamples,
43 int chip);
45 const hdrl_image * flat, cpl_size degree);
46
47/*----------------------------------------------------------------------------*/
51/*----------------------------------------------------------------------------*/
52
54
55/*----------------------------------------------------------------------------*/
74/*----------------------------------------------------------------------------*/
75hdrl_imagelist * cr2res_calib_imagelist(
76 const hdrl_imagelist * in,
77 int chip,
78 int clean_bad,
79 int subtract_nolight_rows,
80 int subtract_interorder_column,
81 int cosmics_corr,
82 const cpl_frame * flat,
83 const cpl_frame * dark,
84 const cpl_frame * bpm,
85 const cpl_frame * detlin,
86 const cpl_vector * dits,
87 const cpl_vector * ndits,
88 const cpl_vector * ndsamples)
89{
90 hdrl_imagelist * out ;
91 double dit ;
92 int ndit ;
93 int ndsamp ;
94 cpl_size i ;
95
96 /* Check Inputs */
97 if (in == NULL) return NULL ;
98
99 /* Initialise */
100 dit = 0.0 ;
101 ndit = 1 ;
102 ndsamp = -1 ;
103
104 /* Create calibrated image list */
105 out = hdrl_imagelist_new() ;
106
107 /* Loop on the images */
108 for (i = 0; i < hdrl_imagelist_get_size(in); i++) {
109 const hdrl_image *cur_ima;
110 hdrl_image *cur_ima_calib;
111 cur_ima = hdrl_imagelist_get(in, i) ;
112 //if (dark != NULL) dit = cpl_vector_get(dits, i) ;
113 if (dits != NULL) dit = cpl_vector_get(dits, i) ;
114 if (ndits != NULL) ndit = (int)cpl_vector_get(ndits, i) ;
115 if (ndsamples != NULL) ndsamp = (int)cpl_vector_get(ndsamples, i) ;
116
117 /* Calibrate */
118 cpl_msg_info(__func__,
119 "Apply calibrations for image #%"CPL_SIZE_FORMAT, i+1) ;
120 cpl_msg_indent_more() ;
121 if ((cur_ima_calib = cr2res_calib_image(cur_ima, chip, clean_bad,
122 subtract_nolight_rows, subtract_interorder_column,
123 cosmics_corr, flat, dark, bpm,
124 detlin, dit, ndit, ndsamp)) == NULL) {
125 cpl_msg_error(__func__, "Failed to Calibrate the Data") ;
127 cpl_msg_indent_less() ;
128 return NULL ;
129 } else {
130 /* All the calibrated image in the list */
131 hdrl_imagelist_set(out, cur_ima_calib, i);
132 }
133 cpl_msg_indent_less() ;
134 }
135 return out ;
136}
137
138/*----------------------------------------------------------------------------*/
157/*----------------------------------------------------------------------------*/
159 const hdrl_image * in,
160 int chip,
161 int clean_bad,
162 int subtract_nolight_rows,
163 int subtract_interorder_column,
164 int cosmics_corr,
165 const cpl_frame * flat,
166 const cpl_frame * dark,
167 const cpl_frame * bpm,
168 const cpl_frame * detlin,
169 double dit,
170 int ndit,
171 int ndsamples)
172{
173 hdrl_image * out ;
174 hdrl_image * calib ;
175 hdrl_imagelist * calib_list ;
176
177 /* Test entries */
178 if (in == NULL) return NULL ;
179 if (chip < 1 || chip > CR2RES_NB_DETECTORS) return NULL ;
180
181 /* Create out image */
182 out = hdrl_image_duplicate(in) ;
183
184 /* Clean the bad pixels */
185 if (bpm != NULL) {
186 cpl_msg_info(__func__, "Correct the bad pixels") ;
188 cpl_frame_get_filename(bpm), chip, clean_bad) != 0) {
189 cpl_msg_error(__func__, "Cannot clean the bad pixels");
191 return NULL ;
192 }
193 }
194
195 /* Apply the non linearity correction */
196 if (detlin != NULL) {
197 cpl_msg_info(__func__, "Correct for the Non-Linearity") ;
198 if ((calib_list = cr2res_io_load_DETLIN_COEFFS(
199 cpl_frame_get_filename(detlin), chip)) == NULL) {
200 cpl_msg_error(__func__, "Cannot load the detlin") ;
202 return NULL ;
203 }
204 /* Detlin correction */
205 if (cr2res_detlin_correct(out, calib_list)) {
206 hdrl_imagelist_delete(calib_list) ;
208 cpl_msg_error(__func__, "Cannot correct for the Non-Linearity") ;
209 return NULL ;
210 }
211 }
212
213 /* Add shot-noise */
214 cpl_msg_info(__func__, "Add shot-noise") ;
215 if (cr2res_add_shotnoise(out, dit, ndit, ndsamples, chip)){
216 cpl_msg_error(__func__, "Cannot add shot-noise") ;
217 if(detlin != NULL)
218 hdrl_imagelist_delete(calib_list) ;
220 return NULL ;
221 }
222
223 /* Apply the dark */
224 if (dark != NULL) {
225 cpl_propertylist *plist;
226 double dark_dit;
227 cpl_msg_info(__func__, "Correct for the dark") ;
228
229 /* Load the dark */
230 if ((calib = cr2res_io_load_MASTER_DARK(cpl_frame_get_filename(dark),
231 chip)) == NULL) {
232 cpl_msg_error(__func__, "Cannot load the dark") ;
234 return NULL ;
235 }
236 if (detlin != NULL) {
237 cpl_msg_indent_more() ;
238 cpl_msg_info(__func__, "Correct DARK for Non-Linearity") ;
239 if (cr2res_detlin_correct(calib, calib_list)) {
240 hdrl_imagelist_delete(calib_list) ;
241 hdrl_image_delete(calib) ;
243 cpl_msg_error(__func__,"Cannot correct DARK for Non-Linearity");
244 cpl_msg_indent_less() ;
245 return NULL ;
246 }
247 cpl_msg_indent_less() ;
248 }
249
250 /* Get the dark DIT */
251 plist = cpl_propertylist_load(cpl_frame_get_filename(dark), 0);
252 dark_dit = cr2res_pfits_get_dit(plist) ;
253 cpl_propertylist_delete(plist) ;
254 /* Multiply the dark by dit/dark_dit */
255 hdrl_value hdrl_dit_corr = {dit/dark_dit, 0.0};
256 hdrl_image_mul_scalar(calib, hdrl_dit_corr) ;
257
258 /* Subtract the dark */
259 if (hdrl_image_sub_image(out, calib) != CPL_ERROR_NONE) {
260 cpl_msg_error(__func__, "Cannot apply the dark") ;
261 hdrl_image_delete(calib) ;
263 return NULL ;
264 }
265 hdrl_image_delete(calib) ;
266 }
267 if (detlin != NULL) {
268 hdrl_imagelist_delete(calib_list) ;
269 }
270
271 /* Subtract residual bias/dark from vignetted rows at bottom */
272 if (subtract_nolight_rows) {
273 cpl_size i;
274 cpl_image *img_tmp;
275 cpl_msg_info(__func__, "Subtract median of bottom rows");
276
277 img_tmp = cpl_image_collapse_median_create(
278 hdrl_image_get_image(out), 0, CR2RES_NB_BPM_EDGEPIX,
279 CR2RES_DETECTOR_SIZE-CR2RES_NB_BPM_VIGN_BOTTOM);
280 calib = hdrl_image_new(CR2RES_DETECTOR_SIZE,CR2RES_DETECTOR_SIZE);
281 for (i=1; i<=CR2RES_DETECTOR_SIZE; i++) {
282 hdrl_image_insert(calib, img_tmp, NULL, 1, i);
283 }
284 hdrl_image_sub_image(out, calib);
285 hdrl_image_delete(calib) ;
286 cpl_image_delete(img_tmp);
287 }
288
289 /* Apply the interorder correction */
290 if (subtract_interorder_column) {
291 if (flat == NULL) {
292 cpl_msg_info(__func__,
293 "Skip subtracting fit to inter-order pixels (no flat-field)");
294 } else {
295 cpl_msg_info(__func__, "Subtract fit to inter-order pixels");
296 if ((calib = cr2res_io_load_MASTER_FLAT(
297 cpl_frame_get_filename(flat), chip)) == NULL) {
298 cpl_msg_error(__func__, "Cannot load the flat field") ;
300 return NULL ;
301 }
302 if (cr2res_calib_subtract_interorder_column(out, calib, 0)){
303 cpl_msg_error(__func__, "Could not subtract inter-order fit");
304 }
305 hdrl_image_delete(calib);
306 }
307 }
308
309 /* Apply the flatfield */
310 if (flat != NULL) {
311 cpl_msg_info(__func__, "Correct for the flat field") ;
312 /* Load the flat */
313 if ((calib = cr2res_io_load_MASTER_FLAT(
314 cpl_frame_get_filename(flat), chip)) == NULL) {
315 cpl_msg_error(__func__, "Cannot load the flat field") ;
317 return NULL ;
318 }
319
320 /* Divide */
321 if (hdrl_image_div_image(out, calib) != CPL_ERROR_NONE) {
322 cpl_msg_error(__func__, "Cannot apply the flat field") ;
323 hdrl_image_delete(calib) ;
325 return NULL ;
326 }
327 hdrl_image_delete(calib) ;
328 }
329
330
331 /* Comics correction */
332 if (cosmics_corr) {
333 cpl_msg_info(__func__, "Apply the cosmics corrections") ;
334 hdrl_parameter * cospar = hdrl_lacosmic_parameter_create(12.0,2.5,1);
335 if (hdrl_lacosmic_parameter_verify(cospar)!=CPL_ERROR_NONE)
336 cpl_msg_warning(__func__,"invalid cospar");
337 cpl_mask* cosmask = hdrl_lacosmic_edgedetect(out,cospar);
338 cpl_mask_or(hdrl_image_get_mask(out), cosmask);
339 cpl_mask_delete(cosmask);
340 hdrl_parameter_delete(cospar);
341 }
342
343 return out ;
344}
345
346/*----------------------------------------------------------------------------*/
354/*----------------------------------------------------------------------------*/
355static double cr2res_utr_shot_factor(int ndsamples)
356{
357 double n ;
358 if (ndsamples < 2) return 1.0 ;
359 n = (double)ndsamples ;
360 return 6.0 * (n * n + 1.0) / (5.0 * n * (n + 1.0)) ;
361}
362
363/*----------------------------------------------------------------------------*/
375/*----------------------------------------------------------------------------*/
376int cr2res_add_shotnoise(hdrl_image * in, double dit, int ndit, int ndsamples,
377 int chip)
378{
379 cpl_image * error ;
380 cpl_image * var ;
381 double gain, alpha, read_noise, min_rn ;
382 const double min_dit = 1.427 ;
383 const double lim_dit = 50.0 ;
384 const double lim_rn = 6.0 ;
385
386 if (in == NULL) return -1 ;
387 error = hdrl_image_get_error(in) ;
388 if (hdrl_image_get_image_const(in) == NULL || error == NULL) {
389 cpl_msg_error(__func__, "Broken input image") ;
390 return -1 ;
391 }
392 if (ndit < 1) {
393 cpl_msg_error(__func__, "Invalid NDIT: %d", ndit) ;
394 return -1 ;
395 }
396
397 if (chip == 1) gain = CR2RES_GAIN_CHIP1 ;
398 else if (chip == 2) gain = CR2RES_GAIN_CHIP2 ;
399 else if (chip == 3) gain = CR2RES_GAIN_CHIP3 ;
400 else {
401 cpl_msg_error(__func__, "Unknown detector") ;
402 return -1 ;
403 }
404
405 /* Effective read noise per DIT in e-, from the CRIRES user manual */
406 min_rn = (chip == 1) ? 11.0 : 12.0 ;
407 if (dit <= min_dit) read_noise = min_rn ;
408 else if (dit >= lim_dit) read_noise = lim_rn ;
409 else read_noise = min_rn + (lim_rn-min_rn)*(dit-min_dit)/(lim_dit-min_dit);
410
411 alpha = cr2res_utr_shot_factor(ndsamples) ;
412
413 cpl_msg_debug(__func__, "chip:%d, gain:%g, ndit:%d, ndsamples:%d, "
414 "alpha:%g, read_noise:%g", chip, gain, ndit, ndsamples, alpha,
415 read_noise) ;
416
417 if ((var = cpl_image_duplicate(hdrl_image_get_image_const(in))) == NULL) {
418 cpl_msg_error(__func__, "Cannot duplicate the input image") ;
419 return -1 ;
420 }
421 cpl_image_threshold(var, 0.0, DBL_MAX, 0.0, DBL_MAX) ;
422 cpl_image_multiply_scalar(var, alpha / (gain * ndit)) ;
423 cpl_image_add_scalar(var, read_noise * read_noise / (gain * gain * ndit)) ;
424
425 /* The BPM should not be stored in the error image */
426 cpl_image_accept_all(var) ;
427
428 if (cpl_image_power(error, 2.0) != CPL_ERROR_NONE ||
429 cpl_image_add(error, var) != CPL_ERROR_NONE ||
430 cpl_image_power(error, 0.5) != CPL_ERROR_NONE) {
431 cpl_msg_error(__func__, "Cannot combine the errors") ;
432 cpl_image_delete(var) ;
433 return -1 ;
434 }
435 cpl_image_delete(var) ;
436 return 0 ;
437}
438
439/*----------------------------------------------------------------------------*/
451/*----------------------------------------------------------------------------*/
453 const hdrl_image * flat, cpl_size degree)
454{
455 // Define Parameters
456 cpl_image * img;
457 const cpl_image * flat_img;
458 cpl_polynomial * poly;
459 cpl_vector * tmp;
460 cpl_size ncolumns, nrow;
461 cpl_size i, j;
462 int badpix;
463 int badcols = 0;
464 double value, median, mad;
465
466 // Check Input
467 if (in == NULL || flat == NULL) return -1;
468 if (hdrl_image_get_size_x(in) != hdrl_image_get_size_x(flat)) return -1;
469 if (hdrl_image_get_size_y(in) != hdrl_image_get_size_y(flat)) return -1;
470
471 // Loop over the columns
472 img = hdrl_image_get_image(in);
473 flat_img = hdrl_image_get_image_const(flat);
474 ncolumns = cpl_image_get_size_x(img);
475 nrow = cpl_image_get_size_y(img);
476
477
478 for (i = CR2RES_NB_BPM_EDGEPIX + 1; i < ncolumns - CR2RES_NB_BPM_EDGEPIX;
479 i++) {
480 cpl_size npixel;
481 cpl_matrix *px;
482 cpl_vector *py;
483 // Fill vectors and matrix
484 px = cpl_matrix_new(1, nrow);
485 py = cpl_vector_new(nrow);
486 npixel = 0;
487 for ( j = CR2RES_NB_BPM_VIGN_BOTTOM + 5; j < nrow -20 ; j++)
488 {
489 // Filter pixels that are rejected in the flat (i.e. between orders)
490 // but not rejected by the image (i.e. not bad pixels)
491 if (cpl_image_is_rejected(flat_img, i, j)
492 && !cpl_image_is_rejected(img, i, j) &&
493 isnan(cpl_image_get(img, i, j, &badpix)) == 0){
494 cpl_matrix_set(px, 0, npixel, j);
495 cpl_vector_set(py, npixel, cpl_image_get(img, i, j, &badpix));
496 npixel++;
497 }
498 }
499 cpl_msg_debug(__func__, "Column %lld has %lld pixels for background",
500 i,npixel);
501 if (npixel < 10){
502 badcols += 1;
503 cpl_matrix_delete(px);
504 cpl_vector_delete(py);
505 continue;
506 }
507 cpl_matrix_set_size(px, 1, npixel);
508 cpl_vector_set_size(py, npixel);
509
510 // Reject outliers and filter
511 median = cr2res_vector_get_mad(py, &mad);
512 for (j=0;j<npixel;j++){
513 // Filtering for the range: median - 1*median to median + 1*median
514 if ((cpl_vector_get(py,j) > median*2) || (cpl_vector_get(py,j) < 0.0) )
515 cpl_vector_set(py,j,median);
516 }
517 //tmp = cpl_vector_filter_median_create(py,50);
518 tmp = cpl_vector_filter_lowpass_create(py,CPL_LOWPASS_LINEAR,100);
519 cpl_vector_delete(py);
520 py=tmp;
521 if (cpl_msg_get_level() == CPL_MSG_DEBUG){
522 tmp = cpl_vector_wrap(npixel, cpl_matrix_get_data(px));
523 cpl_vector_save(tmp, "debug_background.fits",
524 CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE);
525 cpl_vector_save(py, "debug_background.fits",
526 CPL_TYPE_DOUBLE, NULL, CPL_IO_EXTEND);
527 cpl_vector_unwrap(tmp);
528 }
529
530 // Fit polynomial
531 poly = cpl_polynomial_new(1);
532 if (cpl_polynomial_fit(poly, px, NULL, py, NULL, CPL_FALSE, NULL,
533 &degree)
534 != CPL_ERROR_NONE) {
535 badcols += 1;
536 cpl_msg_warning(__func__,
537 "Could not fit the background of column %"CPL_SIZE_FORMAT, i);
538 cpl_error_reset();
539 cpl_matrix_delete(px);
540 cpl_vector_delete(py);
541 cpl_polynomial_delete(poly);
542 continue;
543 }
544
545 // Subtract column
546 for ( j = 1; j < nrow + 1; j++)
547 {
548 value = cpl_image_get(img, i, j, &badpix);
549 // Just skip this pixel if it is bad
550 if (badpix) continue;
551 value -= cpl_polynomial_eval_1d(poly, j, NULL);
552 cpl_image_set(img, i, j, value);
553 }
554
555 // Clean up
556 cpl_matrix_delete(px);
557 cpl_vector_delete(py);
558 cpl_polynomial_delete(poly);
559 }
560
561 if (badcols){
562 cpl_msg_warning(__func__,
563 "%d columns could not be background-subtracted from inter-order gaps",
564 badcols);
565 }
566 return 0;
567}
568
569/*----------------------------------------------------------------------------*/
577/*----------------------------------------------------------------------------*/
579 hdrl_image * ima,
580 const cpl_image * var)
581{
582 cpl_image * err = hdrl_image_get_error(ima) ;
583 cpl_image_power(err, 2.0) ;
584 cpl_image_add(err, var) ;
585 cpl_image_threshold(err, 0.0, DBL_MAX, 0.0, DBL_MAX) ;
586 cpl_image_power(err, 0.5) ;
587}
588
589/*----------------------------------------------------------------------------*/
595/*----------------------------------------------------------------------------*/
596cpl_image * cr2res_calib_flat_relerr2(const hdrl_image * mflat)
597{
598 cpl_image * relerr2 ;
599
600 if (mflat == NULL) return NULL ;
601 relerr2 = cpl_image_divide_create(hdrl_image_get_error_const(mflat),
603 if (relerr2 == NULL) return NULL ;
604 cpl_image_power(relerr2, 2.0) ;
605 return relerr2 ;
606}
607
608/*----------------------------------------------------------------------------*/
617/*----------------------------------------------------------------------------*/
619 hdrl_image * ima,
620 const cpl_image * relerr2,
621 double sign)
622{
623 cpl_image * term = cpl_image_power_create(
624 hdrl_image_get_image_const(ima), 2.0) ;
625 cpl_image_multiply(term, relerr2) ;
626 cpl_image_multiply_scalar(term, sign) ;
627 cr2res_calib_add_var(ima, term) ;
628 cpl_image_delete(term) ;
629}
630
631/*----------------------------------------------------------------------------*/
644/*----------------------------------------------------------------------------*/
646 hdrl_imagelist * list,
647 const cpl_frame * master_dark_frame,
648 int chip,
649 const hdrl_image * mflat,
650 const cpl_vector * dits,
651 double sign)
652{
653 hdrl_image * mdark ;
654 cpl_propertylist * plist ;
655 cpl_image * var ;
656 double dark_dit ;
657 cpl_size i ;
658
659 if (list == NULL || master_dark_frame == NULL || dits == NULL) return -1 ;
660 if (cpl_vector_get_size(dits) != hdrl_imagelist_get_size(list)) return -1;
661
662 if ((mdark = cr2res_io_load_MASTER_DARK(
663 cpl_frame_get_filename(master_dark_frame), chip)) == NULL)
664 return -1 ;
665 plist = cpl_propertylist_load(cpl_frame_get_filename(master_dark_frame),0);
666 dark_dit = cr2res_pfits_get_dit(plist) ;
667 cpl_propertylist_delete(plist) ;
668 if (cpl_error_get_code() || dark_dit == 0.0) {
669 hdrl_image_delete(mdark) ;
670 return -1 ;
671 }
672
673 var = cpl_image_power_create(hdrl_image_get_error_const(mdark), 2.0) ;
674 hdrl_image_delete(mdark) ;
675 if (mflat != NULL) {
676 cpl_image * flat2 = cpl_image_power_create(
677 hdrl_image_get_image_const(mflat), 2.0) ;
678 cpl_image_divide(var, flat2) ;
679 cpl_image_delete(flat2) ;
680 }
681 /* Keep the error image BPM untouched */
682 cpl_image_fill_rejected(var, 0.0) ;
683 cpl_image_accept_all(var) ;
684
685 for (i=0 ; i<hdrl_imagelist_get_size(list) ; i++) {
686 double scale = cpl_vector_get(dits, i) / dark_dit ;
687 cpl_image * term = cpl_image_multiply_scalar_create(var,
688 sign * scale * scale) ;
690 cpl_image_delete(term) ;
691 }
692 cpl_image_delete(var) ;
693 return 0 ;
694}
695
697
int cr2res_bpm_set_and_correct_image(cpl_image *in, const char *bpm, int chip, int correct)
Set the BPM and optionally apply the correction to an image.
Definition cr2res_bpm.c:199
cpl_image * cr2res_calib_flat_relerr2(const hdrl_image *mflat)
Squared relative error of a master flat, (sigma_F/F)^2.
hdrl_image * cr2res_calib_image(const hdrl_image *in, int chip, int clean_bad, int subtract_nolight_rows, int subtract_interorder_column, int cosmics_corr, const cpl_frame *flat, const cpl_frame *dark, const cpl_frame *bpm, const cpl_frame *detlin, double dit, int ndit, int ndsamples)
The images calibration routine for a given chip.
hdrl_imagelist * cr2res_calib_imagelist(const hdrl_imagelist *in, int chip, int clean_bad, int subtract_nolight_rows, int subtract_interorder_column, int cosmics_corr, const cpl_frame *flat, const cpl_frame *dark, const cpl_frame *bpm, const cpl_frame *detlin, const cpl_vector *dits, const cpl_vector *ndits, const cpl_vector *ndsamples)
The images calibration routine for a given chip on a list.
int cr2res_calib_dark_var(hdrl_imagelist *list, const cpl_frame *master_dark_frame, int chip, const hdrl_image *mflat, const cpl_vector *dits, double sign)
Add or remove the master dark variance of cr2res_calib_image()
int cr2res_calib_subtract_interorder_column(hdrl_image *in, const hdrl_image *flat, cpl_size degree)
Remove background column by column.
void cr2res_calib_add_var(hdrl_image *ima, const cpl_image *var)
Add a variance image to the error of an HDRL image.
int cr2res_add_shotnoise(hdrl_image *in, double dit, int ndit, int ndsamples, int chip)
Add shot- and read-noise to errors in HDRL-image.
void cr2res_calib_flat_var(hdrl_image *ima, const cpl_image *relerr2, double sign)
Add or remove the flat-field variance term of an image.
int cr2res_detlin_correct(hdrl_image *in, const hdrl_imagelist *detlin)
Apply the detector linearity correction.
hdrl_imagelist * cr2res_io_load_DETLIN_COEFFS(const char *filename, int detector)
Load the detlin coefficients.
Definition cr2res_io.c:1064
hdrl_image * cr2res_io_load_MASTER_DARK(const char *filename, int detector)
Load an image from a MASTER_DARK.
Definition cr2res_io.c:1020
hdrl_image * cr2res_io_load_MASTER_FLAT(const char *filename, int detector)
Load an hdrl image from a MASTER_FLAT.
Definition cr2res_io.c:1096
double cr2res_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
double cr2res_vector_get_mad(cpl_vector *invec, double *mad)
Get MAD from a vector.
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_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.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
Definition hdrl_image.c:391
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
Definition hdrl_image.c:157
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
Definition hdrl_image.c:131
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
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
Definition hdrl_image.c:144
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_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition hdrl_image.c:105
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
Definition hdrl_image.c:118
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
Definition hdrl_image.c:311
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition hdrl_image.c:379
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.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_mask * hdrl_lacosmic_edgedetect(const hdrl_image *ima_in, const hdrl_parameter *params)
Detect bad-pixels / cosmic-rays on a single image.
cpl_error_code hdrl_lacosmic_parameter_verify(const hdrl_parameter *param)
Verify basic correctness of the LaCosmic parameters.
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