lmedian3d.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 */
00019 
00039 #include "image.h"
00040 #include "median3d.h"
00041 #include <stdlib.h>
00042 
00043 
00044 /* *************************  LECTURE  *******************************/
00056 param* median3d_lect(median3d_t* tMasque, param* ptp, char* debq)
00057 {
00058   char question[500];
00059 
00060 
00061   sprintf(question, "%s winX (entier impair positif)", debq); 
00062   lec_param(question, ptp);
00063   tMasque->winX = atoi(ptp->rep);
00064   ptp = ptp->next;
00065 
00066   sprintf(question, "%s winY (entier impair positif)", debq); 
00067   lec_param(question, ptp);
00068   tMasque->winY = atoi(ptp->rep);
00069   ptp = ptp->next;
00070 
00071   sprintf(question, "%s winZ (entier impair positif)", debq); 
00072   lec_param(question, ptp);
00073   tMasque->winZ = atoi(ptp->rep);
00074   ptp = ptp->next;
00075 
00076   return(ptp);
00077 }
00078 
00079 /* *************************  INITIALISATION  ***************************/
00091 int median3d_init(median3d_t* tMasque, ima3Du1 im0, ima3Du1* imres)
00092 {
00093   /* image resultat */ 
00094   imres->dimx= im0.dimx; 
00095   imres->dimy= im0.dimy;
00096   imres->dimz= im0.dimz;
00097 
00098 
00099   //printf("\n masque :%d x %d x %d \n",tMasque->winX,tMasque->winY,tMasque->winZ); 
00100   allouer_ima3Du1 (imres);
00101   imres->lgtete= im0.lgtete;
00102   imres->dept= im0.dept;
00103 }
00104 
00105 
00106 /* *************************  CALCUL  ***************************/
00118 int median3d_calc(median3d_t *tMasque, ima3Du1 im0, ima3Du1 *imres)
00119 {
00120  int x=0;
00121  int y=0;
00122  int z=0;
00123  int elx=0;
00124  int ely=0;
00125  int elz=0;
00126  //nb. de elements dans le masque
00127  int nb_case=tMasque->winX*tMasque->winY*tMasque->winZ;
00128  int pixel[nb_case+1];
00129  int q=1;
00130  unsigned long i,j,inc;
00131  int v;
00132  inc=1;
00133  //parcour de l'image
00134    for(x=(tMasque->winX-1)/2;x<im0.dimx-(tMasque->winX-1)/2;x++){
00135      for(y=(tMasque->winY-1)/2;y<im0.dimy-(tMasque->winY-1)/2;y++){
00136        for(z=(tMasque->winZ-1)/2;z<im0.dimz-(tMasque->winZ-1)/2;z++){
00137          // selection des pixels x,y,z de l'image permettant d'appliquer completement le filtre
00138          for(elx=-(tMasque->winX-1)/2;elx<=(tMasque->winX-1)/2;elx++){
00139            for(ely=-(tMasque->winY-1)/2;ely<=(tMasque->winY-1)/2;ely++){
00140              for(elz=-(tMasque->winZ-1)/2;elz<=(tMasque->winZ-1)/2;elz++){
00141                //vecteur 1D  avec les elements de la masque
00142                pixel[q]=im0.data[z+elz][y+ely][x+elx];
00143 /*             printf("%d %d ",q,pixel[q]); */
00144                q++;
00145              }
00146            }
00147          }
00148          //triage de le vecteur pixel par la methode Shell
00149          // www.ulib.org/webRoor/Books/Numerical_Recipes/
00150          do {
00151            inc*=3;
00152            inc++;
00153          }while (inc<=nb_case);
00154          do {
00155            inc/=3;
00156            for (i=inc+1;i<=nb_case;i++) {
00157              v=pixel[i];
00158              j=i;
00159              while (pixel[j-inc]>v) {
00160                pixel[j]=pixel[j-inc];
00161                j-=inc;
00162                if (j<=inc) break;
00163              }
00164              pixel[j]=v;
00165            }
00166          } while (inc>1);
00167 /*       for (q=1;q<nb_case+1;q++) printf("%d %d ",q,pixel[q]); */
00168          q=1;
00169          imres->data[z][y][x]=pixel[(nb_case+1)/2];
00170 /*       printf("%d ",pixel[(nb_case+1)/2]); */
00171        }
00172      }
00173    }
00174  return(0);
00175 }
00176 
00177 

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