llogdct.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 */
00041 #include "image.h"
00042 #include "proto2D.h"
00043 #include "radar.h"
00044 #include <stdlib.h>
00045 #include <fcntl.h>
00046 #include <math.h>
00047 #include <limits.h> /* pour  USHRT_MAX ... */
00048 
00049 /* #include "radar_comp.h" */
00050 
00051 
00052 
00053 /* **********************  LECTURE DE PARAMETRES   *************************/
00066 param * logdct_lect(logdct_t *des, param *ptp, char *debq){
00067   char question[500];
00068 
00069   sprintf(question, "%s nombre d'images", debq); 
00070   lec_param(question, ptp);
00071   des->N = atoi(ptp->rep);
00072   ptp = ptp->next; 
00073 
00074   return(ptp);
00075 }
00076 
00077 /* **********************  INITIALISATION  *****************************/
00089 /* initialisation (8 bit)*/
00090 
00091 /* initialisation (16 bit)*/
00092 int logdct_u2_init(logdct_t *des, imau2 *pt_im0, imafl *pt_imres){
00093   int n, k, N;
00094   float ck;
00095   double tmpdb;
00096 
00097   N = des->N;
00098   /* allocation images resultat */
00099   for(n=0; n<N; n++){
00100       pt_imres[n].nc = pt_im0[0].nc;
00101       pt_imres[n].nr = pt_im0[0].nr;
00102       sprintf(pt_imres[n].nom, "%s_logdct_%d", pt_im0[0].nom, n);
00103       alloc_imafl(pt_imres+n);
00104   }
00105 
00106   /* allocation vecteur de donnees */
00107   if(  (des->v0 = (float *)malloc(N*sizeof(float))) == NULL ){
00108       printf ("\n ERREUR logdct_u2_init : allocation vecteur impossible\n");  
00109       exit(1); 
00110   }  
00111 
00112   /* allocation matrice coef de calcul de DCT */ 
00113   if(  (des->matdct = (float **)malloc(N*sizeof(float *))) == NULL ){
00114       printf ("\n ERREUR logdct_u2_init : allocation matrice impossible\n");  
00115       exit(1); 
00116   }  
00117   if( (des->matdct[0] = (float *)malloc(N*N*sizeof(float))) == NULL){
00118       printf ("\n ERREUR logdct_u2_init : allocation image impossible\n");  
00119       exit(1); 
00120   }
00121   for(k=1; k<N; k++)
00122         des->matdct[k] =  des->matdct[0] + k*N;
00123 
00124   /* calcul matrice coef de calcul de DCT */ 
00125   ck = (float)sqrt(1./(double)N);  /* k=0 */
00126   for(n=0; n<N; n++){
00127       des->matdct[0][n] = ck;
00128   }
00129   ck = (float)sqrt(2./(double)N);
00130   for(k=1; k<N; k++)
00131       for(n=0; n<N; n++)
00132           des->matdct[k][n] = ck*(float)cos(M_PI*(double)((2*n+1)*k)/(double)(2*N));
00133   
00134   /* tabulation du log*/
00135   des->tablog[0] = 0. ;
00136   for(n=1; n<65536; n++)
00137       des->tablog[n] = (float)log((double)n);
00138 
00139   return(0);  
00140 }
00141 
00142 /* initialisation (float)*/
00143 
00144 /* initialisation (double)*/
00145 
00146 
00147 /* *************************  CALCUL  ***************************/
00158 /* calcul (8 bit) */
00159 
00160 /* calcul (16 bit) */
00161 int logdct_u2_calc(logdct_t *des, imau2 *pt_im0, imafl *pt_imres){
00162   int i, j, dimX, dimY, n, k, N;
00163   float som;
00164   
00165   N = des->N;
00166   dimX = pt_im0->nc; 
00167   dimY = pt_im0->nr; 
00168   for(j=0; j<dimY; j++)
00169       for(i=0; i<dimX; i++){
00170           for( n=0; n<N; n++)
00171               des->v0[n] = des->tablog[pt_im0[n].p[j][i]];
00172           for( k=0; k<N; k++){
00173               som = des->matdct[k][0] * des->v0[0];
00174               for( n=1; n<N; n++)
00175                   som += des->matdct[k][n] * des->v0[n];
00176               pt_imres[k].p[j][i] = som;
00177           }
00178       }
00179   return(0);
00180 }
00181 
00182 /* calcul (float) */
00183 
00184 /* calcul (double) */
00185 
00186 /* fonction : ******************************* */
00187 
00188 

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