-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathouverture_pgm.cpp
More file actions
101 lines (78 loc) · 1.97 KB
/
ouverture_pgm.cpp
File metadata and controls
101 lines (78 loc) · 1.97 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include "image_ppm.h"
/*
Pour supprimer des points parasites du fond de l’image binaire
*/
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, *ImgOut2;
lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &nH, &nW);
nH = 256;
nW = 256;
nTaille = nH * nW;
allocation_tableau(ImgIn, OCTET, nTaille);
lire_image_pgm(cNomImgLue, ImgIn, nH * nW);
allocation_tableau(ImgOut, OCTET, nTaille);
allocation_tableau(ImgOut2, OCTET, nTaille);
// Erosion puis dilatation pour remplier les trous
//Erosion
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
ImgOut[i*nW+j] = 0;
for (int k = -1; k < 2; ++k)
{
for (int t = -1; t < 2; ++t)
{
int a = i+k;
int b = j+t;
int indice = a*nW+b;
if (a < 0 || a >= nH || b < 0 || b >= nW)
continue;
else {
if (ImgIn[indice] == 255){
ImgOut[i*nW+j] = 255;
break;
}
}
}
}
}
}
//Dilatation
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
ImgOut2[i*nW+j] = 255; // pour initialiser l'image output à blanc
for (int k = -1; k < 2; ++k)
{
for (int t = -1; t < 2; ++t)
{
int a = i+k;
int b = j+t;
int indice = a*nW+b;
if (a < 0 || a >= nH || b < 0 || b >= nW)
continue;
else {
if (ImgOut[indice] == 0){
ImgOut2[i*nW+j] = 0;
break;
}
}
}
}
}
}
ecrire_image_pgm(cNomImgEcrite, ImgOut2, nH, nW);
free(ImgIn); free(ImgOut); free(ImgOut2);
return 1;
}