166 cpl_image* sub_ima=NULL;
178 cpl_ensure_code(img != NULL, CPL_ERROR_NULL_INPUT);
180 nx = cpl_image_get_size_x(img);
181 ny = cpl_image_get_size_y(img);
185 CPL_ERROR_ILLEGAL_INPUT);
187 cpl_ensure_code(
tolerance >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
188 cpl_ensure_code(
kappa > 1.0, CPL_ERROR_ILLEGAL_INPUT);
189 cpl_ensure_code(nclip > 0, CPL_ERROR_ILLEGAL_INPUT);
193 cpl_image_delete(sub_ima);
194 mean = cpl_image_get_mean_window(img,
llx,
lly,
urx,
ury);
195 stdev = cpl_image_get_stdev_window(img,
llx,
lly,
urx,
ury);
196 pi=cpl_image_get_data_float_const(img);
197 pm=cpl_mask_get_data(cpl_image_get_bpm((cpl_image*)img));
202 for(k=0;k<nclip;k++) {
203 mean = cpl_image_get_mean_window(img,
llx,
lly,
urx,
ury);
204 stdev = cpl_image_get_stdev_window(img,
llx,
lly,
urx,
ury);
205 thresh=stdev*stdev*kappa2;
210 (pm[pix] != CPL_BINARY_1) &&
211 ((pi[pix]-mean)*(pi[pix]-mean) > thresh ) ) {
212 pm[pix]=CPL_BINARY_1;
216 if((fabs(thresh_p-thresh)) <
tolerance) {
224 if (kstdev != NULL) *kstdev = stdev;
227 return cpl_error_get_code();
230#define CONCAT(a,b) a ## _ ## b
231#define CONCAT2X(a,b) CONCAT(a,b)
233#define CPL_TYPE double
237#define CPL_TYPE float
static cpl_error_code xsh_ksigma_clip_float(const float *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
static cpl_error_code xsh_ksigma_clip_double(const double *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
static cpl_error_code xsh_ksigma_clip_int(const int *pi, cpl_binary *pm, int llx, int lly, int urx, int ury, int nx, double var_sum, int npixs, double kappa, int nclip, double tolerance, double *mean, double *stdev)
cpl_error_code xsh_ksigma_clip(const cpl_image *img, int llx, int lly, int urx, int ury, double kappa, int nclip, double tolerance, double *kmean, double *kstdev)
Apply kappa-sigma clipping on input image.