45 #include "irplib_ksigma_clip.h"
47 #include "irplib_hist.h"
48 #include "irplib_utils.h"
67 irplib_ksigma_clip_double(
const double * pi,
82 irplib_ksigma_clip_float(
const float * pi,
97 irplib_ksigma_clip_int(
const int * pi,
166 irplib_ksigma_clip(
const cpl_image * img,
177 cpl_errorstate inistate = cpl_errorstate_get();
182 double mean, stdev, var_sum;
185 cpl_ensure_code(img != NULL, CPL_ERROR_NULL_INPUT);
187 nx = cpl_image_get_size_x(img);
188 ny = cpl_image_get_size_y(img);
190 cpl_ensure_code(llx > 0 && urx > llx && urx <= nx &&
191 lly > 0 && ury > lly && ury <= ny,
192 CPL_ERROR_ILLEGAL_INPUT);
194 cpl_ensure_code(tolerance >= 0.0, CPL_ERROR_ILLEGAL_INPUT);
195 cpl_ensure_code(kappa > 1.0, CPL_ERROR_ILLEGAL_INPUT);
196 cpl_ensure_code(nclip > 0, CPL_ERROR_ILLEGAL_INPUT);
198 stats = cpl_stats_new_from_image_window(img,
199 CPL_STATS_MEAN | CPL_STATS_STDEV,
202 npixs = cpl_stats_get_npix(stats);
203 mean = cpl_stats_get_mean(stats);
204 stdev = cpl_stats_get_stdev(stats);
205 var_sum = stdev * stdev * (npixs - 1);
207 cpl_stats_delete(stats);
210 cpl_ensure_code(cpl_errorstate_is_equal(inistate), cpl_error_get_code());
212 switch (cpl_image_get_type(img)) {
213 case CPL_TYPE_DOUBLE:
214 skip_if(irplib_ksigma_clip_double(cpl_image_get_data_double_const(img),
215 llx, lly, urx, ury, nx, var_sum,
216 npixs, kappa, nclip, tolerance,
220 skip_if(irplib_ksigma_clip_float(cpl_image_get_data_float_const(img),
221 llx, lly, urx, ury, nx, var_sum,
222 npixs, kappa, nclip, tolerance,
226 skip_if(irplib_ksigma_clip_int(cpl_image_get_data_int_const(img),
227 llx, lly, urx, ury, nx, var_sum,
228 npixs, kappa, nclip, tolerance,
237 if (kstdev != NULL) *kstdev = stdev;
241 return cpl_error_get_code();
244 #define CONCAT(a,b) a ## _ ## b
245 #define CONCAT2X(a,b) CONCAT(a,b)
247 #define CPL_TYPE double
248 #include "irplib_ksigma_clip_body.h"
251 #define CPL_TYPE float
252 #include "irplib_ksigma_clip_body.h"
256 #include "irplib_ksigma_clip_body.h"