visir_destripe.c

00001 /* $Id: visir_destripe.c,v 1.10 2009/03/06 08:34:32 llundin Exp $
00002  *
00003  * This file is part of the VISIR Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2009/03/06 08:34:32 $
00024  * $Revision: 1.10 $
00025  * $Name: visir-3_2_2 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                    Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "visir_destripe.h"
00037 #include "visir_utils.h"
00038 #include "irplib_filter.h"
00039 
00040 /*-----------------------------------------------------------------------------
00041                           Private function prototypes
00042  -----------------------------------------------------------------------------*/
00043 
00044 static cpl_error_code visir_destripe_mask(cpl_mask *);
00045 
00046 static int visir_destripe_image_one_float(cpl_image *, double, double,
00047                                           cpl_boolean, cpl_boolean);
00048 static cpl_error_code visir_destripe_find_max_index_float(const cpl_image *,
00049                                                           int, int,
00050                                                           int, int, double *,
00051                                                           int *, int *, int *);
00052 
00053 static int visir_destripe_image_one_double(cpl_image *, double, double,
00054                                            cpl_boolean, cpl_boolean);
00055 static cpl_error_code visir_destripe_find_max_index_double(const cpl_image *,
00056                                                            int, int,
00057                                                            int, int, double *,
00058                                                            int *, int *, int *);
00059 
00060 /*----------------------------------------------------------------------------*/
00064 /*----------------------------------------------------------------------------*/
00065 
00068 /*----------------------------------------------------------------------------*/
00082 /*----------------------------------------------------------------------------*/
00083 static
00084 cpl_error_code visir_destripe_image(cpl_image * self, int niter,
00085                                     double threshold, double thres_detect,
00086                                     cpl_boolean morpho)
00087 {
00088 
00089     cpl_boolean do_horizontal = CPL_TRUE;
00090     cpl_boolean did_find = CPL_FALSE;
00091 
00092     bug_if(self == NULL);
00093     bug_if(niter < 1);
00094 
00095     do {
00096 
00097         const char * sdir = do_horizontal ? "horizontal" : "vertical";
00098         int j = 0; /* Avoid (false) uninit warning */
00099 
00100         switch (cpl_image_get_type(self)) {
00101         case CPL_TYPE_DOUBLE:
00102             for (j = 0; j < niter; j++) {
00103                 if (visir_destripe_image_one_double(self, threshold,
00104                                                     thres_detect, morpho,
00105                                                     do_horizontal)) break;
00106             }
00107             break;
00108         case CPL_TYPE_FLOAT:
00109             for (j = 0; j < niter; j++) {
00110                 if (visir_destripe_image_one_float(self, threshold,
00111                                                    thres_detect, morpho,
00112                                                    do_horizontal)) break;
00113             }
00114             break;
00115         default:
00116             bug_if( 1 );
00117         }
00118 
00119         if (j == 0) {
00120             cpl_msg_info(cpl_func, "No %s stripes found", sdir);
00121         } else if (j < niter) {
00122             did_find = CPL_TRUE;
00123             cpl_msg_info(cpl_func, "No more %s stripes found in iteration %d",
00124                          sdir, j+1);
00125         } else {
00126             did_find = CPL_TRUE;
00127             cpl_msg_info(cpl_func, "Stopped %s destriping after %d iterations",
00128                          sdir, niter);
00129         }
00130 
00131         skip_if(0);
00132 
00133         do_horizontal = !do_horizontal;
00134     } while (!did_find && !do_horizontal);
00135 
00136     end_skip;
00137 
00138     return cpl_error_get_code();
00139 
00140 }
00141 
00145 /*----------------------------------------------------------------------------*/
00153 /*----------------------------------------------------------------------------*/
00154 static cpl_error_code visir_destripe_mask(cpl_mask * self)
00155 {
00156 
00157     const int       niter = 3;
00158     cpl_matrix  *   kernel = cpl_matrix_new(5, 5); /* Initialized to zero */
00159     int             i;
00160 
00161     bug_if(0);
00162 
00163     /* Create the kernel */
00164     cpl_matrix_set(kernel, 0, 1, 1.0);
00165     cpl_matrix_set(kernel, 0, 2, 1.0);
00166     cpl_matrix_set(kernel, 0, 3, 1.0);
00167     cpl_matrix_set(kernel, 1, 1, 1.0);
00168     cpl_matrix_set(kernel, 1, 2, 1.0);
00169     cpl_matrix_set(kernel, 1, 3, 1.0);
00170     cpl_matrix_set(kernel, 2, 1, 1.0);
00171     cpl_matrix_set(kernel, 2, 2, 1.0);
00172     cpl_matrix_set(kernel, 2, 3, 1.0);
00173     cpl_matrix_set(kernel, 3, 1, 1.0);
00174     cpl_matrix_set(kernel, 3, 2, 1.0);
00175     cpl_matrix_set(kernel, 3, 3, 1.0);
00176     cpl_matrix_set(kernel, 4, 1, 1.0);
00177     cpl_matrix_set(kernel, 4, 2, 1.0);
00178     cpl_matrix_set(kernel, 4, 3, 1.0);
00179 
00180     /* self = 1-(closing(1-self)) */
00181     cpl_mask_not(self);
00182     bug_if(cpl_mask_closing(self, kernel));
00183 
00184     cpl_matrix_delete(kernel);
00185 
00186     /* Create the new kernel */
00187     kernel = cpl_matrix_new(3, 5);
00188     cpl_matrix_fill(kernel, 1.0);
00189     cpl_matrix_set(kernel, 0, 0, 0.0);
00190     cpl_matrix_set(kernel, 0, 4, 0.0);
00191     cpl_matrix_set(kernel, 2, 0, 0.0);
00192     cpl_matrix_set(kernel, 2, 4, 0.0);
00193     /* self = 1-(dilation(1-self)) */
00194     for (i=0; i<niter; i++)
00195     {
00196         bug_if(cpl_mask_dilation(self, kernel));
00197     }
00198 
00199     cpl_matrix_delete(kernel);
00200 
00201     /* Create the new kernel */
00202     kernel = cpl_matrix_new(5, 5); /* Initialized to zero */
00203     cpl_matrix_set(kernel, 0, 2, 1.0);
00204     cpl_matrix_set(kernel, 1, 1, 1.0);
00205     cpl_matrix_set(kernel, 1, 2, 1.0);
00206     cpl_matrix_set(kernel, 1, 3, 1.0);
00207     cpl_matrix_set(kernel, 2, 0, 1.0);
00208     cpl_matrix_set(kernel, 2, 1, 1.0);
00209     cpl_matrix_set(kernel, 2, 2, 1.0);
00210     cpl_matrix_set(kernel, 2, 3, 1.0);
00211     cpl_matrix_set(kernel, 2, 4, 1.0);
00212     cpl_matrix_set(kernel, 3, 1, 1.0);
00213     cpl_matrix_set(kernel, 3, 2, 1.0);
00214     cpl_matrix_set(kernel, 3, 3, 1.0);
00215     cpl_matrix_set(kernel, 4, 2, 1.0);
00216     /* self = 1-(dilation(1-self)) */
00217     for (i=0; i<niter; i++)
00218     {
00219         bug_if (cpl_mask_dilation(self, kernel));
00220     }
00221 
00222     bug_if(cpl_mask_not(self));
00223 
00224     end_skip;
00225 
00226     cpl_matrix_delete(kernel);
00227 
00228     return cpl_error_get_code();
00229 }
00230 
00231 
00232 
00233 /* These macros are needed for support of the different pixel types */
00234 
00235 #define CONCAT(a,b) a ## _ ## b
00236 #define CONCAT2X(a,b) CONCAT(a,b)
00237 
00238 #define PIXEL_TYPE double
00239 #define PIXEL_TYPE_CPL CPL_TYPE_DOUBLE
00240 #include "visir_destripe_body.c"
00241 #undef PIXEL_TYPE
00242 #undef PIXEL_TYPE_CPL
00243 
00244 #define PIXEL_TYPE float
00245 #define PIXEL_TYPE_CPL CPL_TYPE_FLOAT
00246 #include "visir_destripe_body.c"
00247 #undef PIXEL_TYPE
00248 #undef PIXEL_TYPE_CPL

Generated on Fri Jul 3 11:15:23 2009 for VISIR Pipeline Reference Manual by  doxygen 1.5.8