00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "visir_destripe.h"
00037 #include "visir_utils.h"
00038
00039
00040
00041
00042
00043 static cpl_error_code visir_destripe_mask(cpl_mask *);
00044
00045 static int visir_destripe_image_one_float(cpl_image *, double, double,
00046 cpl_boolean, cpl_boolean);
00047 static cpl_error_code visir_destripe_find_max_index_float(const cpl_image *,
00048 int, int,
00049 int, int, double *,
00050 int *, int *, int *);
00051
00052 static int visir_destripe_image_one_double(cpl_image *, double, double,
00053 cpl_boolean, cpl_boolean);
00054 static cpl_error_code visir_destripe_find_max_index_double(const cpl_image *,
00055 int, int,
00056 int, int, double *,
00057 int *, int *, int *);
00058
00059
00063
00064
00067
00080
00081 cpl_error_code visir_destripe_image(cpl_image * self, int niter,
00082 double threshold, double thres_detect,
00083 cpl_boolean morpho)
00084 {
00085
00086 cpl_boolean do_horizontal = CPL_TRUE;
00087 cpl_boolean did_find = CPL_FALSE;
00088
00089 bug_if(self == NULL);
00090 bug_if(niter < 1);
00091
00092 do {
00093
00094 const char * sdir = do_horizontal ? "horizontal" : "vertical";
00095 int j = 0;
00096
00097 switch (cpl_image_get_type(self)) {
00098 case CPL_TYPE_DOUBLE:
00099 for (j = 0; j < niter; j++) {
00100 if (visir_destripe_image_one_double(self, threshold,
00101 thres_detect, morpho,
00102 do_horizontal)) break;
00103 }
00104 break;
00105 case CPL_TYPE_FLOAT:
00106 for (j = 0; j < niter; j++) {
00107 if (visir_destripe_image_one_float(self, threshold,
00108 thres_detect, morpho,
00109 do_horizontal)) break;
00110 }
00111 break;
00112 default:
00113 bug_if( 1 );
00114 }
00115
00116 if (j == 0) {
00117 cpl_msg_info(cpl_func, "No %s stripes found", sdir);
00118 } else if (j < niter) {
00119 did_find = CPL_TRUE;
00120 cpl_msg_info(cpl_func, "No more %s stripes found in iteration %d",
00121 sdir, j+1);
00122 } else {
00123 did_find = CPL_TRUE;
00124 cpl_msg_info(cpl_func, "Stopped %s destriping after %d iterations",
00125 sdir, niter);
00126 }
00127
00128 skip_if(0);
00129
00130 do_horizontal = !do_horizontal;
00131 } while (!did_find && !do_horizontal);
00132
00133 end_skip;
00134
00135 return cpl_error_get_code();
00136
00137 }
00138
00142
00150
00151 static cpl_error_code visir_destripe_mask(cpl_mask * self)
00152 {
00153
00154 const int niter = 3;
00155 cpl_mask * kernel = cpl_mask_new(3, 5);
00156 cpl_mask * copy = cpl_mask_new(cpl_mask_get_size_x(self),
00157 cpl_mask_get_size_y(self));
00158 int i;
00159
00160 bug_if(0);
00161
00162
00163 cpl_mask_not(self);
00164
00165
00166 cpl_mask_not(kernel);
00167
00168 bug_if(cpl_mask_filter(self, self, kernel,
00169 CPL_FILTER_CLOSING, CPL_BORDER_ZERO));
00170
00171 cpl_mask_delete(kernel);
00172
00173
00174 kernel = cpl_mask_new(5, 3);
00175 cpl_mask_not(kernel);
00176 cpl_mask_set(kernel, 1, 1, CPL_BINARY_0);
00177 cpl_mask_set(kernel, 5, 1, CPL_BINARY_0);
00178 cpl_mask_set(kernel, 1, 3, CPL_BINARY_0);
00179 cpl_mask_set(kernel, 5, 3, CPL_BINARY_0);
00180
00181 for (i = 0; i < 2*(niter/2); i += 2) {
00182 bug_if(cpl_mask_filter(copy, self, kernel,
00183 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00184 bug_if(cpl_mask_filter(self, copy, kernel,
00185 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00186 }
00187 for (; i < niter; i++) {
00188 bug_if(cpl_mask_filter(copy, self, kernel,
00189 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00190 bug_if(cpl_mask_copy(self, copy, 1, 1));
00191 }
00192
00193 cpl_mask_delete(kernel);
00194
00195
00196 kernel = cpl_mask_new(5, 5);
00197 cpl_mask_set(kernel, 3, 1, CPL_BINARY_1);
00198 cpl_mask_set(kernel, 2, 2, CPL_BINARY_1);
00199 cpl_mask_set(kernel, 3, 2, CPL_BINARY_1);
00200 cpl_mask_set(kernel, 4, 2, CPL_BINARY_1);
00201 cpl_mask_set(kernel, 1, 3, CPL_BINARY_1);
00202 cpl_mask_set(kernel, 2, 3, CPL_BINARY_1);
00203 cpl_mask_set(kernel, 3, 3, CPL_BINARY_1);
00204 cpl_mask_set(kernel, 4, 3, CPL_BINARY_1);
00205 cpl_mask_set(kernel, 5, 3, CPL_BINARY_1);
00206 cpl_mask_set(kernel, 2, 4, CPL_BINARY_1);
00207 cpl_mask_set(kernel, 3, 4, CPL_BINARY_1);
00208 cpl_mask_set(kernel, 4, 4, CPL_BINARY_1);
00209 cpl_mask_set(kernel, 3, 5, CPL_BINARY_1);
00210
00211 for (i = 0; i < 2*(niter/2); i += 2) {
00212 bug_if(cpl_mask_filter(copy, self, kernel,
00213 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00214 bug_if(cpl_mask_filter(self, copy, kernel,
00215 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00216 }
00217 for (; i < niter; i++) {
00218 bug_if(cpl_mask_filter(copy, self, kernel,
00219 CPL_FILTER_DILATION, CPL_BORDER_ZERO));
00220 bug_if(cpl_mask_copy(self, copy, 1, 1));
00221 }
00222
00223 bug_if(cpl_mask_not(self));
00224
00225 end_skip;
00226
00227 cpl_mask_delete(copy);
00228 cpl_mask_delete(kernel);
00229
00230 return cpl_error_get_code();
00231 }
00232
00233
00234
00235
00236
00237 #define CONCAT(a,b) a ## _ ## b
00238 #define CONCAT2X(a,b) CONCAT(a,b)
00239
00240 #define PIXEL_TYPE double
00241 #define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
00242 #include "visir_destripe_body.c"
00243 #undef PIXEL_TYPE
00244 #undef PIXEL_TYPE_CPL
00245
00246 #define PIXEL_TYPE float
00247 #define PIXEL_TYPE_CPL CPL_TYPE_FLOAT
00248 #include "visir_destripe_body.c"
00249 #undef PIXEL_TYPE
00250 #undef PIXEL_TYPE_CPL