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
00081
00082 static
00083 cpl_error_code visir_destripe_image(cpl_image * self, int niter,
00084 double threshold, double thres_detect,
00085 cpl_boolean morpho)
00086 {
00087
00088 cpl_boolean do_horizontal = CPL_TRUE;
00089 cpl_boolean did_find = CPL_FALSE;
00090
00091 bug_if(self == NULL);
00092 bug_if(niter < 1);
00093
00094 do {
00095
00096 const char * sdir = do_horizontal ? "horizontal" : "vertical";
00097 int j = 0;
00098
00099 switch (cpl_image_get_type(self)) {
00100 case CPL_TYPE_DOUBLE:
00101 for (j = 0; j < niter; j++) {
00102 if (visir_destripe_image_one_double(self, threshold,
00103 thres_detect, morpho,
00104 do_horizontal)) break;
00105 }
00106 break;
00107 case CPL_TYPE_FLOAT:
00108 for (j = 0; j < niter; j++) {
00109 if (visir_destripe_image_one_float(self, threshold,
00110 thres_detect, morpho,
00111 do_horizontal)) break;
00112 }
00113 break;
00114 default:
00115 bug_if( 1 );
00116 }
00117
00118 if (j == 0) {
00119 cpl_msg_info(cpl_func, "No %s stripes found", sdir);
00120 } else if (j < niter) {
00121 did_find = CPL_TRUE;
00122 cpl_msg_info(cpl_func, "No more %s stripes found in iteration %d",
00123 sdir, j+1);
00124 } else {
00125 did_find = CPL_TRUE;
00126 cpl_msg_info(cpl_func, "Stopped %s destriping after %d iterations",
00127 sdir, niter);
00128 }
00129
00130 skip_if(0);
00131
00132 do_horizontal = !do_horizontal;
00133 } while (!did_find && !do_horizontal);
00134
00135 end_skip;
00136
00137 return cpl_error_get_code();
00138
00139 }
00140
00144
00152
00153 static cpl_error_code visir_destripe_mask(cpl_mask * self)
00154 {
00155
00156 const int niter = 3;
00157 cpl_matrix * kernel = cpl_matrix_new(5, 5);
00158 int i;
00159
00160 bug_if(0);
00161
00162
00163 cpl_matrix_set(kernel, 0, 1, 1.0);
00164 cpl_matrix_set(kernel, 0, 2, 1.0);
00165 cpl_matrix_set(kernel, 0, 3, 1.0);
00166 cpl_matrix_set(kernel, 1, 1, 1.0);
00167 cpl_matrix_set(kernel, 1, 2, 1.0);
00168 cpl_matrix_set(kernel, 1, 3, 1.0);
00169 cpl_matrix_set(kernel, 2, 1, 1.0);
00170 cpl_matrix_set(kernel, 2, 2, 1.0);
00171 cpl_matrix_set(kernel, 2, 3, 1.0);
00172 cpl_matrix_set(kernel, 3, 1, 1.0);
00173 cpl_matrix_set(kernel, 3, 2, 1.0);
00174 cpl_matrix_set(kernel, 3, 3, 1.0);
00175 cpl_matrix_set(kernel, 4, 1, 1.0);
00176 cpl_matrix_set(kernel, 4, 2, 1.0);
00177 cpl_matrix_set(kernel, 4, 3, 1.0);
00178
00179
00180 cpl_mask_not(self);
00181 bug_if(cpl_mask_closing(self, kernel));
00182
00183 cpl_matrix_delete(kernel);
00184
00185
00186 kernel = cpl_matrix_new(3, 5);
00187 cpl_matrix_fill(kernel, 1.0);
00188 cpl_matrix_set(kernel, 0, 0, 0.0);
00189 cpl_matrix_set(kernel, 0, 4, 0.0);
00190 cpl_matrix_set(kernel, 2, 0, 0.0);
00191 cpl_matrix_set(kernel, 2, 4, 0.0);
00192
00193 for (i=0; i<niter; i++)
00194 {
00195 bug_if(cpl_mask_dilation(self, kernel));
00196 }
00197
00198 cpl_matrix_delete(kernel);
00199
00200
00201 kernel = cpl_matrix_new(5, 5);
00202 cpl_matrix_set(kernel, 0, 2, 1.0);
00203 cpl_matrix_set(kernel, 1, 1, 1.0);
00204 cpl_matrix_set(kernel, 1, 2, 1.0);
00205 cpl_matrix_set(kernel, 1, 3, 1.0);
00206 cpl_matrix_set(kernel, 2, 0, 1.0);
00207 cpl_matrix_set(kernel, 2, 1, 1.0);
00208 cpl_matrix_set(kernel, 2, 2, 1.0);
00209 cpl_matrix_set(kernel, 2, 3, 1.0);
00210 cpl_matrix_set(kernel, 2, 4, 1.0);
00211 cpl_matrix_set(kernel, 3, 1, 1.0);
00212 cpl_matrix_set(kernel, 3, 2, 1.0);
00213 cpl_matrix_set(kernel, 3, 3, 1.0);
00214 cpl_matrix_set(kernel, 4, 2, 1.0);
00215
00216 for (i=0; i<niter; i++)
00217 {
00218 bug_if (cpl_mask_dilation(self, kernel));
00219 }
00220
00221 bug_if(cpl_mask_not(self));
00222
00223 end_skip;
00224
00225 cpl_matrix_delete(kernel);
00226
00227 return cpl_error_get_code();
00228 }
00229
00230
00231
00232
00233
00234 #define CONCAT(a,b) a ## _ ## b
00235 #define CONCAT2X(a,b) CONCAT(a,b)
00236
00237 #define PIXEL_TYPE double
00238 #define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
00239 #include "visir_destripe_body.c"
00240 #undef PIXEL_TYPE
00241 #undef PIXEL_TYPE_CPL
00242
00243 #define PIXEL_TYPE float
00244 #define PIXEL_TYPE_CPL CPL_TYPE_FLOAT
00245 #include "visir_destripe_body.c"
00246 #undef PIXEL_TYPE
00247 #undef PIXEL_TYPE_CPL