lkuan.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 */
00040 #include "image.h"
00041 #include "proto2D.h"
00042 #include "radar.h"
00043 #include <stdlib.h>
00044 #include <fcntl.h>
00045 #include <limits.h> /* pour  USHRT_MAX ... */
00046 
00047 
00048 /* **********************  LECTURE DE PARAMETRES   *************************/
00062 param * kuan_lect(kuan_t *des, param *ptp, char *debq){
00063   char question[500];
00064 
00065   sprintf(question, "%s fenetre d'estimation, nombre de colonnes (impaire)", debq); 
00066   lec_param(question, ptp);
00067   des->dimX = atoi(ptp->rep);
00068   ptp = ptp->next; 
00069 
00070   sprintf(question, "%s fenetre d'estimation, nombre de lignes (impaire)", debq); 
00071   lec_param(question, ptp);
00072   des->dimY = atoi(ptp->rep);
00073   ptp = ptp->next;
00074 
00075   if( des->dimX%2 == 0 || des->dimY%2 == 0 || des->dimX<=0 || des->dimY<=0){
00076       printf("\n>> ERREUR kuan_lect : dimensions incorrectes\n");
00077       exit(1);
00078   }
00079 
00080   sprintf(question, "%s nombre de vues (equivalent) de l'image initiale", debq); 
00081   lec_param(question, ptp);
00082   des->nbvue = (double)atof(ptp->rep);
00083   ptp = ptp->next;
00084 
00085   return(ptp);
00086 }
00087 
00088 
00089 /* **********************  INITIALISATION  *****************************/
00101 /* initialisation (16 bit)*/
00102 int kuanu2_init(kuan_t *des, imau2 im0, imau2 *imres){
00103   /* image resultat */ 
00104   imres->nc = im0.nc;
00105   imres->nr = im0.nr;
00106   sprintf(imres->nom, "%s(kuan%dx%d)", im0.nom, des->dimX, des->dimY);
00107   alloc_imau2(imres);
00108   return(0);  
00109 }
00110 
00111 /* initialisation (float)*/
00112 int kuanfl_init(kuan_t *des, imafl im0, imafl *imres){
00113   /* image resultat */ 
00114   imres->nc = im0.nc;
00115   imres->nr = im0.nr;
00116   sprintf(imres->nom, "%s(kuan%dx%d)", im0.nom, des->dimX, des->dimY);
00117   alloc_imafl(imres);
00118   return(0);  
00119 }
00120 
00121 /* initialisation (double)*/
00122 int kuandb_init(kuan_t *des, imadb im0, imadb *imres){
00123   /* image resultat */ 
00124   imres->nc = im0.nc;
00125   imres->nr = im0.nr;
00126   sprintf(imres->nom, "%s(kuan%dx%d)", im0.nom, des->dimX, des->dimY);
00127   alloc_imadb(imres);
00128   return(0);  
00129 }
00130 
00131 /* *************************  CALCUL  ***************************/
00145 /* calcul (16 bit) */
00146 int kuanu2_calc(kuan_t *des, imau2 im0, imau2 moyint, imafl moycarre, imau2 *imres){
00147   int i, j, nbneg = 0;
00148   double cv2, resdb;
00149   
00150   /* coef de variation (au carre) du speckle dans une image d'intensite n_vues */ 
00151   cv2 = 1. / des->nbvue; 
00152 
00153   for(j=0; j<im0.nr; j++)
00154       for(i=0; i<im0.nc; i++){
00155           resdb = filt_kuan((double)im0.p[j][i], (double)moyint.p[j][i],
00156                             (double)moycarre.p[j][i], cv2, &nbneg) + 0.5;
00157           if( resdb < 0 ){
00158               printf("\n ATT kuanu2_calc : resultat negatif!\n");
00159               imres->p[j][i] = 0;
00160           }
00161           else if (resdb >= USHRT_MAX+1){
00162               printf("\n ATT kuanu2_calc : resultat superieur a %d\n", USHRT_MAX);
00163               imres->p[j][i] = USHRT_MAX;
00164           }
00165           else
00166               imres->p[j][i] = (pixu2)resdb;
00167       }
00168   printf("\n ATT kuanu2_calc : %d points tels que CV_image < CV_speckle\n", nbneg);   
00169   return(0);
00170 }
00171 
00172 /* calcul (float) */
00173 int kuanfl_calc(kuan_t *des, imafl im0, imafl moyint, imafl moycarre, imafl *imres){
00174   int i, j, nbneg = 0;
00175   double cv2, resdb;
00176   
00177   /* coef de variation (au carre) du speckle dans une image d'intensite n_vues */ 
00178   cv2 = 1. / des->nbvue; 
00179 
00180   for(j=0; j<im0.nr; j++)
00181       for(i=0; i<im0.nc; i++)
00182           imres->p[j][i] = (pixfl)filt_kuan((double)im0.p[j][i], (double)moyint.p[j][i],
00183                             (double)moycarre.p[j][i], cv2, &nbneg);
00184   printf("\n ATT kuanfl_calc : %d points tels que CV_image < CV_speckle\n", nbneg);   
00185   return(0);
00186 }
00187 
00188 /* calcul (double) */
00189 int kuandb_calc(kuan_t *des, imadb im0, imadb moyint, imadb moycarre, imadb *imres){
00190   int i, j, nbneg = 0;
00191   double cv2, resdb;
00192   
00193   /* coef de variation (au carre) du speckle dans une image d'intensite n_vues */ 
00194   cv2 = 1. / des->nbvue; 
00195 
00196   for(j=0; j<im0.nr; j++)
00197       for(i=0; i<im0.nc; i++)
00198           imres->p[j][i] = (pixdb)filt_kuan((double)im0.p[j][i], (double)moyint.p[j][i],
00199                             (double)moycarre.p[j][i], cv2, &nbneg);
00200   printf("\n ATT kuandb_calc : %d points tels que CV_image < CV_speckle\n", nbneg);   
00201   return(0);
00202 }
00203 
00204 /* fonction : ******************************* */
00205 double filt_kuan(double int0, double moyint, double moycarre, double cv2, int* nbneg){
00206   double  ci2, cr2;
00207 
00208   ci2 = moycarre/(moyint*moyint) - 1.; /* ci2 = sigma2 / mu^2, sigma2 = moycarre - mu^2 */
00209   cr2 = (ci2 - cv2)/(1. + cv2);
00210   if(cr2 < 0){
00211       /* printf("\n ATT kuanu2_calc : CV_image^2=%f < CV_speckle^2=%f\n", ci2, cv2); */
00212       *nbneg = *nbneg + 1;
00213       return(moyint);
00214   }
00215   else
00216       return(moyint + (int0 - moyint) * cr2 / ci2);
00217 } 
00218 

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