lidctexp.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 */
00043 #include "image.h"
00044 #include "proto2D.h"
00045 #include "radar.h"
00046 #include <stdlib.h>
00047 #include <fcntl.h>
00048 #include <math.h>
00049 #include <limits.h> /* pour  USHRT_MAX ... */
00050 
00051 /* #include "radar_comp.h" */
00052 
00053 
00054 
00055 /* **********************  LECTURE DE PARAMETRES   *************************/
00068 param * idctexp_lect(idctexp_t *des, param *ptp, char *debq){
00069   char question[500];
00070 
00071   sprintf(question, "%s nombre d'images", debq); 
00072   lec_param(question, ptp);
00073   des->N = atoi(ptp->rep);
00074   ptp = ptp->next; 
00075 
00076   sprintf(question, "%s biais a corriger (division apres l'exponentielle)", debq); 
00077   lec_param(question, ptp);
00078   des->B = (float)atof(ptp->rep);
00079   ptp = ptp->next; 
00080 
00081   return(ptp);
00082 }
00083 
00084 /* **********************  INITIALISATION  *****************************/
00098 /* initialisation (8 bit)*/
00099 
00100 /* initialisation (16 bit)*/
00101 int idctexp_u2_init(idctexp_t *des, imafl *pt_imdct, imau2 *pt_imres){
00102   int n, k, N;
00103   float c0, ck;
00104   double tmpdb;
00105 
00106   N = des->N;
00107   /* allocation images resultat */
00108   for(n=0; n<N; n++){
00109       if (pt_imres[n].p == NULL){
00110           pt_imres[n].nc = pt_imdct[0].nc;
00111           pt_imres[n].nr = pt_imdct[0].nr;
00112           sprintf(pt_imres[n].nom, "%s_idctexp_%d", pt_imdct[0].nom, n);
00113           alloc_imau2(pt_imres+n);
00114       }
00115   }
00116 
00117   /* allocation vecteur de donnees */
00118   if(  (des->v0 = (float *)malloc(N*sizeof(float))) == NULL ){
00119       printf ("\n ERREUR idctexp_u2_init : allocation vecteur impossible\n");  
00120       exit(1); 
00121   }  
00122 
00123   /* allocation matrice coef de calcul de DCT */ 
00124   if(  (des->matidct = (float **)malloc(N*sizeof(float *))) == NULL ){
00125       printf ("\n ERREUR idctexp_u2_init : allocation matrice impossible\n");  
00126       exit(1); 
00127   }  
00128   if( (des->matidct[0] = (float *)malloc(N*N*sizeof(float))) == NULL){
00129       printf ("\n ERREUR idctexp_u2_init : allocation image impossible\n");  
00130       exit(1); 
00131   }
00132   for(n=1; n<N; n++)
00133         des->matidct[n] =  des->matidct[0] + n*N;
00134 
00135   /* calcul matrice coef de calcul de IDCT */ 
00136   c0 = (float)sqrt(1./(double)N);  
00137   ck = (float)sqrt(2./(double)N);
00138   for(n=0; n<N; n++){
00139       des->matidct[n][0] = c0;
00140       for(k=1; k<N; k++)
00141          des->matidct[n][k] = ck*(float)cos(M_PI*(double)((2*n+1)*k)/(double)(2*N));
00142   }
00143 
00144   return(0);  
00145 }
00146 
00147 /* initialisation (float)*/
00148 
00149 /* initialisation (double)*/
00150 
00151 
00152 /* *************************  CALCUL  ***************************/
00163 /* calcul (8 bit) */
00164 
00165 /* calcul (16 bit) */
00166 int idctexp_u2_calc(idctexp_t *des, imafl *pt_imdct, imau2 *pt_imres){
00167   int i, j, dimX, dimY, n, k, N;
00168   float som, res;
00169   
00170   N = des->N;
00171   dimX = pt_imdct->nc; 
00172   dimY = pt_imdct->nr; 
00173   for(j=0; j<dimY; j++)
00174       for(i=0; i<dimX; i++){
00175           for( k=0; k<N; k++)
00176               des->v0[k] = pt_imdct[k].p[j][i];
00177           for( n=0; n<N; n++){
00178               som = des->matidct[n][0] * des->v0[0];
00179               for( k=1; k<N; k++)
00180                   som += des->matidct[n][k] * des->v0[k];
00181               res = (float)exp((double)som) / des->B + 0.5;
00182               if(res >= USHRT_MAX +1)
00183                   pt_imres[n].p[j][i] = USHRT_MAX;
00184               else if (res <=0.)
00185                   pt_imres[n].p[j][i] = 0;
00186               else
00187                   pt_imres[n].p[j][i] = (pixu2)res;
00188           }
00189       }
00190   return(0);
00191 }
00192 
00193 /* calcul (float) */
00194 
00195 /* calcul (double) */
00196 
00197 /* fonction : ******************************* */
00198 

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