mfiltmdate_bru.c

00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library 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 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  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 BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 /* ************************** mfiltmdate_bru.c ****************************/
00020 /*                                                                        */
00021 /*       FILTRAGE MULTIDATE - BRUNIQUEL  1/N                              */
00022 /*                                                                        */
00023 /*  Derniere modif : E. TROUVE, 27/03/2000                                */
00024 /* ************************************************************************/
00025 #include <math.h>
00026 #include <limits.h>
00027 #include "image.h"
00028 #include "proto2D.h"
00029 #include "radar.h"
00030 
00053 int main(int argc, char *argv[]){
00054 
00055   /* operateurs */
00056   read_ima_t  rea;
00057   moy2D_t    dmoy;
00058   moycarre2D_t dcarre;
00059   kuan_t  dkuan;
00060   write_ima_t *tabwri;
00061 
00062   /* main */
00063   param par0, *ptp;      /* tete et pointeur pour la chaine de parametres */
00064   char nomtmp[200];
00065   pixu2 *pt0;
00066   int n, N, i, j, k, dimX, dimY, nbp, texture;
00067   pixfl *ptim2, *ptf2D, *ptsom, *ptcarre;  
00068   pixfl tab2[65536];
00069   double tmpdb;  
00070 
00071   /* images */
00072   imau2 im0;     /* image intermediaire u2 pour lecture et ecriture */ 
00073   imafl *tabim2; /* images intensite, puis filtrees (res de moy2D ou kuan), puis resultat */
00074   imafl imf2D;   /* image intermediaire, res de moy2D ou kuan */
00075   imafl imcarre; /* image intermediaire de la moyenne des carres */
00076   imafl imsom;   /* somme des images compensee radiometriquement */
00077 
00078 
00079 /* LECTURE PARAMETRES */
00080   param_debut(argc, argv, &par0); 
00081   ptp = &par0; 
00082 
00083   lec_param("Filtre multidates de Bruniquel simplifie (1/N) : nombre d'images", ptp);
00084   N = atoi(ptp->rep);
00085   ptp = ptp->next;
00086 
00087   lec_param("Filtrage avec compensation des moyennes (0) ou des textures (1)", ptp);
00088   texture = atoi(ptp->rep);
00089   ptp = ptp->next;  
00090  
00091   ptp = kuan_lect(&dkuan, ptp, "Fenetre de filtrage spatial :");
00092 
00093   ptp = read_ima_lect(&rea, ptp, "Premiere image initiale (u2) :");
00094 
00095   if( (tabwri = (write_ima_t *)malloc(N*sizeof(write_ima_t))) == NULL ){
00096       printf ("\n allocation tableau descripteurs impossible\n");  
00097       exit(1);
00098   }
00099   ptp = write_ima_lect(tabwri, ptp, "Premiere image resultat (u2) :");
00100   for(n=1; n<N; n++){
00101       tabwri[n] = tabwri[0];
00102       nom_image_suivante( tabwri[n-1].nom, tabwri[n].nom);
00103   }
00104 
00105   param_fin(argc, argv, &par0);
00106 
00107 /* INITIALISATION  */
00108   if( (tabim2 = (imafl *)malloc(N*sizeof(imafl))) == NULL ){
00109       printf ("\n allocation tableau image impossible\n");  
00110       exit(1);
00111   }
00112 
00113   /* lecture/ecriture des images */
00114   for(j=0; j<65536; j++)
00115       tab2[j] = (pixfl)(j*j);
00116   for(n=0; n<N; n++){
00117       if(n>0){
00118           nom_image_suivante(rea.nom, nomtmp);
00119           strcpy(rea.nom, nomtmp);
00120       }
00121       read_imau2_init(&rea, &im0);
00122       pt0 = im0.p[0];
00123       if(n==0)
00124           nbp = im0.nc*im0.nr;
00125       else{ 
00126           if (im0.nc*im0.nr != nbp ){
00127               printf ("\n dimension image %s incoherente avec les precedentes\n", rea.nom);
00128               exit(1);
00129           }
00130       }
00131       /* passage en intensite */
00132       tabim2[n].nr = im0.nr; 
00133       tabim2[n].nc = im0.nc;
00134       alloc_imafl(tabim2+n);
00135       ptim2 = tabim2[n].p[0];
00136       for(k=0; k<nbp; k++)
00137               ptim2[k] = tab2[pt0[k]];
00138       if(n<N-1)
00139          free_imau2(&im0); 
00140       write_ima_init(tabwri+n);
00141   }
00142 
00143   /* init du filtrage pour estimer la radiometrie moy2D ou kuan */
00144   dmoy.dimX = dkuan.dimX;
00145   dmoy.dimY = dkuan.dimY;
00146   moy2Dfl_init(&dmoy, tabim2[0], &imf2D);
00147   ptf2D = imf2D.p[0];
00148   if(texture){
00149       dcarre.dimX = dkuan.dimX;
00150       dcarre.dimY = dkuan.dimY;
00151       moycarre2Dfl_init(&dcarre, tabim2[0], &imcarre);
00152       ptcarre = imcarre.p[0];
00153       /* pas besoin d'init du kuan, on utilise l'image imf2D pour le resultat */
00154   }
00155 
00156   /* init de l'image somme */
00157   imsom.nc = imf2D.nc;  
00158   imsom.nr = imf2D.nr; 
00159   alloc_imafl(&imsom);
00160   ptsom = imsom.p[0];
00161   for(k=0; k<nbp; k++)
00162       ptsom[k] = 0.;  
00163 
00164 /* CALCUL */
00165   for(n=0; n<N; n++){
00166       ptim2 = tabim2[n].p[0];
00167       /* filtrage spatial */
00168       moy2Dfl_calc(&dmoy, tabim2[n], &imf2D);
00169       if(texture){
00170           moycarre2Dfl_calc(&dcarre, tabim2[n], &imcarre);
00171           kuanfl_calc(&dkuan, tabim2[n], imf2D, imcarre, &imf2D);
00172       }
00173       for(k=0; k<nbp; k++){
00174           ptsom[k] += ptim2[k]/ptf2D[k];
00175           ptim2[k] = ptf2D[k];
00176       }
00177   }  
00178   for(k=0; k<nbp; k++)
00179       ptsom[k] = ptsom[k]/N;
00180 
00181   for(n=0; n<N; n++){ 
00182       ptim2 = tabim2[n].p[0];
00183       for(k=0; k<nbp; k++){  
00184           /* resultat remis en amplitude */
00185           tmpdb = sqrt((double)(ptim2[k]*ptsom[k])) + 0.5;
00186           if( tmpdb < 65536. )
00187               pt0[k] = (pixu2)tmpdb;
00188           else
00189               pt0[k] = 65535;     
00190       }
00191       /* FREMETURE */
00192       write_imau2_ferm(tabwri+n, im0);
00193   }
00194 }
00195 
00196 
00197 

Generated on Tue Apr 22 13:31:04 2008 for ima2D by  doxygen 1.5.3