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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
typedef struct T_image
{
char P[2];
int n;
int l;
int h;
int nb_col;
int R;
int V;
int B;
}T_image;
void convolution(FILE *image0,double M[3][3],int n)
{
FILE *sortie=fopen("image_sortie.ppm","w");
T_image I;
supprim_com(image0,"image.ppm");
FILE *image=fopen("image.ppm","r");
fseek(image,0,SEEK_SET);
fscanf(image,"%c%d\n%d %d\n%d",&(I.P[0]),&(I.n),&(I.l),&(I.h),&(I.nb_col));
I.P[1]='\0';
fprintf(sortie,"%c%d\n%d %d\n%d\n",I.P[0],I.n,I.l,I.h,I.nb_col);
int R[I.l][n];int V[I.l][n];int B[I.l][n];
int h,l,i,j;
double R1,V1,B1,R2,V2,B2;
//initialisation
for(j=0;j<n;j++)
for(i=0;i<I.l;i++)
fscanf(image,"%d\n%d\n%d\n",&(R[i][j]),&(V[i][j]),&(B[i][j]));
//calcul des pixels "masqués" et des début et fin de lignes (copie)
for(h=0;h<I.h;h++)
for(l=0;l<I.l;l++)
{
if (h<((n-1)/2) || h>((I.h-(n-1)/2)-1) || l<((n-1)/2) || l>((I.l-(n-1)/2))-1)
{
/*if (h<((n-1)/2))
{
fprintf(sortie,"%d\%d\%d\n",R[l][(n-1)/2],V[l][(n-1)/2],B[l][(n-1)/2]);
}
if (h>((I.h-(n-1)/2)-1))
{
if (h!=(I.h-1))
{
fprintf(sortie,"%d\%d\%d\n",R[l][(n-1)/2],V[l][(n-1)/2],B[l][(n-1)/2]);
}
else
{
fprintf(sortie,"%d\%d\%d\n",R[l][n-1],V[l][n-1],B[l][n-1]);
}
}
if (l<((n-1)/2))
{
fprintf(sortie,"%d\%d\%d\n",R[l][(n-1)/2],V[l][(n-1)/2],B[l][(n-1)/2]);
}
if (l>((I.l-(n-1)/2))-1)
{
fprintf(sortie,"%d\%d\%d\n",R[l][(n-1)/2],V[l][(n-1)/2],B[l][(n-1)/2]);
}
//fprintf(sortie,"%d\n%d\n%d\n",R[l][h],V[h][h],B[l][h]);*/
fprintf(sortie,"255\n255\n255\n");
}
else
{
R2=0;V2=0;B2=0;
for(j=0;j<n;j++)
for(i=0;i<n;i++)
{
R1=(double)R[l+i-(n-1)/2][j];
V1=(double)V[l+i-(n-1)/2][j];
B1=(double)B[l+i-(n-1)/2][j];
R2=R2+R1*M[i][j];
V2=V2+V1*M[i][j];
B2=B2+B1*M[i][j];
}
fprintf(sortie,"%d\n%d\n%d\n",(int)R2,(int)V2,(int)B2);
//fprintf(sortie,"100\n166\n55\n");
}
//on calcule les nouveaux tableaux des couleurs
for(j=0;j<n-1;j++)
for(i=0;i<I.l;i++)
{
R[i][j]=R[i][j+1];
V[i][j]=V[i][j+1];
B[i][j]=B[i][j+1];
}
for(i=0;i<I.l;i++)
fscanf(image,"%d\n%d\n%d\n",&(R[i][n-1]),&(V[i][n-1]),&(B[i][n-1]));
}
//fin de l'écriture de la convolution
fclose(sortie);
remove("image.ppm");
} |
Partager