-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherosion_rgb.cpp
More file actions
95 lines (74 loc) · 2.35 KB
/
Copy patherosion_rgb.cpp
File metadata and controls
95 lines (74 loc) · 2.35 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
#include <stdio.h>
#include "image_ppm.h"
/*
Pour faire l’erosion on parcours tout l’image par les couche rouge, vert et blue et on regarde ces 8 voisins puis s’il a un voisin blanc, on
transforme ce pixel centrale en blanc sinon on laisse noir. Comme ca on enlève le bruit d’image et il
devient plus facile à traiter.
*/
int main(int argc, char* argv[])
{
char cNomImgLue[250], cNomImgEcrite[250];
int nH, nW, nTaille;
if (argc != 3)
{
printf("Usage: ImageIn.ppm ImageOut.ppm \n");
exit (1) ;
}
sscanf (argv[1],"%s",cNomImgLue) ;
sscanf (argv[2],"%s",cNomImgEcrite);
OCTET *ImgIn, *ImgOut, *ImgInR, *ImgOutR, *ImgInG, *ImgOutG, *ImgInB, *ImgOutB;
lire_nb_lignes_colonnes_image_ppm(cNomImgLue, &nH, &nW);
nTaille = nH * nW;
int nTaille3 = nTaille * 3;
allocation_tableau(ImgIn, OCTET, nTaille3);
allocation_tableau(ImgInR, OCTET, nTaille);
allocation_tableau(ImgInG, OCTET, nTaille);
allocation_tableau(ImgInB, OCTET, nTaille);
lire_image_ppm(cNomImgLue, ImgIn, nH * nW);
allocation_tableau(ImgOutR, OCTET, nTaille);
allocation_tableau(ImgOutG, OCTET, nTaille);
allocation_tableau(ImgOutB, OCTET, nTaille);
allocation_tableau(ImgOut, OCTET, nTaille3);
//SEPARATION DES COLEURS
planR(ImgInR, ImgIn, nH * nW);
planV(ImgInG, ImgIn, nH * nW);
planB(ImgInB, ImgIn, nH * nW);
for (int i = 0; i < nTaille; ++i)
{
ImgOutR[i] = 0;
ImgOutG[i] = 0;
ImgOutB[i] = 0;
}
for (int i=0; i < nH; i++){
for (int j=0; j < nW; j++)
{
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 (ImgInR[indice] == 255) ImgOutR[i*nW+j] = 255;
if (ImgInG[indice] == 255) ImgOutG[i*nW+j] = 255;
if (ImgInB[indice] == 255) ImgOutB[i*nW+j] = 255;
}
}
}
}
}
//reconstruction de rgb
for (int i = 0; i < nTaille; ++i)
{
ImgOut[3*i] = ImgOutR[i];
ImgOut[3*i+1] = ImgOutG[i];
ImgOut[3*i+2] = ImgOutB[i];
}
ecrire_image_ppm(cNomImgEcrite, ImgOut, nH, nW);
free(ImgIn); free(ImgOut);
free(ImgOutR); free(ImgInR);
free(ImgInG); free(ImgOutG);
free(ImgInB); free(ImgOutB);
return 1;
}