-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhysteresis_pgm.cpp
More file actions
81 lines (66 loc) · 1.93 KB
/
Copy pathhysteresis_pgm.cpp
File metadata and controls
81 lines (66 loc) · 1.93 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
#include <stdio.h>
#include "image_ppm.h"
/*
Première lecture de l’image de la norme des gradients : si norme du gradient <= SB alors 0, si
norme du gradient >= SH alors 255.
Deuxième lecture de l’image de la norme de gradients pré-seuillée avec SB et SH : si SB < norme
du gradient < SH ET qu’au moins 1 de ses voisins = 255 alors 255 sinon 0.
*/
int main(int argc, char* argv[])
{
char cNomImgLue[250], cNomImgEcrite[250];
int nH, nW, nTaille, SB, SH;
if (argc != 5)
{
printf("Usage: ImageIn.pgm ImageOut.pgm SH SB \n");
exit (1) ;
}
sscanf (argv[1],"%s",cNomImgLue) ;
sscanf (argv[2],"%s",cNomImgEcrite);
sscanf (argv[3],"%d",&SH);
sscanf (argv[4],"%d",&SB);
OCTET *ImgIn, *ImgOut1, *ImgOut2;
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(ImgOut1, OCTET, nTaille);
allocation_tableau(ImgOut2, OCTET, nTaille);
//premier lecture
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
if ( ImgIn[i*nW+j] <= SB)
ImgOut1[i*nW+j]=0;
else if (ImgIn[i*nW+j] >= SH)
ImgOut1[i*nW+j]=255;
else
ImgOut1[i*nW+j] = ImgIn[i*nW+j];
}
}
//deuxieme lecture
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
if (ImgOut1[i*nW+j] == 0 || ImgOut1[i*nW+j] == 255)
ImgOut2[i*nW+j] = ImgOut1[i*nW+j];
else{
bool voisin = false;
for (int k = -1; k < 2; ++k){
for (int t = -1; t < 2; ++t){
if (ImgOut2[(i+k)*nW + j+t] == 255)
voisin = true;
}
}
if (voisin)
ImgOut2[i*nW+j] = 255;
else
ImgOut2[i*nW+j] = 0;
}
}
}
ecrire_image_pgm(cNomImgEcrite, ImgOut2, nH, nW);
free(ImgIn); free(ImgOut1);
free(ImgOut2);
return 1;
}