1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include<stdlib.h>
#include<stdio.h>
int Lecture(int **tab,int h,int i,int j){
FILE* fichier = NULL;
int a,b,c,d,e,f,g;
int pix[i*j];
fichier = fopen("//home//richard//projet//foreman.yuv","r");
if(fichier!=NULL){
for(a=0;a<h;a++){
tab[a] = malloc((i*j)*sizeof(int));
for(b=0;b<i;b++){
for(c=0;c<j;c++){
fread(&pix,1,1,fichier);
tab[a][b*c]=*pix;
//printf("la valeur à l'image %d, pixel: avec longueur=%d et hauteur=%d est: %d \n",a+1,b,c,tab[a][b*c]);
}
}
for(d=0;d<(i/2);d++){
for(e=0;e<(j/2);e++){
fread(&pix,1,1,fichier);
}
}
for(f=0;f<(i/2);f++){
for(g=0;g<(j/2);g++){
fread(&pix,1,1,fichier);
}
}
}
fclose(fichier);
}
else{
printf("Impossible d'ouvrir le fichier");
}
return tab[a][b*c];
}
void MoyennageFond(int *TF,int h, int i,int j){ //Cette fonction permet de faire une valeur moyenne pour chaque pixel de chaque image afin de stocker le tout dans un tableau de fond
//Moyennage
int k,l,m,som;
for(k=0;k<j;k++){
for(l=0;l<i;l++){
som=0;
TF = malloc((i*j)*sizeof(int));
for(m=0;m<h;m++){
som+=tab[m][k*l];
}
TF[k*l]=som/m;
printf("la valeur moyenne avec longueur=%d et largeur=%d est: %d \n",k,l,TF[k*l]);
}
}
}
int main(void){
int **tableau;
int *tabFond;
int nb_img,nb_long,nb_larg;
printf("Sur combien d'images voulez vous travailler? ");
scanf("%d",&nb_img);
printf("Quelle est le nombre de pixel en longueur?");
scanf("%d",&nb_long);
printf("Quelle est le nombre de pixel en largeur?");
scanf("%d",&nb_larg);
tableau = malloc(nb_img*sizeof(int *));
Lecture(tableau,nb_img,nb_long,nb_larg);
tabFond = malloc
MoyennageFond(tableau,nb_img,nb_long,nb_larg,tabFond);
return 0;
} |
Partager