00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00039 #include "image.h"
00040 #include "median3d.h"
00041 #include <stdlib.h>
00042
00043
00044
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
00091 int median3d_init(median3d_t* tMasque, ima3Du1 im0, ima3Du1* imres)
00092 {
00093
00094 imres->dimx= im0.dimx;
00095 imres->dimy= im0.dimy;
00096 imres->dimz= im0.dimz;
00097
00098
00099
00100 allouer_ima3Du1 (imres);
00101 imres->lgtete= im0.lgtete;
00102 imres->dept= im0.dept;
00103 }
00104
00105
00106
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
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
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
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
00142 pixel[q]=im0.data[z+elz][y+ely][x+elx];
00143
00144 q++;
00145 }
00146 }
00147 }
00148
00149
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
00168 q=1;
00169 imres->data[z][y][x]=pixel[(nb_case+1)/2];
00170
00171 }
00172 }
00173 }
00174 return(0);
00175 }
00176
00177