mmoycarre2D.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 */
00032 #include "image.h"
00033 #include "proto2D.h"
00034 #include "math.h"
00035 #include <limits.h> /* pour  USHRT_MAX ... */
00036 
00037 int main(int argc, char *argv[]){
00038   /* images */ 
00039   imau1 im0u1;          
00040   imau2 im0u2;          
00041   imafl im0fl, moycarre;    
00042 
00043   /* operateurs */
00044   read_ima_t  rea;
00045   moycarre2D_t moy;
00046   write_ima_t wri;
00047 
00048  /* main : variables et parametres propres au main*/
00049   param par0, *ptp;      /* tete et pointeur pour la chaine de parametres */
00050   int t0;
00051   register int n;
00052   register double tmpdb;
00053   pixu1 *ptu1;
00054   pixu2 *ptu2;
00055   pixfl *ptfl, *ptmoy;
00056  
00057 
00058 /* LECTURE PARAMETRES */
00059   param_debut(argc, argv, &par0); 
00060   ptp = &par0;
00061   ptp = read_ima_lect(&rea, ptp, ">> image initiale (u1|u2|fl) :");
00062   ptp = write_ima_lect(&wri, ptp, ">> image resultat (meme type) :");
00063   ptp = moycarre2D_lect(&moy, ptp, ">> moyenne des carres :");
00064   param_fin(argc, argv, &par0);
00065 
00066 /* INITIALISATION  */
00067  if( !strcmp(rea.ext, "ima") || !strcmp(rea.ext, "ras")){
00068       t0 = 1;
00069       read_imau1_init(&rea, &im0u1);  
00070       moycarre2Du1_init(&moy, im0u1, &moycarre);
00071   }
00072   else if(!strcmp(rea.ext, "imw")){
00073       t0 = 2;
00074       read_imau2_init(&rea, &im0u2);
00075       moycarre2Du2_init(&moy, im0u2, &moycarre);
00076   }
00077   else if(!strcmp(rea.ext, "imf")){
00078       t0 = 4;
00079       read_imafl_init(&rea, &im0fl);
00080       moycarre2Dfl_init(&moy, im0fl, &moycarre);
00081   }
00082   else{
00083       printf("\n>>moycarre2D ERREUR : extension %s inconnue\n", rea.ext);
00084       exit(0);
00085   }
00086   write_ima_init(&wri);
00087  
00088 /* CALCUL : moyenne des carres (operateur) et racine pour revenir au format initial*/
00089   ptmoy = moycarre.p[0];
00090   switch(t0){
00091   case 1 :      
00092       moycarre2Du1_calc(&moy, im0u1, &moycarre);
00093       ptu1 = im0u1.p[0];
00094       for(n=moycarre.nr*moycarre.nc-1; n>=0; n--){
00095           tmpdb = sqrt((double)ptmoy[n]) + 0.5;
00096           ptu1[n] = (tmpdb < 256.) ? (pixu1)tmpdb : 255; 
00097       } 
00098       break;
00099   case 2 :
00100       moycarre2Du2_calc(&moy, im0u2, &moycarre);
00101       ptu2 = im0u2.p[0];
00102       for(n=moycarre.nr*moycarre.nc-1; n>=0; n--){
00103           tmpdb = sqrt((double)ptmoy[n]) + 0.5;
00104           ptu2[n] = (tmpdb < USHRT_MAX+1.) ? (pixu2)tmpdb : USHRT_MAX; 
00105       } 
00106       break;
00107   case 4 :
00108       moycarre2Dfl_calc(&moy, im0fl, &moycarre);
00109       ptfl = im0fl.p[0];
00110       for(n=moycarre.nr*moycarre.nc-1; n>=0; n--)
00111           ptfl[n] = (float)sqrt((double)ptmoy[n]);
00112       break;
00113   }
00114   
00115 /* FREMETURE */
00116   switch(t0){
00117   case 1 :      
00118       write_imau1_ferm(&wri, im0u1);
00119       break;
00120   case 2 :      
00121       write_imau2_ferm(&wri, im0u2);
00122       break;
00123   case 4 :      
00124       write_imafl_ferm(&wri, im0fl);
00125       break;
00126   }
00127 }
00128 
00129 
00130 

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