1 | /* -------------------------------- */ |
---|
2 | /* --- ecc_main_rosenfeld_sa.c ---- */ |
---|
3 | /* -------------------------------- */ |
---|
4 | |
---|
5 | // main pour rosenfeld standalone |
---|
6 | // version 2014 - 2016 |
---|
7 | |
---|
8 | #include <stdio.h> |
---|
9 | #include <stdlib.h> |
---|
10 | #include <math.h> |
---|
11 | |
---|
12 | #ifdef CLI |
---|
13 | #include "nrc_os_config.h" |
---|
14 | #include "nrc.h" |
---|
15 | #endif |
---|
16 | |
---|
17 | // fichiers generalistes |
---|
18 | #include "palette.h" |
---|
19 | #include "bmpNR.h" |
---|
20 | #include "histogramNR.h" |
---|
21 | |
---|
22 | // fichiers communs pour ecc |
---|
23 | #include "ecc_common.h" |
---|
24 | #include "ecc_features.h" |
---|
25 | #include "ecc_examples.h" |
---|
26 | #include "ecc_generation.h" |
---|
27 | |
---|
28 | // algorithme d'ecc |
---|
29 | #include "ecc_rosenfeld.h" |
---|
30 | |
---|
31 | // -------------------- |
---|
32 | void ecc_info_omp(void) |
---|
33 | // -------------------- |
---|
34 | { |
---|
35 | #ifdef OPENMP |
---|
36 | printf("OPENMP is ON"); |
---|
37 | #else |
---|
38 | printf("OPENMP is OFF"); |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifdef OPENMP2 |
---|
42 | printf("OPENMP2 is ON"); |
---|
43 | #else |
---|
44 | printf("OPENMP2 is OFF"); |
---|
45 | #endif |
---|
46 | |
---|
47 | #ifdef OPENMP4 |
---|
48 | printf("OPENMP4 is ON"); |
---|
49 | #else |
---|
50 | printf("OPENMP4 is OFF"); |
---|
51 | #endif |
---|
52 | } |
---|
53 | // -------------------------------------- |
---|
54 | void main_rosenfeld_forme(char *dst_path) |
---|
55 | // -------------------------------------- |
---|
56 | { |
---|
57 | char *filename; |
---|
58 | |
---|
59 | uint8 **X0, **X; |
---|
60 | uint8 **E8; |
---|
61 | |
---|
62 | uint32 **E32; |
---|
63 | uint32 *S; // Stack for Bailey algorithm |
---|
64 | |
---|
65 | uint32 *T; |
---|
66 | uint32 *A; |
---|
67 | uint32 *N; |
---|
68 | //uint32 *SNE; // memorisation de la somme des ne: sne |
---|
69 | |
---|
70 | int i0, i1, j0, j1; |
---|
71 | int height, width, border = 1; |
---|
72 | uint32 nermax, nemax; |
---|
73 | int na; |
---|
74 | |
---|
75 | RegionStats *Stats; |
---|
76 | |
---|
77 | RGBQuad palette[256]; |
---|
78 | char complete_filename[1024]; |
---|
79 | |
---|
80 | |
---|
81 | printf("[----------------------------]"); |
---|
82 | printf("[--- main_rosenfeld_forme ---]"); |
---|
83 | printf("[----------------------------]"); |
---|
84 | |
---|
85 | Palette_18ColorsBW(palette); |
---|
86 | |
---|
87 | // fonction d'init choisir dans ecc_examples.c |
---|
88 | // init et allocation de X0 |
---|
89 | //init_forme_backdoor1b(&X0, &i0, &i1, &j0, &j1); |
---|
90 | //init_forme_backdoor2b(&X0, &i0, &i1, &j0, &j1); |
---|
91 | //init_forme_backdoor3b(&X0, &i0, &i1, &j0, &j1); |
---|
92 | init_forme_boulon1(&X0, &i0, &i1, &j0, &j1); |
---|
93 | |
---|
94 | // allocation memoire |
---|
95 | X = ui8matrix (i0-border, i1+border, j0-border, j1+border); |
---|
96 | E8 = ui8matrix (i0-border, i1+border, j0-border, j1+border); |
---|
97 | E32 = ui32matrix(i0-border, i1+border, j0-border, j1+border); |
---|
98 | |
---|
99 | // initialisation de la memoire |
---|
100 | zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
101 | zero_ui8matrix (E8, i0-border, i1+border, j0-border, j1+border); |
---|
102 | zero_ui8matrix (X, i0-border, i1+border, j0-border, j1+border); |
---|
103 | |
---|
104 | // pre-traitements |
---|
105 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 1, 1, X); // pour le traitement |
---|
106 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 1, 255, X0); // pour la verif visuelle |
---|
107 | generate_path_filename(dst_path, "verif.pgm", complete_filename, 1024); |
---|
108 | SavePGM_ui8matrix(X0, i0, i1, j0, j1, complete_filename); |
---|
109 | display_ui8matrix_positive(X, i0, i1, j0, j1, 3, "X"); |
---|
110 | |
---|
111 | height = i1 - i0 + 1; |
---|
112 | width = j1 - j0 + 1; |
---|
113 | |
---|
114 | nemax = ((height + 1) * (width + 1)) / 2; // majorant strict |
---|
115 | nermax = (width + 1) / 2; |
---|
116 | |
---|
117 | // alloc init des tables d'equivalences pour UF, Suzuki et Bailey |
---|
118 | T = ui32vector(0, nemax); |
---|
119 | A = ui32vector(0, nemax); |
---|
120 | N = ui32vector(0, nemax); |
---|
121 | |
---|
122 | S = ui32vector(0, 2*nermax); |
---|
123 | |
---|
124 | initT(T, nemax); |
---|
125 | initT(A, nemax); |
---|
126 | initZ(N, nemax); |
---|
127 | |
---|
128 | Stats = RegionStatsVector(0, nemax); |
---|
129 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
130 | |
---|
131 | // traitement: desactiver FlattenL dans Rosenfeld |
---|
132 | // pour voir l'image d'etiquettes sans re-etiquetage |
---|
133 | na = Rosenfeld_UF_Org1_4C(X, height, width, E32, T, A, nemax, Stats); ECC_VERBOSE(printf("na = %d\n", na)); filename = "Rosenfeld_UF_Org1_4C.bmp"; mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); generate_path_filename(dst_path, filename, complete_filename, 1024); SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); display_ui32matrix_positive(E32,i0, i1, j0, j1, 3, "E1"); zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); display_RegionStatsVector(Stats, 1, na, "Stats"); zero_RegionStatsVector(Stats, 0, nemax); |
---|
134 | |
---|
135 | |
---|
136 | na = Rosenfeld_UF_Org1_8C(X, height, width, E32, T, A, nemax, Stats); ECC_VERBOSE(printf("na = %d\n", na)); filename = "Rosenfeld_UF_Org1_8C.bmp"; mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); generate_path_filename(dst_path, filename, complete_filename, 1024); SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); display_ui32matrix_positive(E32,i0, i1, j0, j1, 3, "E1"); zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); display_RegionStatsVector(Stats, 1, na, "Stats"); zero_RegionStatsVector(Stats, 0, nemax); |
---|
137 | |
---|
138 | |
---|
139 | na = Rosenfeld_UF_Org2_4C(X, height, width, E32, T, A, nemax, Stats); ECC_VERBOSE(printf("na = %d\n", na)); filename = "Rosenfeld_UF_Org2_4C.bmp"; mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); generate_path_filename(dst_path, filename, complete_filename, 1024); SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); display_ui32matrix_positive(E32,i0, i1, j0, j1, 3, "E1"); zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); display_RegionStatsVector(Stats, 1, na, "Stats"); zero_RegionStatsVector(Stats, 0, nemax); |
---|
140 | |
---|
141 | // free |
---|
142 | free_ui8matrix (X0, i0, i1, j0, j1); |
---|
143 | free_ui8matrix (X, i0-border, i1+border, j0-border, j1+border); |
---|
144 | free_ui8matrix (E8, i0-border, i1+border, j0-border, j1+border); |
---|
145 | free_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
146 | |
---|
147 | free_ui32vector(T, 0, nemax); |
---|
148 | free_ui32vector(A, 0, nemax); |
---|
149 | free_ui32vector(N, 0, nemax); |
---|
150 | |
---|
151 | free_ui32vector(S, 0, 2*nermax); |
---|
152 | |
---|
153 | free_RegionStatsVector(Stats, 0, nemax); |
---|
154 | |
---|
155 | return; |
---|
156 | } |
---|
157 | // --------------------------------------------------------------------- |
---|
158 | void main_rosenfeld_file(char *src_path, char *filename, char *dst_path) |
---|
159 | // --------------------------------------------------------------------- |
---|
160 | { |
---|
161 | printf("[---------------------------]"); |
---|
162 | printf("[--- main_rosenfeld_file ---]"); |
---|
163 | printf("[---------------------------]"); |
---|
164 | |
---|
165 | char *pathSrc = src_path; |
---|
166 | char *pathDst = dst_path; |
---|
167 | |
---|
168 | uint8 **X0, **X; |
---|
169 | uint8 **E8; |
---|
170 | |
---|
171 | uint32 **E32; |
---|
172 | uint32 *S; // Stack for Bailey algorithm |
---|
173 | |
---|
174 | uint32 *T; |
---|
175 | uint32 *A; |
---|
176 | uint32 *N; |
---|
177 | //uint32 *SNE; // memorisation de la somme des ne: sne |
---|
178 | |
---|
179 | int i0, i1, j0, j1; |
---|
180 | int height, width, border=1; |
---|
181 | uint32 nemax, nermax; |
---|
182 | int na; |
---|
183 | |
---|
184 | RegionStats * Stats = NULL; |
---|
185 | |
---|
186 | RGBQuad palette[256]; |
---|
187 | char complete_filename[1024]; |
---|
188 | |
---|
189 | Palette_18ColorsBW(palette); |
---|
190 | generate_path_filename(pathSrc, filename, complete_filename, 1024); |
---|
191 | |
---|
192 | // chargement d'une image depuis le disque |
---|
193 | //X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); |
---|
194 | init_forme_boulon1(&X0, &i0, &i1, &j0, &j1); |
---|
195 | |
---|
196 | // allocation memoire |
---|
197 | X = ui8matrix (i0 - border, i1 + border, j0 - border, j1 + border); |
---|
198 | E8 = ui8matrix (i0 - border, i1 + border, j0 - border, j1 + border); |
---|
199 | E32 = ui32matrix(i0 - border, i1 + border, j0 - border, j1 + border); |
---|
200 | |
---|
201 | // initialisation de la memoire |
---|
202 | zero_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
203 | zero_ui8matrix (E8, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
204 | zero_ui8matrix (X, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
205 | |
---|
206 | // pre-traitements |
---|
207 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 1, X); // pour le traitement |
---|
208 | //binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 255, X0); // pour la verif visuelle |
---|
209 | //generate_path_filename(pathDst, "verif.pgm", complete_filename, 1024); |
---|
210 | //SavePGM_ui8matrix(X0, i0, i1, j0, j1, complete_filename); |
---|
211 | |
---|
212 | height = i1 - i0 + 1; |
---|
213 | width = j1 - j0 + 1; |
---|
214 | |
---|
215 | nemax = ((height + 1) * (width + 1)) / 2; // majorant strict |
---|
216 | nermax = (width + 1) / 2; |
---|
217 | |
---|
218 | // alloc init des tables d'equivalences pour UF, Suzuki et Bailey |
---|
219 | T = ui32vector(0, nemax); |
---|
220 | A = ui32vector(0, nemax); |
---|
221 | N = ui32vector(0, nemax); |
---|
222 | |
---|
223 | S = ui32vector(0, 2 * nermax); |
---|
224 | |
---|
225 | initT(T, nemax); |
---|
226 | initT(A, nemax); |
---|
227 | initZ(N, nemax); |
---|
228 | |
---|
229 | Stats = RegionStatsVector(0, nemax); |
---|
230 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
231 | |
---|
232 | // traitement: desactiver FlattenL dans Rosenfeld |
---|
233 | // pour voir l'image d'etiquettes sans re-etiquetage |
---|
234 | /*na = Rosenfeld_UF_Org1_4C (X, height, width, E32, T, A, nemax, Stats); ECC_VERBOSE(printf("na = %d\n", na)); filename = "Rosenfeld_UF_Org1_4C.bmp"; mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); generate_path_filename(pathDst, filename, complete_filename); SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); display_RegionStatsVector(Stats, 1, na, "Stats"); zero_RegionStatsVector(Stats, 0, nemax);*/ |
---|
235 | |
---|
236 | na = Rosenfeld_UF_Org1_8C(X, height, width, E32, T, A, nemax, Stats); |
---|
237 | printf("na = %d\n", na); |
---|
238 | //filename = "Rosenfeld_UF_Org1_8C.bmp"; |
---|
239 | mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); |
---|
240 | //generate_path_filename(pathDst, filename, complete_filename, 1024); |
---|
241 | //SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); |
---|
242 | zero_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
243 | display_RegionStatsVector(Stats, 1, na, "Stats"); |
---|
244 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
245 | |
---|
246 | /*na = Rosenfeld_UF_Org2_4C (X, height, width, E32, T, A, nemax, Stats); ECC_VERBOSE(printf("na = %d\n", na)); filename = "Rosenfeld_UF_Org2_4C.bmp"; mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); generate_path_filename(pathDst, filename, complete_filename); SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); display_RegionStatsVector(Stats, 1, na, "Stats"); zero_RegionStatsVector(Stats, 0, nemax);*/ |
---|
247 | |
---|
248 | free_ui8matrix (X0, i0, i1, j0, j1); |
---|
249 | free_ui8matrix (X, i0-border, i1+border, j0-border, j1+border); |
---|
250 | free_ui8matrix (E8, i0-border, i1+border, j0-border, j1+border); |
---|
251 | free_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
252 | |
---|
253 | free_ui32vector(T, 0, nemax); |
---|
254 | free_ui32vector(A, 0, nemax); |
---|
255 | free_ui32vector(N, 0, nemax); |
---|
256 | |
---|
257 | free_ui32vector(S, 0, 2*nermax); |
---|
258 | |
---|
259 | return; |
---|
260 | } |
---|
261 | // --------------------------------------- |
---|
262 | int main_rosenfeld(int argc, char* argv[]) |
---|
263 | // --------------------------------------- |
---|
264 | { |
---|
265 | char *src_path; |
---|
266 | char *filename; |
---|
267 | char *dst_path; |
---|
268 | |
---|
269 | printf("[======================]"); |
---|
270 | printf("[=== main_rosenfeld ===]"); |
---|
271 | printf("[======================]"); |
---|
272 | |
---|
273 | src_path = "./"; // ne pas oublier le / a la fin |
---|
274 | dst_path = ""; |
---|
275 | |
---|
276 | filename = "boulons.pgm"; |
---|
277 | |
---|
278 | //main_rosenfeld_forme(dst_path); |
---|
279 | main_rosenfeld_file(src_path, filename, dst_path); |
---|
280 | |
---|
281 | return 0; |
---|
282 | } |
---|
283 | // ------------------------------------- |
---|
284 | void display_arg(int argc, char* argv[]) |
---|
285 | // ------------------------------------- |
---|
286 | { |
---|
287 | int i; |
---|
288 | |
---|
289 | printf("================="); |
---|
290 | printf("== display_arg =="); |
---|
291 | printf("================="); |
---|
292 | printf(""); |
---|
293 | |
---|
294 | printf("argc = %d\n", argc); |
---|
295 | |
---|
296 | for (i = 0; i < argc; i++) { |
---|
297 | printf("%s ", argv[i]); |
---|
298 | } |
---|
299 | printf(""); |
---|
300 | } |
---|
301 | // ----------------------- |
---|
302 | void ecc_info_define(void) |
---|
303 | // ----------------------- |
---|
304 | { |
---|
305 | printf("====================="); |
---|
306 | printf("== ecc_info_define =="); |
---|
307 | printf("====================="); |
---|
308 | printf(""); |
---|
309 | ecc_info_omp(); |
---|
310 | //Label_Display_Info(); |
---|
311 | printf(""); |
---|
312 | } |
---|
313 | // ----------------------------- |
---|
314 | int main(int argc, char* argv[]) |
---|
315 | // ----------------------------- |
---|
316 | { |
---|
317 | #if TARGET_OS==GIET_VM |
---|
318 | giet_tty_alloc(1); |
---|
319 | #endif |
---|
320 | display_arg(argc, argv); |
---|
321 | ecc_info_define(); |
---|
322 | main_rosenfeld(argc, argv); |
---|
323 | printf("[main]: bye"); |
---|
324 | return 0; |
---|
325 | } |
---|