45#include "irplib_ksigma_clip.h"
47#include "irplib_hist.h"
48#include "irplib_utils.h"
66static cpl_error_code irplib_ksigma_clip_double(
const double *pi,
80static cpl_error_code irplib_ksigma_clip_float(
const float *pi,
94static cpl_error_code irplib_ksigma_clip_int(
const int *pi,
163irplib_ksigma_clip(
const cpl_image *img,
174 cpl_errorstate inistate = cpl_errorstate_get();
179 double mean, stdev, var_sum;
182 cpl_ensure_code(img != NULL, CPL_ERROR_NULL_INPUT);
184 nx = cpl_image_get_size_x(img);
185 ny = cpl_image_get_size_y(img);
187 cpl_ensure_code(llx > 0 && urx > llx && urx <= nx && lly > 0 && ury > lly &&
189 CPL_ERROR_ILLEGAL_INPUT);
191 cpl_ensure_code(tolerance >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
192 cpl_ensure_code(kappa > 1.0, CPL_ERROR_ILLEGAL_INPUT);
193 cpl_ensure_code(nclip > 0, CPL_ERROR_ILLEGAL_INPUT);
196 cpl_stats_new_from_image_window(img, CPL_STATS_MEAN | CPL_STATS_STDEV,
199 npixs = cpl_stats_get_npix(stats);
200 mean = cpl_stats_get_mean(stats);
201 stdev = cpl_stats_get_stdev(stats);
202 var_sum = stdev * stdev * (npixs - 1);
204 cpl_stats_delete(stats);
207 cpl_ensure_code(cpl_errorstate_is_equal(inistate), cpl_error_get_code());
209 switch (cpl_image_get_type(img)) {
210 case CPL_TYPE_DOUBLE:
211 skip_if(irplib_ksigma_clip_double(
212 cpl_image_get_data_double_const(img), llx, lly, urx, ury, nx,
213 var_sum, npixs, kappa, nclip, tolerance, &mean, &stdev));
216 skip_if(irplib_ksigma_clip_float(
217 cpl_image_get_data_float_const(img), llx, lly, urx, ury, nx,
218 var_sum, npixs, kappa, nclip, tolerance, &mean, &stdev));
221 skip_if(irplib_ksigma_clip_int(cpl_image_get_data_int_const(img),
222 llx, lly, urx, ury, nx, var_sum,
223 npixs, kappa, nclip, tolerance,
237 return cpl_error_get_code();
240#define CONCAT(a, b) a##_##b
241#define CONCAT2X(a, b) CONCAT(a, b)
243#define CPL_TYPE double
244#include "irplib_ksigma_clip_body.h"
247#define CPL_TYPE float
248#include "irplib_ksigma_clip_body.h"
252#include "irplib_ksigma_clip_body.h"