#include #include #define W 3 #define batd "lena.dim" #define bati "lena.ima" #define imagedim "a.dim" #define imageima "a.ima" #define sortieima "test.ima" #define sortiedim "test.dim" int charge_image(void); int ecrire_image(void); unsigned char cwm(int ,int ,int); int chercheIndice(unsigned char*, int , unsigned char); void insere(unsigned char*, int, unsigned char, int); unsigned char choix(int ,int ,int); long int erreur(void); unsigned char **image_entree; unsigned char **image_sortie; long int size1, size2; int T; int Wc; void main(void) { int i,j; Wc=3; charge_image(); for (T=12;T<13;T=T+2) { ecrire_image(); printf("%ld\n", erreur()/(size1*size2)); } } int charge_image(void) { FILE *dim,*ima; int i,j; dim=fopen(imagedim,"r"); fscanf(dim,"%d %d",&size1,&size2); image_entree=(unsigned char**)malloc(size1*sizeof(unsigned char*)); for(i=0;i<(size1);i++) image_entree[i]=(unsigned char*)malloc(size2*sizeof(unsigned char)); ima=fopen(imageima,"r"); for(i=0;i=(size1-W/2))||(j>=(size2-W/2))) { fprintf(ima,"%c",image_entree[i][j]); } else fprintf(ima,"%c",choix(i,j,T)); } fclose(ima); return(1); } unsigned char choix(int x, int y, int t) { if (abs(image_entree[x][y]-cwm(x,y,1)) <= t) { return image_entree[x][y]; } else if (abs(image_entree[x][y]-cwm(x,y,Wc) <= t ) && ( t < abs(image_entree[x][y]-cwm(x,y,1)))) { return cwm(x,y,Wc); } else if (abs(image_entree[x][y]-cwm(x,y,Wc)) > t ) { return cwm(x,y,1); } } unsigned char cwm(int x,int y,int c) { char vecteur[W*W-1+c],vecteur_sortie[W*W-1+c]; int i,j; for(i=0;i tableau[milieu]) gauche = milieu + 1; else if (cle == tableau[milieu]) return milieu; else return -1; } return gauche; } void insere(unsigned char * tableau, int nbEntiers,unsigned char cle, int place) { int i; for(i = nbEntiers; i > place; i--) tableau[i] = tableau[i - 1]; tableau[place] = cle; } long int erreur(void) { int i,j; long int err; FILE *f,*g,*h; unsigned char a,b,c; long int a1,b1; f=fopen(sortieima,"r"); g=fopen(bati,"r"); err=0; for(i=0;i