30#include "cr2res_bpm.h"
31#include "cr2res_flat.h"
37static cpl_image * cr2res_bpm_from_master_flat(
38 const hdrl_image * master_flat,
41 double bad_per_line_limit) ;
64 const hdrl_image * collapsed,
65 const hdrl_image * model_master,
68 double bad_per_line_limit,
71 hdrl_image * master_flat ;
75 if (collapsed == NULL)
return NULL ;
76 if (model_master == NULL)
return NULL ;
80 model_master)) == NULL) {
81 cpl_msg_error(__func__,
"Failed to divide by the model") ;
86 if ((bpm_loc = cr2res_bpm_from_master_flat(master_flat, low, high,
87 bad_per_line_limit)) == NULL) {
88 cpl_msg_error(__func__,
"Failed to compute the BPM") ;
93 if (bpm != NULL) *bpm = bpm_loc ;
94 else cpl_image_delete(bpm_loc) ;
107static cpl_image * cr2res_bpm_from_master_flat(
108 const hdrl_image * master_flat,
111 double bad_per_line_limit)
113 const cpl_image * ima ;
114 const double * pima ;
115 cpl_mask * mask_flat ;
116 cpl_mask * mask_inter_order ;
117 cpl_binary * pmask_flat ;
118 cpl_binary * pmask_inter_order ;
124 if (master_flat == NULL)
return NULL ;
128 pima = cpl_image_get_data_double_const(ima) ;
129 nx = cpl_image_get_size_x(ima) ;
130 ny = cpl_image_get_size_y(ima) ;
131 mask_flat = cpl_mask_new(nx, ny) ;
132 pmask_flat = cpl_mask_get_data(mask_flat) ;
133 mask_inter_order = cpl_mask_new(nx, ny) ;
134 pmask_inter_order = cpl_mask_get_data(mask_inter_order) ;
137 for (j=0 ; j<ny ; j++) {
138 for (i=0 ; i<nx ; i++) {
139 if (isinf(pima[i+j*nx])) continue ;
140 if (isnan(pima[i+j*nx])) {
141 pmask_inter_order[i+j*nx] = CPL_BINARY_1 ;
142 }
else if (pima[i+j*nx] < low || pima[i+j*nx] > high) {
143 pmask_flat[i+j*nx] = CPL_BINARY_1 ;
154 for (j=0 ; j<ny ; j++) {
156 cur_bp_nb = cpl_mask_count_window(mask_flat, 1, j+1, nx, j+1) ;
158 if (cur_bp_nb > bad_per_line_limit * nx) {
160 for (i=0 ; i<nx ; i++) pmask_flat[i+j*nx] = CPL_BINARY_0 ;
165 bpm = cpl_image_new(nx, ny, CPL_TYPE_INT) ;
169 cpl_mask_delete(mask_flat) ;
170 cpl_mask_delete(mask_inter_order) ;
int cr2res_bpm_add_mask(cpl_image *bpm_ima, cpl_mask *bpm, int bpm_code)
Add a mask to a BPM image with a dedicated code
hdrl_image * cr2res_master_flat(const hdrl_image *collapsed, const hdrl_image *model_master, double low, double high, double bad_per_line_limit, cpl_image **bpm)
Compute the Master Flat.
hdrl_image * hdrl_image_div_image_create(const hdrl_image *self, const hdrl_image *other)
Divide two images and return the resulting image.
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image