lgradient_organisation.c

Go to the documentation of this file.
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 */
00031 #include <stdio.h>
00032 #include "gradient_organisation.h"
00033 #include <math.h>
00034 
00035 #define MAX(x,y) (((x)>(y))? (x):(y))
00036 #define PI_DOUBLE 6.2832
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 /******************************************************************/
00051 float CalculAlpha(int top, int nb, float eps)
00052 {
00053     float alpha,alpha1,alpha2,val,c;
00054     int i;
00055 
00056 alpha1=0; alpha2=10.0;
00057 alpha=5.0;
00058 c=(1.0-exp(-alpha))*(1.0-exp(-alpha))/(1.0+2.0*alpha*exp(-alpha)-exp(-2.0*alpha));
00059 for(i=0;i<nb;i++)
00060  {
00061     val=c*(1.0+alpha*top)*exp(-alpha*top)-eps;
00062     if (val<0)  alpha2=alpha;
00063     else alpha1=alpha;
00064     alpha=(alpha1+alpha2)*0.5;
00065  }
00066 return(alpha);
00067 }
00068 
00069 
00070 
00071 
00072 
00073 /******************************************************************/
00074 void Equation3D(double *g,double *lambda,double vect[3][3],int flag)
00075 {
00076     double b,c,d,p,q,delta,teta,module,x,y,z,lambda_temp,val;
00077     int i;
00078 
00079 b= -g[0]-g[3]-g[5];
00080 c= -g[1]*g[1]-g[2]*g[2]-g[4]*g[4]+g[0]*g[3]+g[0]*g[5]+g[3]*g[5];
00081 d= -g[0]*g[3]*g[5]+g[0]*g[4]*g[4]+g[3]*g[2]*g[2]+g[5]*g[1]*g[1]-
00082         2.0*g[1]*g[2]*g[4];                                     
00083 p= c-b*b/3.0;
00084 q= d-b*c/3.0+2.0*b*b*b/27.0;
00085 delta=q*q+4*p*p*p/27;
00086 if(delta > 0) { 
00087         teta = 0;
00088         module = 1.0 ;
00089         lambda[0] = lambda[1] = lambda[2] = 0.0;
00090 } else {
00091         if (delta==0.0 && q==0.0) teta = 0.0;
00092         else teta = atan2(sqrt(-delta), -q);
00093         module = 2.0*sqrt(-p/3.0);
00094         lambda[0] = module*cos(teta/3.0)-b/3.0; 
00095         lambda[1] = module*cos((teta+PI_DOUBLE)/3.0)-b/3.0;     
00096         lambda[2] = module*cos((teta+2.0*PI_DOUBLE)/3.0)-b/3.0;
00097 }
00098 if ( fabs(lambda[1]) > fabs(lambda[0]) ) 
00099  { 
00100     lambda_temp = lambda[0]; 
00101     lambda[0] = lambda[1]; 
00102     lambda[1] = lambda_temp; 
00103  }
00104 if ( fabs(lambda[2]) > fabs(lambda[0]) ) 
00105  {  
00106     lambda_temp = lambda[0]; 
00107     lambda[0] = lambda[2]; 
00108     lambda[2] = lambda_temp; 
00109  }
00110 if ( fabs(lambda[2]) > fabs(lambda[1]) ) 
00111  { 
00112     lambda_temp = lambda[1]; 
00113     lambda[1] = lambda[2]; 
00114     lambda[2] = lambda_temp; 
00115  }
00116 x = y = z = 0.0;
00117 for(i=0;i<3;i++)
00118  {      
00119     val=lambda[i];
00120 
00121     module=(g[3]-val)*(g[5]-val)-g[4]*g[4];
00122     if ( fabs(module) > 0.01 )
00123     {
00124         x=1.0;
00125         y=( -(g[5]-val)*g[1]+g[4]*g[2] ) / module;
00126         z=( -(g[3]-val)*g[2]+g[4]*g[1] ) / module;
00127     }
00128     else
00129     {
00130         module=(g[0]-val)*(g[3]-val)-g[1]*g[1];
00131         if ( fabs(module) > 0.01 )
00132         {
00133             x=( -(g[3]-val)*g[2]+g[4]*g[1] ) / module;
00134             y=( -(g[0]-val)*g[4]+g[1]*g[2] ) / module;
00135             z=1.0;
00136         }
00137         else
00138         {
00139             module = (g[0]-val)*(g[5]-val)-g[2]*g[2];
00140             if ( module > 0.01 )
00141             {
00142                 y = 1.0;
00143                 x = ((val-g[5])*g[1]+g[2]*g[4])/module;
00144                 z = ((val-g[0])*g[4]+g[1]*g[2])/module;
00145             }
00146             else { x=0; y=0; z=0; }
00147         }
00148     }
00149     module = sqrt(x*x+y*y+z*z);
00150     if ( fabs(module) > 0.01 )
00151     {
00152         vect[i][0]=x/module;
00153         vect[i][1]=y/module;
00154         vect[i][2]=z/module;
00155     }
00156     else
00157     {
00158         vect[i][0]=1.0;
00159         vect[i][1]=0.0;
00160         vect[i][2]=0.0;
00161     }
00162  }
00163 if (flag==1) 
00164  {
00165     lambda[0]=fabs(b);
00166     lambda[1]=fabs(c);
00167     lambda[2]=fabs(d);
00168  }
00169 }
00170 
00171 
00172 
00173 /******************************************************************/
00174 void Acp3D_NS(short **gradx, short **grady, short **gradz,
00175                         int largeur, int hauteur,
00176                         float *acp_x, float *acp_y, float *acp_z,
00177                         float *conf1, float *conf2, float *conf3,
00178                         int tax, int tay, int taz, int flag)
00179 {
00180     long k, k_inf, k_sup, l, n, p, m, limx = tax/2, limy=tay/2;
00181     long add, add_sup, add_inf, taille = largeur*hauteur;
00182     double * somme_colonne_xx, * somme_colonne_yy, * somme_colonne_zz,
00183                  * somme_colonne_xy, * somme_colonne_xz, * somme_colonne_yz;
00184     double somme_xx, somme_yy, somme_zz, somme_xy, somme_xz, somme_yz,
00185                 gx, gy, gz, gx_sup, gx_inf, gy_sup, gy_inf, gz_sup, gz_inf;
00186     double tf;
00187     double g[6], vect[3][3], lambda[3] , val;
00188 
00189 for (add=0; add<taille; add++)
00190 { acp_x[add] = acp_y[add] = acp_z[add] = (float)0.0; }
00191 somme_colonne_xx = (double *) malloc (largeur*sizeof(double));
00192 somme_colonne_yy = (double *) malloc (largeur*sizeof(double));
00193 somme_colonne_zz = (double *) malloc (largeur*sizeof(double));
00194 somme_colonne_xy = (double *) malloc (largeur*sizeof(double));
00195 somme_colonne_xz = (double *) malloc (largeur*sizeof(double));
00196 somme_colonne_yz = (double *) malloc (largeur*sizeof(double));
00197 tf=(double)tax*tay*taz;
00198 for (k=0; k<largeur; k++)
00199  {
00200     somme_colonne_xx[k] = somme_colonne_yy[k] = somme_colonne_zz[k]
00201                         = somme_colonne_xy[k] = somme_colonne_xz[k]
00202                         = somme_colonne_yz[k] = 0.0;
00203     for (l=0; l<tay; l++)
00204     {
00205         add = l*largeur+k;
00206         for (m=0; m<taz; m++)
00207         {
00208             gx=(double)gradx[m][add];
00209             gy=(double)grady[m][add];
00210             gz=(double)gradz[m][add];
00211             somme_colonne_xx[k] += gx*gx;
00212             somme_colonne_yy[k] += gy*gy;
00213             somme_colonne_zz[k] += gz*gz;
00214             somme_colonne_xy[k] += gx*gy;
00215             somme_colonne_xz[k] += gx*gz;
00216             somme_colonne_yz[k] += gy*gz;
00217         }
00218     }
00219  }
00220 for (p=limy; p<hauteur-limy; p++)
00221  {
00222     somme_xx = somme_yy = somme_zz = somme_xy = somme_xz = somme_yz = 0.0;
00223     for (k=0; k<tax; k++)
00224     {
00225         somme_xx += somme_colonne_xx[k];
00226         somme_yy += somme_colonne_yy[k];
00227         somme_zz += somme_colonne_zz[k];
00228         somme_xy += somme_colonne_xy[k];
00229         somme_xz += somme_colonne_xz[k];
00230         somme_yz += somme_colonne_yz[k];
00231     }
00232     for (n=limx; n<largeur-limx; n++)
00233     {
00234         add = p*largeur+n;
00235         g[0] = somme_xx/tf;
00236         g[1] = somme_xy/tf;
00237         g[2] = somme_xz/tf;
00238         g[3] = somme_yy/tf;
00239         g[4] = somme_yz/tf;
00240         g[5] = somme_zz/tf;
00241         Equation3D(g,lambda,vect,flag);
00242         acp_x[add] = (float)vect[0][0];
00243         acp_y[add] = (float)vect[0][1];
00244         acp_z[add] = (float)vect[0][2];
00245         if (acp_x[add]<0)
00246         {
00247             acp_x[add] = -acp_x[add];
00248             acp_y[add] = -acp_y[add];
00249             acp_z[add] = -acp_z[add];
00250         }
00251         conf1[add] = (float)(lambda[0]);
00252         conf2[add] = (float)(lambda[1]);
00253         conf3[add] = (float)(lambda[2]);
00254 
00255         if ( n < (largeur-limx-1) )
00256         {
00257             k_sup = n+limx+1; k_inf = n-limx;
00258             somme_xx += somme_colonne_xx[k_sup]-somme_colonne_xx[k_inf];
00259             somme_yy += somme_colonne_yy[k_sup]-somme_colonne_yy[k_inf];
00260             somme_zz += somme_colonne_zz[k_sup]-somme_colonne_zz[k_inf];
00261             somme_xy += somme_colonne_xy[k_sup]-somme_colonne_xy[k_inf];
00262             somme_xz += somme_colonne_xz[k_sup]-somme_colonne_xz[k_inf];
00263             somme_yz += somme_colonne_yz[k_sup]-somme_colonne_yz[k_inf];
00264 
00265         }
00266     }
00267     if ( p != (hauteur-limy-1) )
00268         for (k=0; k<largeur; k++)
00269         {
00270             add_sup = (p+limy+1)*largeur+k;
00271             add_inf = (p-limy)*largeur+k;
00272             for (m=0; m<taz; m++)
00273             {
00274                     gx_sup = (double)gradx[m][add_sup];
00275                     gx_inf = (double)gradx[m][add_inf];
00276                     gy_sup = (double)grady[m][add_sup];
00277                     gy_inf = (double)grady[m][add_inf];
00278                     gz_sup = (double)gradz[m][add_sup];
00279                     gz_inf = (double)gradz[m][add_inf];
00280                     somme_colonne_xx[k] += gx_sup*gx_sup-gx_inf*gx_inf;
00281                     somme_colonne_yy[k] += gy_sup*gy_sup-gy_inf*gy_inf;
00282                     somme_colonne_zz[k] += gz_sup*gz_sup-gz_inf*gz_inf;
00283                     somme_colonne_xy[k] += gx_sup*gy_sup-gx_inf*gy_inf;
00284                     somme_colonne_xz[k] += gx_sup*gz_sup-gx_inf*gz_inf;
00285                     somme_colonne_yz[k] += gy_sup*gz_sup-gy_inf*gz_inf;
00286             }
00287         }
00288  }
00289 free(somme_colonne_xx); free(somme_colonne_xy); free(somme_colonne_yy);
00290 free(somme_colonne_xz); free(somme_colonne_yz); free(somme_colonne_zz);
00291 }
00292 
00293 
00294 
00295 /********************************************************/
00296 void LissageDeriche (float alpha,float *ima,int largeur,int hauteur)
00297 {
00298     float  *imatmp;
00299     double *vectima,*vectaller,*vectretour,*tmpvect;
00300     float *tmpdeb,*tmpfin,*tmp;
00301     int m, n;
00302     double a1, a2,a3,a4, b, b1, b2;
00303     long adresse, add, taille;
00304 
00305 taille=(long)largeur*(long)hauteur;
00306 imatmp=(float  *)calloc(taille,sizeof(float));
00307 
00308 b=(1-exp(-alpha))*(1-exp(-alpha))/(1+2*alpha*exp(-alpha)-exp(-2*alpha));
00309 a1=b;
00310 a2=b*exp(-alpha)*(alpha-1);
00311 a3=b*exp(-alpha)*(alpha+1);
00312 a4=-b*exp(-2*alpha);
00313 b1=2*exp(-alpha);
00314 b2=-exp(-2*alpha);
00315 /********************************************************/
00316 /************** Filtrage PB ligne************************/
00317 /********************************************************/
00318 vectima=(double *)calloc(largeur,sizeof(double));
00319 vectaller=(double *)calloc(largeur,sizeof(double));
00320 vectretour=(double *)calloc(largeur,sizeof(double));
00321 for (n=0; n<hauteur; n++)
00322  {
00323     adresse=(long)n*largeur;
00324     tmpdeb=ima+adresse;
00325     tmpfin=tmpdeb+largeur;
00326     tmpvect=vectima;
00327     for(tmp=tmpdeb;tmp<tmpfin;*(tmpvect++)=(double)( *(tmp++)) );
00328         /************************************************/
00329         /********** Filtrage PB ligne aller**************/
00330         /************************************************/
00331     vectaller[0]=(a1+a2)/(1-b1-b2)*vectima[0];
00332     vectaller[1]=a1*vectima[1]+a2*vectima[0]+
00333                 (b1+b2)*vectaller[0];
00334     for (add=2; add<largeur; add++)
00335         vectaller[add]=a1*vectima[add]+a2*vectima[add-1]
00336                         +b1*vectaller[add-1]+b2*vectaller[add-2];
00337 
00338         /************************************************/
00339         /********** Filtrage PB ligne retour*************/
00340         /************************************************/
00341     vectretour[largeur-1]=(a3+a4)/(1-b1-b2)*vectima[largeur-1];
00342     vectretour[largeur-2]=(a3+a4)*vectima[largeur-1] +
00343                         (b1+b2)*vectretour[largeur-1];
00344     for (add=largeur-3; add>-1; add--)
00345         vectretour[add]=a3*vectima[add+1]+a4*vectima[add+2]
00346                         +b1*vectretour[add+1]+b2*vectretour[add+2];
00347 
00348         /************************************************/
00349         /********** Filtrage PB ligne********************/
00350         /************************************************/
00351     for (add=0; add<largeur; add++)
00352         vectima[add]=vectaller[add]+vectretour[add];
00353 
00354     tmpdeb=imatmp+adresse;
00355     tmpfin=tmpdeb+largeur;
00356     tmpvect=vectima;
00357     for(tmp=tmpdeb;tmp<tmpfin;*(tmp++)=(float)( *(tmpvect++)) );
00358  }
00359 free(vectima); free(vectaller); free(vectretour);
00360 
00361 /********************************************************/
00362 /************** Filtrage PB colonne**********************/
00363 /********************************************************/
00364 vectima=(double *)calloc(hauteur,sizeof(double));
00365 vectaller=(double *)calloc(hauteur,sizeof(double));
00366 vectretour=(double *)calloc(hauteur,sizeof(double));
00367 for (m=0; m<largeur; m++)
00368  {
00369     adresse=(long)m;
00370     tmpdeb=imatmp+adresse;
00371     tmpfin=tmpdeb+(long)largeur*(hauteur-1);
00372     tmpvect=vectima;
00373     for(tmp=tmpdeb;tmp<=tmpfin;tmp+=largeur)
00374         *(tmpvect++)=(double)( *tmp );
00375         /************************************************/
00376         /********** Filtrage PB colonne aller************/
00377         /************************************************/
00378     vectaller[0]=(a1+a2)/(1-b1-b2)*vectima[0];
00379     vectaller[1]=a1*vectima[1]+a2*vectima[0]+
00380                 (b1+b2)*vectaller[0];
00381     for (add=2; add<hauteur; add++)
00382         vectaller[add]=a1*vectima[add]+a2*vectima[add-1]
00383                         +b1*vectaller[add-1]+b2*vectaller[add-2];
00384 
00385         /************************************************/
00386         /********** Filtrage PB colonne retour***********/
00387         /************************************************/
00388     vectretour[hauteur-1]=(a3+a4)/(1-b1-b2)*vectima[hauteur-1];
00389     vectretour[hauteur-2]=(a3+a4)*vectima[hauteur-1] +
00390                         (b1+b2)*vectretour[hauteur-1];
00391     for (add=hauteur-3; add>-1; add--)
00392         vectretour[add]=a3*vectima[add+1]+a4*vectima[add+2]
00393                         +b1*vectretour[add+1]+b2*vectretour[add+2];
00394 
00395         /************************************************/
00396         /********** Filtrage PB colonne******************/
00397         /************************************************/
00398     for (add=0; add<hauteur; add++)
00399         vectima[add]=vectaller[add]+vectretour[add];
00400 
00401     tmpdeb=ima+adresse;
00402     tmpfin=tmpdeb+(long)largeur*(hauteur-1);
00403     tmpvect=vectima;
00404     for(tmp=tmpdeb;tmp<=tmpfin;tmp+=largeur)
00405         *tmp=(float)( *(tmpvect++) );
00406  }
00407 free(vectima); free(vectaller); free(vectretour);
00408 free(imatmp);
00409 }
00410 
00411 
00412 
00413 
00414 
00415 
00416 
00417 
00418 
00419 void gradient3D(unsigned char ***ima,short *gradx,short *grady,short *gradz,int dimx,int dimy,float alpha,int n)
00420 {
00421     long add,taille;
00422     int i,j,k;
00423     float *tmp1, *tmp2, val;
00424     double *a, *b, soma, somb;
00425     unsigned int x,y; /*ajout lionel*/
00426 
00427 a=(double *)calloc((n+1),sizeof(double));
00428 b=(double *)calloc((n+1),sizeof(double));
00429 somb=0.0;
00430 soma=0.0;
00431 for(i=0;i<=n;i++)
00432  {
00433     b[i]=(1.0+alpha*i)*exp(-alpha*i);
00434     a[i]=(double)i*exp(-alpha*i);
00435     if (i==0) { soma+=a[i]; somb+=b[i]; }
00436     else { soma+=2.0*a[i]; somb+=2*b[i]; }
00437  }
00438 for(i=0;i<=n;i++)
00439  {
00440     a[i] /= soma;
00441     b[i] /= somb;
00442  }
00443 taille=(long)dimy*dimx;
00444 tmp1=(float *)calloc(taille,sizeof(float));
00445 tmp2=(float *)calloc(taille,sizeof(float));
00446 
00447 /****************** GRADIENT X *********************/
00448 
00449 //for (add=0;add<taille;add++)
00450 for ( y=0; y<dimy; y++)
00451   for (x=0; x<dimx; x++)
00452  {
00453    //val=b[0]*(float)ima[n][add];
00454     val=b[0]*(float)ima[n][y][x];
00455     for(k=1;k<=n;k++)
00456       //val += b[k]*((float)ima[n-k][add]+ima[n+k][add]);
00457         val += b[k]*((float)ima[n-k][y][x]+ima[n+k][y][x]);
00458     //tmp1[add]=val;
00459     tmp1[y*dimx+x]=val;
00460  }
00461 for (i=0;i<dimy;i++)
00462     for(j=n;j<dimx-n;j++)
00463     {
00464         add=i*dimx+j;
00465         val=0.0;
00466         for (k=1;k<=n;k++)
00467             val += a[k]*(tmp1[add+k]-tmp1[add-k]);
00468         tmp2[add]=val;
00469     }
00470 for (i=n;i<dimy-n;i++)
00471     for(j=0;j<dimx;j++)
00472     {
00473         add=i*dimx+j;
00474         val=b[0]*tmp2[add];
00475         for (k=1;k<=n;k++)
00476             val += b[k]*(tmp2[add-k*dimx]+tmp2[add+k*dimx]);
00477         gradx[add]=(short)val;
00478     }
00479 for (add=0;add<taille;add++) tmp2[add]=0;
00480 
00481 /****************** GRADIENT Y *********************/
00482 
00483 for (i=n;i<dimy-n;i++)
00484     for(j=0;j<dimx;j++)
00485     {
00486         add=i*dimx+j;
00487         val=0.0;
00488         for (k=1;k<=n;k++)
00489             val += a[k]*(tmp1[add+k*dimx]-tmp1[add-k*dimx]);
00490         tmp2[add]=val;
00491     }
00492 for (i=0;i<dimy;i++)
00493     for(j=n;j<dimx-n;j++)
00494     {
00495         add=i*dimx+j;
00496         val=b[0]*tmp2[add];
00497         for (k=1;k<=n;k++)
00498             val += b[k]*(tmp2[add-k]+tmp2[add+k]);
00499         grady[add]=(short)val;
00500     }
00501 for (add=0;add<taille;add++) tmp2[add]=0;
00502 
00503 /****************** GRADIENT Z *********************/
00504 
00505 //for (add=0;add<taille;add++)
00506 for ( y=0; y<dimy; y++)
00507   for (x=0; x<dimx; x++)
00508  {
00509     val = 0.0;
00510     for(k=1;k<=n;k++)
00511       //val += a[k]*((float)ima[n+k][add]-ima[n-k][add]);
00512         val += a[k]*((float)ima[n+k][y][x]-ima[n-k][y][x]);
00513     //tmp1[add]=val;
00514     tmp1[y*dimx+x]=val;
00515  }
00516 for (i=0;i<dimy;i++)
00517     for(j=n;j<dimx-n;j++)
00518     {
00519         add=i*dimx+j;
00520         val=b[0]*tmp1[add];
00521         for (k=1;k<=n;k++)
00522             val += b[k]*(tmp1[add-k]+tmp1[add+k]);
00523         tmp2[add]=val;
00524     }
00525 for (i=n;i<dimy-n;i++)
00526     for(j=0;j<dimx;j++)
00527     {
00528         add=i*dimx+j;
00529         val=b[0]*tmp2[add];
00530         for (k=1;k<=n;k++)
00531             val += b[k]*(tmp2[add-k*dimx]+tmp2[add+k*dimx]);
00532         gradz[add]=(short)val;
00533     }
00534 free(tmp1); free(tmp2);
00535 free(a); free(b);
00536 }
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 
00548 
00549 
00560 param* gradient_organisation_lect(ogi_t* des, param* ptp, char* debq){
00561   char question[500];
00562 
00563   sprintf(question, "Alpha (filtre de Deriche):", debq); 
00564   lec_param(question, ptp);
00565   des->alpha = atof(ptp->rep);
00566   ptp = ptp->next;
00567   
00568   sprintf(question, "Taille ACP x:", debq); 
00569   lec_param(question, ptp);
00570   des->ax = atoi(ptp->rep);
00571   ptp = ptp->next;
00572   
00573   sprintf(question, "Taille ACP y:", debq); 
00574   lec_param(question, ptp);
00575   des->ay = atoi(ptp->rep);
00576   ptp = ptp->next;
00577   
00578   sprintf(question, "Taille ACP z:", debq); 
00579   lec_param(question, ptp);
00580   des->az = atoi(ptp->rep);
00581   ptp = ptp->next;
00582   
00583   sprintf(question, "Taille gradient:", debq); 
00584   lec_param(question, ptp);
00585   des->tgrad = atoi(ptp->rep);
00586   ptp = ptp->next;
00587 
00588   printf("\nListe des attributs");
00589   printf("\n\t         1 : v1");
00590   printf("\n\t         2 : v2");
00591   printf("\n\t         3 : v3");
00592   printf("\n\t         4 : v1+v2+v3");
00593   printf("\n\t         5 : v2-v3");
00594   printf("\n\t         6 : (v2-v3)/(v1+v2+v3)");
00595   printf("\n\t         7 : v2+v3");
00596   printf("\n\t         8 : (v2+v3)/(v1+v2+v3)");
00597   printf("\n\t         9 : erreur de flux");
00598   printf("\n\t        10 : v3/(v1+v2+v3)");
00599   printf("\n\t        11 : v2*v3");
00600   printf("\n\t        12 : (v2*v3)/(v1+v2+v3)'2");
00601   printf("\n\t        13 : v1*v2*v3");
00602   printf("\n\t        14 : (v1*v2*v3)/(v1+v2+v3)'3");
00603   printf("\n\t        15 : (v2+v3)'n/(v1+v2+v3)'p");
00604   printf("\n\t        16 : v2/(v1+v3)");
00605   printf("\n\t        17 : (v2-v3)/(v2+v3)");
00606   
00607 
00608   sprintf(question, "Type d'attribut:", debq); 
00609   lec_param(question, ptp);
00610   des->type = atoi(ptp->rep);
00611   ptp = ptp->next;
00612 
00613   sprintf(question, "Coefficient de normalisation:", debq); 
00614   lec_param(question, ptp);
00615   des->normalisation = atof(ptp->rep);
00616   ptp = ptp->next;
00617 
00618   return(ptp);
00619 }
00620 
00621 
00622 
00623 
00624 
00625 
00626 
00627 int gradient_organisation_init(ogi_t* des, ima3Du1 * ima){
00628 
00629   int taille = ima->dimx*ima->dimy; 
00630   int i;
00631   
00632   /*allocation mémoire pour le calcul des gradients*/
00633   des->gradx=(short **)calloc(des->az,sizeof(short *));
00634   des->grady=(short **)calloc(des->az,sizeof(short *));
00635   des->gradz=(short **)calloc(des->az,sizeof(short *));
00636   for(i=0;i<des->az;i++)
00637     {
00638       des->gradx[i]=(short *)calloc(taille,sizeof(short));
00639       des->grady[i]=(short *)calloc(taille,sizeof(short));
00640       des->gradz[i]=(short *)calloc(taille,sizeof(short));
00641     }
00642 
00643   /*Allocation mémoire pour le calcul de l'ACP*/
00644   des->acp_x=(float *)calloc(taille,sizeof(float));
00645   des->acp_y=(float *)calloc(taille,sizeof(float));
00646   des->acp_z=(float *)calloc(taille,sizeof(float));
00647   des->conf1=(float *)calloc(taille,sizeof(float));
00648   des->conf2=(float *)calloc(taille,sizeof(float));
00649   des->conf3=(float *)calloc(taille,sizeof(float));
00650   
00651 
00652   des->alp=CalculAlpha(des->tgrad,50,0.02);
00653 
00654 
00655 }
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 int gradient_organisation_calc(ogi_t* des,  ima3Du1 * imaIn,  ima3Du1 * imaOut){
00664 
00665   int i;
00666   int num;
00667   float conf[20];
00668   int add;
00669   int x, y;
00670 
00671   short **gradx = des->gradx;
00672   short **grady = des->grady;
00673   short **gradz = des->gradz;
00674   float *acp_x  = des->acp_x;
00675   float *acp_y  = des->acp_y;
00676   float *acp_z  = des->acp_z;
00677   float *conf1  = des->conf1;  
00678   float *conf2  = des->conf2;
00679   float *conf3  = des->conf3;
00680 
00681   short *tmp_s1, *tmp_s2, *tmp_s3;
00682   float v1, v2, v3, val;
00683 
00684   /*calcul des gradients sur les AZ premiere sections*/
00685   gradient3D( imaIn->data, 
00686               gradx[0], grady[0], gradz[0],
00687               imaIn->dimx, imaIn->dimy,
00688               des->alp, des->tgrad/2);
00689   for(i=1;i<des->az;i++){
00690     gradient3D( imaIn->data, 
00691                 gradx[i], grady[i], gradz[i],
00692                 imaIn->dimx, imaIn->dimy,
00693                 des->alp, 2);
00694     lect_volume_u1_sequence_next(imaIn);
00695   }
00696 
00697   /*calcul de l'ACP sur toutes les sections*/  
00698   for( num=0; num<imaIn->dimz; num++){
00699     printf("Section %d/%d...\n",num+1,imaIn->dimz);
00700     Acp3D_NS( gradx, grady, gradz,
00701               imaIn->dimx,imaIn->dimy,
00702               acp_x, acp_y, acp_z,
00703               conf1,conf2,conf3,des->ax,des->ay,des->az,0);
00704 
00705     if (des->alpha!=0.0)
00706      {
00707         LissageDeriche( des->alpha, conf1, imaIn->dimx, imaIn->dimy);
00708         LissageDeriche( des->alpha, conf2, imaIn->dimx, imaIn->dimy);
00709         LissageDeriche( des->alpha, conf3, imaIn->dimx, imaIn->dimy);
00710      }
00711 
00712     for( add=0; add<(imaIn->dimx*imaIn->dimy); add++) {
00713         v1 = conf1[add];
00714         v2 = conf2[add];
00715         v3 = conf3[add];
00716         
00717         conf[1]=v1;
00718         conf[2]=v2;
00719         conf[3]=v3;
00720         conf[4]=v1+v2+v3;
00721         conf[5]=v2-v3;
00722         conf[6] = (conf[4]>0.01) ? (conf[2]-conf[3])/conf[4] : 0.0;
00723         conf[7]=(conf[2]+conf[3]);
00724         conf[8] = (conf[4]>0.01) ? (conf[2]+conf[3])/conf[4] : 0.0;
00725         if (v2>v3 && v2!=0.0){
00726           val=sqrt((v2-v3)/v2);
00727           conf[9] = v3/val*log( (1+val)/(1-val) );
00728         }
00729         else conf[9] = v2;
00730         conf[10] = (conf[4]>0.01) ? conf[3]/conf[4] : 0.0;
00731         conf[11]=conf[2]*conf[3];
00732         conf[12] = (conf[4]>0.01) ? conf[2]*conf[3]/(conf[4]*conf[4]) : 0.0;
00733         conf[13]=conf[1]*conf[2]*conf[3];
00734         conf[14] = (conf[4]>0.01) ? conf[1]*conf[2]*conf[3]/(conf[4]*conf[4]*conf[4]) : 0.0;
00735         //conf[15] = (conf[4]>0.5) ? pow(conf[7],n)/pow(conf[4],p) : 0.0;
00736 
00737         conf[16] = (v1>0.01) ? v2/(v1+v3) : 0.0;
00738         conf[17] = (v1-v2>0.01) ? (v2-v3)/(v1-v2) : 0.0;
00739         
00740         conf1[add]=conf[des->type];
00741     }
00742     
00743 
00744     for ( y=0; y<imaIn->dimy; y++)
00745       for ( x=0; x<imaIn->dimx; x++){
00746         add = y*imaIn->dimx+x;
00747         val=fabs(conf1[add]*des->normalisation); 
00748         val = (val>255) ? 255 : val; 
00749         val = (val<0) ? 0 : val; 
00750         imaOut->data[0][y][x] = (unsigned char)val;
00751       }
00752 
00753     write_volume_u1_sequence_next( imaOut);
00754     
00755     tmp_s1=gradx[0]; tmp_s2=grady[0]; tmp_s3=gradz[0];
00756     for( i=0; i<des->az-1; i++){
00757       gradx[i]=gradx[i+1];
00758       grady[i]=grady[i+1];
00759       gradz[i]=gradz[i+1];
00760     }
00761     gradx[des->az-1]=tmp_s1; grady[des->az-1]=tmp_s2; gradz[des->az-1]=tmp_s3;
00762     
00763     lect_volume_u1_sequence_next(imaIn);
00764     gradient3D( imaIn->data,
00765                 gradx[des->az-1],grady[des->az-1],gradz[des->az-1],
00766                 imaIn->dimx,imaIn->dimy,des->alp,des->tgrad/2);
00767     
00768   }/*fin for sur les sections*/
00769 
00770  
00771 }
00772 
00773 
00774 
00775 
00776 
00777 int gradient_organisation_ferm(ogi_t* des){
00778   int i;
00779   
00780   for(i=0;i<des->az;i++) { 
00781     free(des->gradx[i]); 
00782     free(des->grady[i]); 
00783     free(des->gradz[i]); 
00784   }
00785   free(des->gradx); 
00786   free(des->grady); 
00787   free(des->gradz);
00788 
00789   free(des->acp_x);
00790   free(des->acp_y);
00791   free(des->acp_z);
00792   free(des->conf1);
00793   free(des->conf2);
00794   free(des->conf3);
00795 
00796 }
00797 
00798 
00799 
00800 

Generated on Tue Apr 22 13:31:06 2008 for volume by  doxygen 1.5.3