-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdessinner_histogramme.c
More file actions
250 lines (217 loc) · 8.79 KB
/
Copy pathdessinner_histogramme.c
File metadata and controls
250 lines (217 loc) · 8.79 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//
// dessinner_histogramme.c
// projet7
//
// Created by remy DEME on 12/04/2016.
// Copyright © 2016 DEME Rémy. All rights reserved.
//
#include "histogramme.h"
/* cette fonction permet de calculer l'effectif pour chaque couleur */
void determination_effectif( unsigned char ** matrice , const infoBMP * infoEntete, int *tableau_effectif)
{
int i , j ;
for ( i = 0 ; i < infoEntete->hauteur ; i++ )
{
for ( j = 0 ; j < infoEntete->largeur ; j++ )
{
tableau_effectif[matrice[i][j]]+= 1 ;
// printf ( " valeur matrice :ici %d ", matrice[i][j]);
}
}
}
/* Cette fonction permet de calculer la fréquence */
void calcul_frequence (int *tableau_effectif , int *tableau_frequence, const infoBMP*infoEntete )
{
int i ;
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
tableau_frequence[i] = (tableau_effectif[i]/(infoEntete->hauteur*infoEntete->largeur));
}
}
/*creation des classe on somme l'ensemble de frequence de (beg à beg + largeur de classe ) */
void creation_classe ( int *tableau_classe , int * tableau_effectif)
{
int i ;
int j ;
int compteur = 0;
const unsigned int nombre_classe = sqrt((double)NBR_COULEUR);
//printf ( " nombre_classe : %d \n ", nombre_classe);
for ( i = 0 ; i < nombre_classe ; i++ )
{
for ( j = compteur ; j < compteur + nombre_classe ; j++ )
{
// printf ( " effectif%d %d \n",j,tableau_effectif[j]);
tableau_classe[i] += tableau_effectif[j] ;
}
compteur += nombre_classe ;
// printf ( "tableau : %d \n", tableau_classe[i]);
}
}
/* fonction qui réalise l'histogramme */
void dessiner_histogramme ( unsigned char **matrice , int *tableau_classe, const infoBMP*infoEntete )
{
int i ;
int max = determiner_max(tableau_classe);
const int nombre_classe = sqrt((double)NBR_COULEUR);
int compteur = 0 ;
for ( i = 0 ; i < nombre_classe ; i++ )
{
tracer_barre(pourcentage(tableau_classe[i], infoEntete,max), compteur, matrice);
compteur += nombre_classe ;
}
}
void tracer_barre ( const int hauteur , const int colonne , unsigned char ** matrice )
{
const int largeur_classe = 512/sqrt(NBR_COULEUR);
int i , j ;
for ( i = 0 ; i < hauteur ; i++ )
{
for ( j = colonne ; j < colonne + largeur_classe ; j++ )
{
matrice[i][j] = 0 ;
}
}
}
void tapis_blanc ( unsigned char ** matrice ,const infoBMP*infoEntete)
{
int i , j ;
for ( i = 0 ; i < infoEntete->hauteur ; i++ )
{
for ( j = 0 ; j < infoEntete->largeur ; j++ )
{
matrice[i][j]= 250 ;
}
}
}
/* Pourcentage retourne une valeur qui correspond à la lageur du trai tracé par la fonction tracer // on utilise max qui représente la vale*/
int pourcentage ( const int valeur , const infoBMP*infoEntete , const int max )
{
return ((float)( valeur*(infoEntete->hauteur-2))/(max));
}
void afficher_taff ( int * tab )
{
int i ;
for ( i = 0 ; i < 16 ; i++ )
{
printf ( " valeur : %d \n", tab[i] );
}
}
int determiner_max ( const int * tableau )
{
int max = tableau[0];
int i ;
for ( i = 0 ; i < NBR_COULEUR; i++ )
{
if ( tableau[i] > max )
{
max = tableau[i];
}
}
return max ;
}
// histogramme couleur //
void determination_effectif_IMC( pix ** matrice , const infoBMP * infoEntete,effec_pix * effectif )
{
int i , j ;
for ( i = 0 ; i < infoEntete->hauteur ; i++ )
{
for ( j = 0 ; j < infoEntete->largeur ; j++ )
{
effectif->effectif_b[matrice[i][j].b]++ ;
effectif->effectif_r[matrice[i][j].r]++ ;
effectif->effectif_v[matrice[i][j].v]++ ;
}
}
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
printf ( "\n effectif b - %d \n %d ",i,effectif->effectif_b[i]);
}
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
printf ( "\n effectif r - %d : \n %d ",i,effectif->effectif_r[i]);
}
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
printf ( "\n effectif v - %d : \n %d ",i,effectif->effectif_v[i]);
}
}
/*void determination_frequence_IMC( const infoBMP * infoEntete, const effec_pix * const effectif , frequence_pix * const frequence)
{
int i ;
long nombre_pixel = infoEntete->hauteur*infoEntete->largeur ;
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
frequence->frequence_b[i] = (float)effectif->effectif_b[i]/(nombre_pixel);
frequence->frequence_r[i] = (float)effectif->effectif_r[i] /nombre_pixel;
frequence->frequence_v[i] = (float)effectif->effectif_v[i]/nombre_pixel ;
}
}*/
void tapis_blanc_IMC ( pix ** matrice ,const infoBMP*infoEntete)
{
int i , j ;
for ( i = 0 ; i < infoEntete->hauteur ; i++ )
{
for ( j = 0 ; j < infoEntete->largeur ; j++ )
{
matrice[i][j].r= 0 ;
matrice[i][j].v=0;
matrice[i][j].b = 0 ;
}
}
}
void tracer_barre_IMC_R ( const int hauteur , const int colonne , pix ** matrice )
{
const int largeur_classe = 1 ;
int i , j ;
for ( i = 0 ; i < hauteur ; i++ )
{
for ( j = colonne ; j < colonne + largeur_classe ; j++ )
{
matrice[i][j].r = 250;
}
}
}
void tracer_barre_IMC_V ( const int hauteur , const int colonne , pix ** matrice )
{
const int largeur_classe = 1 ;
int i , j ;
for ( i = 0 ; i < hauteur ; i++ )
{
for ( j = colonne ; j < colonne + largeur_classe ; j++ )
{
matrice[i][j].v = 250;
}
}
}
void tracer_barre_IMC_B ( const int hauteur , const int colonne , pix ** matrice )
{
const int largeur_classe = 1 ;
int i , j ;
for ( i = 0 ; i < hauteur ; i++ )
{
for ( j = colonne ; j < colonne + largeur_classe ; j++ )
{
matrice[i][j].b = 250;
}
}
}
int pourcentage_IMC ( const int valeur , const infoBMP*infoEntete , const int max )
{
return (( valeur*(infoEntete->hauteur-2))/(max));
}
void dessiner_histogramme_IMC ( pix**matrice , const infoBMP*infoEntete, effec_pix * effectif )
{
int i ;
int max_r = determiner_max(effectif->effectif_r); // détermine l'effectif le plus important pour la fonction pourcentage
int max_b = determiner_max(effectif->effectif_b);
int max_v = determiner_max(effectif->effectif_v);
const int nombre_classe = 1 ;
int compteur = 0 ;
for ( i = 0 ; i < NBR_COULEUR ; i++ )
{
tracer_barre_IMC_R(pourcentage(effectif->effectif_r[i], infoEntete,max_r), compteur, matrice);
tracer_barre_IMC_V(pourcentage(effectif->effectif_v[i], infoEntete,max_v), compteur, matrice);
tracer_barre_IMC_B(pourcentage(effectif->effectif_b[i], infoEntete,max_b), compteur, matrice);
compteur += nombre_classe ;
}
}