Bonjour , en effet j'ai un gros problème que je n'arrive pas à résoudre alors une petite aide sera la bienvenue.
voilà je charge mon fichier .ppm dans une matrice.
XXX
XXX
XXX
J'entoure cette matrice par 1 ligne/colonne de 0 (pour l'application des filtres)
OOOOO
OXXXO
OXXXO
OXXXO
OOOOO
si j'ouvre puis je sauvegarde le même fichier tout se passe bien.
Passant maintenant à l'application du filtre :
PAR EXEMPLE effet FLOU :
puis le ecrire tout sur le fichier de sortie
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
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 void appliquerFiltre(char* name) { //taille image MatriceImgROut=malloc_matrice_2d(length,width); MatriceImgVOut=malloc_matrice_2d(length,width); MatriceImgBOut=malloc_matrice_2d(length,width); coefficients=malloc_matrice_2d(3,3); int h , w , i , j ; coefficients[0][0] = 1 ; coefficients[0][1] = 1; coefficients[0][2] = 1 ; coefficients[1][0] = 1; coefficients[1][1] = 1; coefficients[1][2] = 1 ; coefficients[2][0] = 1 ; coefficients[2][1] = 1 ; coefficients[2][2] = 1 ; for (h = 0 ; h < length ; h++) for (w = 0 ; w < width ; w++) { MatriceImgROut[h][w] = 0 ; MatriceImgVOut[h][w] = 0 ; MatriceImgBOut[h][w] = 0 ; for (i = 0 ; i < 3 ; i++) for (j = 0 ; j < 3 ; j++) { MatriceImgROut[h][w] += coefficients[i][j] * MatriceImgR[h+i][w+j] ; MatriceImgVOut[h][w] += coefficients[i][j] * MatriceImgV[h+i][w+j] ; MatriceImgBOut[h][w] += coefficients[i][j] * MatriceImgB[h+i][w+j] ; } MatriceImgROut[h][w] = MatriceImgROut[h][w]/9 ; if(MatriceImgROut[h][w]<0) MatriceImgROut[h][w]=0; else if(MatriceImgROut[h][w]>255) MatriceImgROut[h][w]=255; MatriceImgVOut[h][w] = MatriceImgVOut[h][w]/9; if(MatriceImgVOut[h][w]<0) MatriceImgVOut[h][w]=0; else if(MatriceImgVOut[h][w]>255) MatriceImgVOut[h][w]=255; MatriceImgBOut[h][w] = MatriceImgBOut[h][w]/9; if(MatriceImgBOut[h][w]<0) MatriceImgBOut[h][w]=0; else if(MatriceImgBOut[h][w]>255) MatriceImgBOut[h][w]=255; }
Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 /*--sauvegarde de l'entete--*/ fprintf(fic,"P3"); fprintf(fic,"\n# IMG Created , %s",ctime(&tm)); fprintf(fic,"%d %d",length,width); fprintf(fic,"\n255\n"); /*--enregistrement--*/ for(i=0;i<length;i++) for(j=0;j<width;j++) { fprintf(fic,"%d\n",(int)MatriceImgROut[i][j]); fprintf(fic,"%d\n",(int)MatriceImgVOut[i][j]); fprintf(fic,"%d\n",(int)MatriceImgBOut[i][j]); }
Le résultat j'ai un effet flou mais image impossible à reconnaitre on dirait que j'ai pris juste un morceau vertical et je l'ai mis 3 fois :s
merci de regarder le code si jamais vous voyez quelque chose .
Partager