-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiltre_flou2.cpp
More file actions
77 lines (63 loc) · 1.51 KB
/
Copy pathfiltre_flou2.cpp
File metadata and controls
77 lines (63 loc) · 1.51 KB
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
#include <stdio.h>
#include "image_ppm.h"
/*
moyenne de ce pixel avec ses 8 voisins
*/
int main(int argc, char* argv[])
{
char cNomImgLue[250], cNomImgEcrite[250];
int nH, nW, nTaille;
if (argc != 3)
{
printf("Usage: ImageIn.pgm ImageOut.pgm \n");
exit (1) ;
}
sscanf (argv[1],"%s",cNomImgLue) ;
sscanf (argv[2],"%s",cNomImgEcrite);
OCTET *ImgIn, *ImgOut;
lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &nH, &nW);
nTaille = nH * nW;
allocation_tableau(ImgIn, OCTET, nTaille);
lire_image_pgm(cNomImgLue, ImgIn, nH * nW);
allocation_tableau(ImgOut, OCTET, nTaille);
// pour les bordures moyenneur
/*
for(int i=0; i<nH; i++) {
for(int j=0; j<nW; j++)
{
int x = 0;
int quantite = 0;
for(int k=-1; k<2; k++) {
for(int t=-1; t<2; t++)
{
if(i+k>=0 && i+k<nH && j+t>=0 && j+t<nW) {
x += ImgIn[(i+k)*nW+j+t];
quantite++;
}
}
}
ImgOut[i*nW+j] = (int)(x/quantite);
}
}
*/
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
if (i == 0 || j == 0 || i == nW-1 || i == nH-1)
ImgOut[i*nW+j] = ImgIn[i*nW+j];
else{
int x = 0;
for (int k = -1; k < 2; ++k){
for (int t = -1; t < 2; ++t)
{
x += ImgIn[(i+k)*nW + j+t];
}
}
ImgOut[i*nW+j] = x/9;
}
}
}
ecrire_image_pgm(cNomImgEcrite, ImgOut, nH, nW);
free(ImgIn); free(ImgOut);
return 1;
}