36#include "visir_destripe.h"
37#include "visir_utils.h"
43static cpl_error_code visir_destripe_mask(cpl_mask *);
45static int visir_destripe_image_one_float(cpl_image *,
double,
double,
46 cpl_boolean, cpl_boolean);
47static cpl_error_code visir_destripe_find_max_index_float(
const cpl_image *,
52static int visir_destripe_image_one_double(cpl_image *,
double,
double,
53 cpl_boolean, cpl_boolean);
54static cpl_error_code visir_destripe_find_max_index_double(
const cpl_image *,
82 double threshold,
double thres_detect,
86 cpl_boolean do_horizontal = CPL_TRUE;
87 cpl_boolean did_find = CPL_FALSE;
94 const char * sdir = do_horizontal ?
"horizontal" :
"vertical";
97 switch (cpl_image_get_type(self)) {
99 for (j = 0; j < niter; j++) {
100 if (visir_destripe_image_one_double(self, threshold,
101 thres_detect, morpho,
102 do_horizontal))
break;
106 for (j = 0; j < niter; j++) {
107 if (visir_destripe_image_one_float(self, threshold,
108 thres_detect, morpho,
109 do_horizontal))
break;
117 cpl_msg_info(cpl_func,
"No %s stripes found", sdir);
118 }
else if (j < niter) {
120 cpl_msg_info(cpl_func,
"No more %s stripes found in iteration %d",
124 cpl_msg_info(cpl_func,
"Stopped %s destriping after %d iterations",
130 do_horizontal = !do_horizontal;
131 }
while (!did_find && !do_horizontal);
135 return cpl_error_get_code();
151static cpl_error_code visir_destripe_mask(cpl_mask * self)
155 cpl_mask * kernel = cpl_mask_new(3, 5);
156 cpl_mask * copy = cpl_mask_new(cpl_mask_get_size_x(self),
157 cpl_mask_get_size_y(self));
166 cpl_mask_not(kernel);
168 bug_if(cpl_mask_filter(self, self, kernel,
169 CPL_FILTER_CLOSING, CPL_BORDER_ZERO));
171 cpl_mask_delete(kernel);
174 kernel = cpl_mask_new(5, 3);
175 cpl_mask_not(kernel);
176 cpl_mask_set(kernel, 1, 1, CPL_BINARY_0);
177 cpl_mask_set(kernel, 5, 1, CPL_BINARY_0);
178 cpl_mask_set(kernel, 1, 3, CPL_BINARY_0);
179 cpl_mask_set(kernel, 5, 3, CPL_BINARY_0);
181 for (i = 0; i < 2*(niter/2); i += 2) {
182 bug_if(cpl_mask_filter(copy, self, kernel,
183 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
184 bug_if(cpl_mask_filter(self, copy, kernel,
185 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
187 for (; i < niter; i++) {
188 bug_if(cpl_mask_filter(copy, self, kernel,
189 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
190 bug_if(cpl_mask_copy(self, copy, 1, 1));
193 cpl_mask_delete(kernel);
196 kernel = cpl_mask_new(5, 5);
197 cpl_mask_set(kernel, 3, 1, CPL_BINARY_1);
198 cpl_mask_set(kernel, 2, 2, CPL_BINARY_1);
199 cpl_mask_set(kernel, 3, 2, CPL_BINARY_1);
200 cpl_mask_set(kernel, 4, 2, CPL_BINARY_1);
201 cpl_mask_set(kernel, 1, 3, CPL_BINARY_1);
202 cpl_mask_set(kernel, 2, 3, CPL_BINARY_1);
203 cpl_mask_set(kernel, 3, 3, CPL_BINARY_1);
204 cpl_mask_set(kernel, 4, 3, CPL_BINARY_1);
205 cpl_mask_set(kernel, 5, 3, CPL_BINARY_1);
206 cpl_mask_set(kernel, 2, 4, CPL_BINARY_1);
207 cpl_mask_set(kernel, 3, 4, CPL_BINARY_1);
208 cpl_mask_set(kernel, 4, 4, CPL_BINARY_1);
209 cpl_mask_set(kernel, 3, 5, CPL_BINARY_1);
211 for (i = 0; i < 2*(niter/2); i += 2) {
212 bug_if(cpl_mask_filter(copy, self, kernel,
213 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
214 bug_if(cpl_mask_filter(self, copy, kernel,
215 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
217 for (; i < niter; i++) {
218 bug_if(cpl_mask_filter(copy, self, kernel,
219 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
220 bug_if(cpl_mask_copy(self, copy, 1, 1));
223 bug_if(cpl_mask_not(self));
227 cpl_mask_delete(copy);
228 cpl_mask_delete(kernel);
230 return cpl_error_get_code();
237#define CONCAT(a,b) a ## _ ## b
238#define CONCAT2X(a,b) CONCAT(a,b)
240#define PIXEL_TYPE double
241#define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
242#include "visir_destripe_body.c"
246#define PIXEL_TYPE float
247#define PIXEL_TYPE_CPL CPL_TYPE_FLOAT
248#include "visir_destripe_body.c"
cpl_error_code visir_destripe_image(cpl_image *self, int niter, double threshold, double thres_detect, cpl_boolean morpho)
Remove the stripes frome an image using iterations.