1 | /* ----------------------- */ |
---|
2 | /* --- ecc_rosenfeld.c --- */ |
---|
3 | /* ----------------------- */ |
---|
4 | |
---|
5 | // Copyright (c) 2013-2014 Lionel Lacassagne, All Rights Reserved |
---|
6 | // Laboratoire de Recherche en Informatique |
---|
7 | // Universite Paris-Sud / CNRS |
---|
8 | |
---|
9 | /* -- Contient les implementations avancees de l'algorithme de Rosenfeld -- */ |
---|
10 | #include <stdio.h> |
---|
11 | #include <stdlib.h> |
---|
12 | #include <math.h> |
---|
13 | |
---|
14 | #ifdef CLI |
---|
15 | #include "nrc_os_config.h" |
---|
16 | #include "nrc.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "util.h" |
---|
20 | #include "ecc_common.h" |
---|
21 | #include "ecc_features.h" |
---|
22 | |
---|
23 | #include "ecc_rosenfeld.h" |
---|
24 | |
---|
25 | // --------------------------------- |
---|
26 | uint32 FindRoot(uint32 *T, uint32 e) |
---|
27 | // --------------------------------- |
---|
28 | { |
---|
29 | uint32 r; |
---|
30 | r = e; |
---|
31 | while (T[r] < r) { |
---|
32 | r = T[r]; |
---|
33 | } |
---|
34 | return r; |
---|
35 | } |
---|
36 | // -------------------------------------------------------------- |
---|
37 | uint32 FindRoot_Features(uint32 *T, uint32 e, RegionStats *Stats) |
---|
38 | // -------------------------------------------------------------- |
---|
39 | { |
---|
40 | // ne sert pas, sauf a creer des backdoors |
---|
41 | uint32 r; |
---|
42 | r = FindRoot(T,e); |
---|
43 | RegionStats_Accumulate_Stats1_From_Index(Stats, r, e); |
---|
44 | return r; |
---|
45 | } |
---|
46 | // ---------------------------------------- |
---|
47 | void SetRoot(uint32 *T, uint32 e, uint32 r) |
---|
48 | // ---------------------------------------- |
---|
49 | { |
---|
50 | while (T[e] < e) { |
---|
51 | e = T[e]; |
---|
52 | } |
---|
53 | T[e] = r; |
---|
54 | } |
---|
55 | // ----------------------------- |
---|
56 | uint32 Find(uint32 *T, uint32 e) |
---|
57 | // ----------------------------- |
---|
58 | { |
---|
59 | // never used in Rosenfeld ? |
---|
60 | uint32 r; |
---|
61 | r = FindRoot(T, e); |
---|
62 | SetRoot(T, e, r); |
---|
63 | return r; |
---|
64 | } |
---|
65 | // ------------------------------------------- |
---|
66 | uint32 Union0(uint32 *T, uint32 ei, uint32 ej) |
---|
67 | // ------------------------------------------- |
---|
68 | { |
---|
69 | // version de la publication |
---|
70 | uint32 ri, rj; |
---|
71 | ri = FindRoot(T, ei); |
---|
72 | if (ei!=ej) { |
---|
73 | rj = FindRoot(T, ej); |
---|
74 | if (ri > rj) { |
---|
75 | ri = rj; |
---|
76 | } |
---|
77 | SetRoot(T, ej, ri); |
---|
78 | } |
---|
79 | SetRoot(T, ei, ri); |
---|
80 | return ri; |
---|
81 | } |
---|
82 | // ----------------------------------------- |
---|
83 | uint32 Union1(uint32 *T, uint32 i, uint32 j) |
---|
84 | // ----------------------------------------- |
---|
85 | { |
---|
86 | // version modifiee Lionel Lacassagne |
---|
87 | uint32 r, ri, rj; |
---|
88 | uint32 k; |
---|
89 | ri = FindRoot(T, i); |
---|
90 | rj = FindRoot(T, j); |
---|
91 | if (ri != rj) { |
---|
92 | r = ri < rj ? ri : rj; |
---|
93 | SetRoot(T, i, r); |
---|
94 | SetRoot(T, j, r); |
---|
95 | } |
---|
96 | else { |
---|
97 | r = ri; |
---|
98 | k = i > j ? i : j; |
---|
99 | SetRoot(T, k, r); |
---|
100 | } |
---|
101 | return ri; |
---|
102 | } |
---|
103 | // ------------------------------------------- |
---|
104 | uint32 Union2(uint32 *T, uint32 ei, uint32 ej) |
---|
105 | // ------------------------------------------- |
---|
106 | { |
---|
107 | return Union0(T, ei, ej); // original |
---|
108 | //return Union1(T, ei, ej); // Lionel Lacassagne |
---|
109 | } |
---|
110 | /* -------------------------------------------------------------- */ |
---|
111 | uint32 Union4(uint32 *T, uint32 e1, uint32 e2, uint32 e3, uint32 e4) |
---|
112 | /* -------------------------------------------------------------- */ |
---|
113 | { |
---|
114 | uint32 r12, r34; |
---|
115 | r12 = Union2(T, e1, e2); |
---|
116 | r34 = Union2(T, e3, e4); |
---|
117 | return Union2(T, r12, r34); |
---|
118 | } |
---|
119 | // --------------------------------------------------------------- |
---|
120 | uint32 updateTable_Rosenfeld(uint32 *T, uint32 e, uint32 epsillon) |
---|
121 | // --------------------------------------------------------------- |
---|
122 | { |
---|
123 | // notations e == v, epsillon == u avec v>u (v forcement different de u) |
---|
124 | return Union0(T, e, epsillon); // original |
---|
125 | } |
---|
126 | // -------------------------------------------------------------------------------------------- |
---|
127 | uint32 updateTable_Features_Rosenfeld(uint32 *T, uint32 e, uint32 epsillon, RegionStats *Stats) |
---|
128 | // -------------------------------------------------------------------------------------------- |
---|
129 | { |
---|
130 | uint32 r; // racine totale = epsillon |
---|
131 | uint32 re; // racine de e > r |
---|
132 | |
---|
133 | re = FindRoot(T, e); // backdoor: sans cela Accumulate est faux |
---|
134 | |
---|
135 | r = updateTable_Rosenfeld(T, e, epsillon); |
---|
136 | RegionStats_Accumulate_Stats1_From_Index(Stats, epsillon, re); |
---|
137 | return r; |
---|
138 | } |
---|
139 | // ---------------------------- |
---|
140 | void Flatten(uint32 *T, int ne) |
---|
141 | // ---------------------------- |
---|
142 | { |
---|
143 | // equivalent a solveTable_Rosenfeld |
---|
144 | // fermeture transitive sans pack |
---|
145 | // (presence de trous dans les numeros d'etiquettes) |
---|
146 | |
---|
147 | int32 i, k; |
---|
148 | k = 1; |
---|
149 | for (i = 1; i <= ne; i++) { |
---|
150 | T[i] = T[T[i]]; |
---|
151 | } |
---|
152 | } |
---|
153 | // ---------------------------- |
---|
154 | int FlattenL(uint32 *T, int ne) |
---|
155 | // ---------------------------- |
---|
156 | { |
---|
157 | // equivalent a solvePackTable_Rosenfeld |
---|
158 | // fermeture transitive *avec* pack |
---|
159 | // (pas de trous dans les numeros d'etiquettes) |
---|
160 | |
---|
161 | int32 i, k; |
---|
162 | k = 1; |
---|
163 | |
---|
164 | for (i = 1; i <= ne; i++) { |
---|
165 | if ((int) T[i] < i) { |
---|
166 | T[i] = T[T[i]]; |
---|
167 | } |
---|
168 | else { |
---|
169 | T[i] = k; |
---|
170 | k++; |
---|
171 | } |
---|
172 | } |
---|
173 | return k - 1; |
---|
174 | } |
---|
175 | // ---------------------------------------------- |
---|
176 | uint32 solveTable_Rosenfeld(uint32 *T, uint32 ne) |
---|
177 | // ---------------------------------------------- |
---|
178 | { |
---|
179 | // equivalent a Flatten |
---|
180 | // fermeture transitive sans pack |
---|
181 | // (presence de trous dans les numeros d'etiquettes) |
---|
182 | |
---|
183 | uint32 e; |
---|
184 | |
---|
185 | for (e = 1; e <= ne; e++) { |
---|
186 | T[e] = T[T[e]]; |
---|
187 | } |
---|
188 | return ne; |
---|
189 | } |
---|
190 | // -------------------------------------------------- |
---|
191 | uint32 solvePackTable_Rosenfeld(uint32 *T, uint32 ne) |
---|
192 | // -------------------------------------------------- |
---|
193 | { |
---|
194 | // equivalent a FlattenL |
---|
195 | // fermeture transitive *avec* pack |
---|
196 | // (pas de trous dans les numeros d'etiquettes) |
---|
197 | |
---|
198 | uint32 e; |
---|
199 | uint32 na = 0; // ancetre packe |
---|
200 | |
---|
201 | for (e = 1; e <= ne; e++) { |
---|
202 | if (e != T[e]) { |
---|
203 | T[e] = T[T[e]]; |
---|
204 | } |
---|
205 | else { |
---|
206 | T[e] = ++na; |
---|
207 | } |
---|
208 | } |
---|
209 | return na; |
---|
210 | } |
---|
211 | // --------------------------------------------------------------------------- |
---|
212 | uint32 solveTable_Features_Rosenfeld(uint32 *T, uint32 ne, RegionStats *Stats) |
---|
213 | // --------------------------------------------------------------------------- |
---|
214 | { |
---|
215 | // fermeture transitive *sans* pack |
---|
216 | // (presence de trous dans les numeros d'etiquettes) |
---|
217 | // Calculs des Features pour la composante |
---|
218 | |
---|
219 | uint32 e, r; |
---|
220 | |
---|
221 | for (e = 1; e <= ne; e++) { |
---|
222 | r = T[T[e]]; |
---|
223 | |
---|
224 | if (r < e) { |
---|
225 | T[e] = r; |
---|
226 | RegionStats_Accumulate_Stats1_From_Index(Stats, r, e); |
---|
227 | } |
---|
228 | } |
---|
229 | return ne; |
---|
230 | } |
---|
231 | // ------------------------------------------------------------------------------- |
---|
232 | uint32 solvePackTable_Features_Rosenfeld(uint32 *T, uint32 ne, RegionStats *Stats) |
---|
233 | // ------------------------------------------------------------------------------- |
---|
234 | { |
---|
235 | // fermeture transitive *avec* pack |
---|
236 | // Calculs des Features pour la composante |
---|
237 | |
---|
238 | uint32 e, r; |
---|
239 | uint32 na = 0; |
---|
240 | |
---|
241 | for (e = 1; e <= ne; e++) { |
---|
242 | r = T[T[e]]; |
---|
243 | |
---|
244 | if (r < e) { |
---|
245 | T[e] = r; |
---|
246 | RegionStats_Accumulate_Stats1_From_Index(Stats, r, e); |
---|
247 | } |
---|
248 | else { |
---|
249 | // r == e <=> ancetre |
---|
250 | na++; |
---|
251 | T[r] = na; |
---|
252 | RegionStats_Copy_Stats1_From_Index(Stats, na, r); |
---|
253 | } |
---|
254 | } |
---|
255 | return na; |
---|
256 | } |
---|
257 | |
---|
258 | // ============================================ |
---|
259 | // == line-labeling (lineLabeling_*) ========== |
---|
260 | // ============================================ |
---|
261 | |
---|
262 | // ------------------------------------------------------------------------------------------------------------------ |
---|
263 | uint32 lineLabeling_Rosenfeld_UF_Org1_4C(uint8 **X, int i, int width, uint32 **E, uint32 *T, uint32 ne, uint32 nemax) |
---|
264 | // ------------------------------------------------------------------------------------------------------------------ |
---|
265 | { |
---|
266 | int j; |
---|
267 | uint8 x; |
---|
268 | uint32 e; |
---|
269 | uint32 e2,e4; |
---|
270 | uint32 r2,r4; |
---|
271 | |
---|
272 | // version de WU avec union find |
---|
273 | // correct: on remonte a la racine |
---|
274 | |
---|
275 | for (j = 0; j < width; j++) { |
---|
276 | |
---|
277 | x = X[i][j]; |
---|
278 | |
---|
279 | if (x) { |
---|
280 | |
---|
281 | e2 = E[i - 1][j]; |
---|
282 | e4 = E[i][j - 1]; |
---|
283 | |
---|
284 | // nouvel element |
---|
285 | if ((e2 == 0) && (e4 == 0)) { |
---|
286 | e = ++ne; |
---|
287 | E[i][j] = e; |
---|
288 | } else { |
---|
289 | |
---|
290 | // etiquettes identiques |
---|
291 | if (e2 == e4) { |
---|
292 | e = e2; |
---|
293 | E[i][j] = e; |
---|
294 | } |
---|
295 | else { |
---|
296 | |
---|
297 | // cas general |
---|
298 | r2 = FindRoot(T, e2); |
---|
299 | r4 = FindRoot(T, e4); |
---|
300 | |
---|
301 | e = ui32MinNonNul2(r2, r4); |
---|
302 | |
---|
303 | ECC_DEBUG(printf("%d->%d %d->%d min = %d\n", e2, r2, e4, r4, e)); |
---|
304 | |
---|
305 | if ((e2) && (e2 != e)) SetRoot(T, e2, e); |
---|
306 | if ((e4) && (e4 != e)) SetRoot(T, e4, e); |
---|
307 | |
---|
308 | E[i][j] = e; |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | else { |
---|
313 | E[i][j] = 0; |
---|
314 | } // x |
---|
315 | } // j |
---|
316 | return ne; |
---|
317 | } |
---|
318 | // ------------------------------------------------------------------------------------------------------------------ |
---|
319 | uint32 lineLabeling_Rosenfeld_UF_Org1_8C(uint8 **X, int i, int width, uint32 **E, uint32 *T, uint32 ne, uint32 nemax) |
---|
320 | // ------------------------------------------------------------------------------------------------------------------ |
---|
321 | { |
---|
322 | int j; |
---|
323 | |
---|
324 | uint8 x; |
---|
325 | uint32 e; |
---|
326 | uint32 e1, e2, e3, e4; |
---|
327 | uint32 r1, r2, r3, r4; |
---|
328 | |
---|
329 | for (j = 0; j < width; j++) { |
---|
330 | |
---|
331 | x = X[i][j]; |
---|
332 | |
---|
333 | if (x) { |
---|
334 | |
---|
335 | e1 = E[i-1][j-1]; |
---|
336 | e2 = E[i-1][j ]; |
---|
337 | e3 = E[i-1][j+1]; |
---|
338 | e4 = E[i ][j-1]; |
---|
339 | |
---|
340 | // nouvel element |
---|
341 | if ((e1==0) && (e2==0) && (e3==0) && (e4==0)) { |
---|
342 | e = ++ne; |
---|
343 | E[i][j] = e; |
---|
344 | |
---|
345 | } else { |
---|
346 | |
---|
347 | // etiquettes identiques |
---|
348 | if((e1 == e2) && (e1 == e3) && (e1 == e4)) { |
---|
349 | e = e1; |
---|
350 | E[i][j] = e; |
---|
351 | |
---|
352 | } else { |
---|
353 | |
---|
354 | // cas general |
---|
355 | r1 = FindRoot(T, e1); |
---|
356 | r2 = FindRoot(T, e2); |
---|
357 | r3 = FindRoot(T, e3); |
---|
358 | r4 = FindRoot(T, e4); |
---|
359 | |
---|
360 | e = ui32MinNonNul4(r1, r2, r3, r4); |
---|
361 | |
---|
362 | // modification 2014: |
---|
363 | // ek est remplacé par rk = Quick-Union |
---|
364 | //if((r1) && (r1 != e)) SetRoot(T, r1, e); |
---|
365 | //if((r2) && (r2 != e)) SetRoot(T, r2, e); |
---|
366 | //if((r3) && (r3 != e)) SetRoot(T, r3, e); |
---|
367 | //if((r4) && (r4 != e)) SetRoot(T, r4, e); |
---|
368 | |
---|
369 | // modification 2015: |
---|
370 | // rk remplace par ek, comme dans l'algorithme original |
---|
371 | if((r1) && (r1 != e)) SetRoot(T, e1, e); |
---|
372 | if((r2) && (r2 != e)) SetRoot(T, e2, e); |
---|
373 | if((r3) && (r3 != e)) SetRoot(T, e3, e); |
---|
374 | if((r4) && (r4 != e)) SetRoot(T, e4, e); |
---|
375 | |
---|
376 | E[i][j] = e; |
---|
377 | |
---|
378 | } |
---|
379 | } |
---|
380 | } else { |
---|
381 | E[i][j] = 0; |
---|
382 | } // x |
---|
383 | } // j |
---|
384 | return ne; |
---|
385 | } |
---|
386 | // ------------------------------------------------------------------------------------------------------------------ |
---|
387 | uint32 lineLabeling_Rosenfeld_UF_Org2_4C(uint8 **X, int i, int width, uint32 **E, uint32 *T, uint32 ne, uint32 nemax) |
---|
388 | // ------------------------------------------------------------------------------------------------------------------ |
---|
389 | { |
---|
390 | int j; |
---|
391 | |
---|
392 | uint8 x; |
---|
393 | uint32 e; |
---|
394 | uint32 e2, e4; |
---|
395 | uint32 r2, r4; |
---|
396 | |
---|
397 | for(j=0; j<width; j++) { |
---|
398 | |
---|
399 | x = X[i][j]; |
---|
400 | |
---|
401 | if(x) { |
---|
402 | |
---|
403 | e2 = E[i-1][j ]; |
---|
404 | e4 = E[i ][j-1]; |
---|
405 | |
---|
406 | // nouvel element |
---|
407 | if( (e2==0) && (e4==0) ) { |
---|
408 | e = ++ne; |
---|
409 | E[i][j] = e; |
---|
410 | } else { |
---|
411 | |
---|
412 | if(e2 == e4) { |
---|
413 | e = e2; |
---|
414 | E[i][j] = e; |
---|
415 | |
---|
416 | } else { |
---|
417 | if((e2!=0) && (e4!=0)) { |
---|
418 | |
---|
419 | r2 = FindRoot(T, e2); |
---|
420 | r4 = FindRoot(T, e4); |
---|
421 | |
---|
422 | e = ui32MinNonNul2(r2, r4); |
---|
423 | |
---|
424 | ECC_DEBUG(printf("%d->%d %d->%d min = %d\n", e2, r2, e4, r4, e)); |
---|
425 | |
---|
426 | if((e2) && (e2 != e)) SetRoot(T, e2, e); |
---|
427 | if((e4) && (e4 != e)) SetRoot(T, e4, e); |
---|
428 | E[i][j] = e; |
---|
429 | } else { |
---|
430 | if(e2) { |
---|
431 | r2 = FindRoot(T, e2); |
---|
432 | e = r2; |
---|
433 | SetRoot(T, e2, e); // inutile |
---|
434 | E[i][j] = e; |
---|
435 | } else { |
---|
436 | r4 = FindRoot(T, e4); |
---|
437 | e = r4; |
---|
438 | SetRoot(T, e4, e); // inutile |
---|
439 | E[i][j] = e; |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | } |
---|
444 | } else { |
---|
445 | E[i][j] = 0; |
---|
446 | } // x |
---|
447 | } // j |
---|
448 | return ne; |
---|
449 | } |
---|
450 | // ------------------------------------------------------------------------------------------------------------------ |
---|
451 | uint32 lineLabeling_Rosenfeld_UF_Org3_4C(uint8 **X, int i, int width, uint32 **E, uint32 *T, uint32 ne, uint32 nemax) |
---|
452 | // ------------------------------------------------------------------------------------------------------------------ |
---|
453 | { |
---|
454 | // version Org1, mais sans le cas des etiquettes identiques. Nouveaute 2015 |
---|
455 | |
---|
456 | int j; |
---|
457 | uint8 x; |
---|
458 | uint32 e; |
---|
459 | uint32 e2,e4; |
---|
460 | uint32 r2,r4; |
---|
461 | |
---|
462 | // version de WU avec union find |
---|
463 | // correct: on remonte a la racine |
---|
464 | |
---|
465 | for(j=0; j<width; j++) { |
---|
466 | |
---|
467 | x = X[i][j]; |
---|
468 | |
---|
469 | if(x) { |
---|
470 | |
---|
471 | e2 = E[i-1][j ]; |
---|
472 | e4 = E[i ][j-1]; |
---|
473 | |
---|
474 | // nouvel element |
---|
475 | if( (e2==0) && (e4==0) ) { |
---|
476 | e = ++ne; |
---|
477 | E[i][j] = e; |
---|
478 | |
---|
479 | } else { |
---|
480 | |
---|
481 | // cas general |
---|
482 | r2 = FindRoot(T, e2); |
---|
483 | r4 = FindRoot(T, e4); |
---|
484 | |
---|
485 | e = ui32MinNonNul2(r2,r4); |
---|
486 | |
---|
487 | if((e2) && (e2 != e)) SetRoot(T, e2, e); |
---|
488 | if((e4) && (e4 != e)) SetRoot(T, e4, e); |
---|
489 | |
---|
490 | E[i][j] = e; |
---|
491 | } |
---|
492 | } else { |
---|
493 | E[i][j] = 0; |
---|
494 | } // x |
---|
495 | } // j |
---|
496 | return ne; |
---|
497 | } |
---|
498 | // ------------------------------------------------------------------------------------------------------------------ |
---|
499 | uint32 lineLabeling_Rosenfeld_UF_Org3_8C(uint8 **X, int i, int width, uint32 **E, uint32 *T, uint32 ne, uint32 nemax) |
---|
500 | // ------------------------------------------------------------------------------------------------------------------ |
---|
501 | { |
---|
502 | // version Org1, mais sans le cas des etiquettes identiques. Nouveaute 2015 |
---|
503 | |
---|
504 | int j; |
---|
505 | |
---|
506 | uint8 x; |
---|
507 | uint32 e; |
---|
508 | uint32 e1,e2,e3,e4; |
---|
509 | uint32 r1,r2,r3,r4; |
---|
510 | |
---|
511 | for(j=0; j<width; j++) { |
---|
512 | |
---|
513 | x = X[i][j]; |
---|
514 | |
---|
515 | if(x) { |
---|
516 | |
---|
517 | e1 = E[i-1][j-1]; |
---|
518 | e2 = E[i-1][j ]; |
---|
519 | e3 = E[i-1][j+1]; |
---|
520 | e4 = E[i ][j-1]; |
---|
521 | |
---|
522 | // nouvel element |
---|
523 | if( (e1==0) && (e2==0) && (e3==0) && (e4==0)) { |
---|
524 | e = ++ne; |
---|
525 | E[i][j] = e; |
---|
526 | |
---|
527 | } else { |
---|
528 | |
---|
529 | // cas general |
---|
530 | r1 = FindRoot(T,e1); |
---|
531 | r2 = FindRoot(T,e2); |
---|
532 | r3 = FindRoot(T,e3); |
---|
533 | r4 = FindRoot(T,e4); |
---|
534 | |
---|
535 | e = ui32MinNonNul4(r1,r2,r3,r4); |
---|
536 | |
---|
537 | if((r1) && (r1 != e)) SetRoot(T, e1, e); |
---|
538 | if((r2) && (r2 != e)) SetRoot(T, e2, e); |
---|
539 | if((r3) && (r3 != e)) SetRoot(T, e3, e); |
---|
540 | if((r4) && (r4 != e)) SetRoot(T, e4, e); |
---|
541 | |
---|
542 | E[i][j] = e; |
---|
543 | |
---|
544 | } |
---|
545 | } else { |
---|
546 | E[i][j] = 0; |
---|
547 | } // x |
---|
548 | } // j |
---|
549 | return ne; |
---|
550 | } |
---|
551 | // ====================================== |
---|
552 | // == image-labeling (*_pass1) ========== |
---|
553 | // ====================================== |
---|
554 | |
---|
555 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
556 | uint32 Rosenfeld_UF_Org1_4C_pass1(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 nemax, RegionStats *Stats) |
---|
557 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
558 | { |
---|
559 | int i; |
---|
560 | uint32 ne = 0; // nombre d'etiquettes |
---|
561 | |
---|
562 | for(i=0; i<height; i++) { |
---|
563 | ne = lineLabeling_Rosenfeld_UF_Org1_4C(X, i, width, E, T, ne, nemax); |
---|
564 | // mettre les lineFeaturesComputation(...) |
---|
565 | } |
---|
566 | |
---|
567 | return ne; |
---|
568 | } |
---|
569 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
570 | uint32 Rosenfeld_UF_Org1_8C_pass1(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 nemax, RegionStats *Stats) |
---|
571 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
572 | { |
---|
573 | int i; |
---|
574 | uint32 ne = 0; // nombre d'etiquettes |
---|
575 | |
---|
576 | for(i=0; i<height; i++) { |
---|
577 | ne = lineLabeling_Rosenfeld_UF_Org1_8C(X, i, width, E, T, ne, nemax); |
---|
578 | // mettre les lineFeaturesComputation(...) |
---|
579 | } |
---|
580 | |
---|
581 | return ne; |
---|
582 | } |
---|
583 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
584 | uint32 Rosenfeld_UF_Org2_4C_pass1(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 nemax, RegionStats *Stats) |
---|
585 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
586 | { |
---|
587 | int i; |
---|
588 | uint32 ne = 0; // nombre d'etiquettes |
---|
589 | |
---|
590 | for(i=0; i<height; i++) { |
---|
591 | ne = lineLabeling_Rosenfeld_UF_Org2_4C(X, i, width, E, T, ne, nemax); |
---|
592 | // mettre les lineFeaturesComputation(...) |
---|
593 | } |
---|
594 | |
---|
595 | return ne; |
---|
596 | } |
---|
597 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
598 | uint32 Rosenfeld_UF_Org3_4C_pass1(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 nemax, RegionStats *Stats) |
---|
599 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
600 | { |
---|
601 | int i; |
---|
602 | uint32 ne = 0; // nombre d'etiquettes |
---|
603 | |
---|
604 | for(i=0; i<height; i++) { |
---|
605 | ne = lineLabeling_Rosenfeld_UF_Org3_4C(X, i, width, E, T, ne, nemax); |
---|
606 | // mettre les lineFeaturesComputation(...) |
---|
607 | } |
---|
608 | |
---|
609 | return ne; |
---|
610 | } |
---|
611 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
612 | uint32 Rosenfeld_UF_Org3_8C_pass1(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 nemax, RegionStats *Stats) |
---|
613 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
614 | { |
---|
615 | int i; |
---|
616 | uint32 ne = 0; // nombre d'etiquettes |
---|
617 | |
---|
618 | for(i=0; i<height; i++) { |
---|
619 | ne = lineLabeling_Rosenfeld_UF_Org3_8C(X, i, width, E, T, ne, nemax); |
---|
620 | // mettre les lineFeaturesComputation(...) |
---|
621 | } |
---|
622 | |
---|
623 | return ne; |
---|
624 | } |
---|
625 | |
---|
626 | // ========================================== |
---|
627 | // == Interface function ==================== |
---|
628 | // ========================================== |
---|
629 | |
---|
630 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
631 | uint32 Rosenfeld_UF_Org1_4C(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 *A, uint32 nemax, RegionStats *Stats) |
---|
632 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
633 | { |
---|
634 | int32 ne, na = -1; // nombre d'etiquettes, d'ancetres |
---|
635 | //uint32 nemax = height * width /2; |
---|
636 | |
---|
637 | |
---|
638 | ECC_VERBOSE(printf("====================================\n")); |
---|
639 | ECC_VERBOSE(printf("=== Rosenfeld Union-Find Org1 4C ===\n")); |
---|
640 | ECC_VERBOSE(printf("====================================\n")); |
---|
641 | // version de WU avec union find |
---|
642 | // correct: on remonte a la racine |
---|
643 | |
---|
644 | ne = Rosenfeld_UF_Org1_4C_pass1(X, height, width, E, T, nemax, Stats); |
---|
645 | |
---|
646 | ECC_VERBOSE2(display_ui32vector_number(T, 0, ne, "%3d", "T")); |
---|
647 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height - 1, 0, width - 1, 3, "E0")); |
---|
648 | |
---|
649 | //Flatten(T, ne); na = ne; |
---|
650 | ECC_SOLVE(na = FlattenL(T, ne)); |
---|
651 | |
---|
652 | ECC_LABEL2(applyTable(E, height, width, T, E)); |
---|
653 | |
---|
654 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height - 1, 0, width - 1, 3, "E1")); |
---|
655 | |
---|
656 | ECC_VERBOSE(printf("%d -> %d\n", ne, na)); |
---|
657 | if (Stats) { ECC_FEATURES(featuresComputation(E, height, width, Stats)); } |
---|
658 | |
---|
659 | // optimal table reset for next call |
---|
660 | initT(T, ne); |
---|
661 | |
---|
662 | return na; |
---|
663 | } |
---|
664 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
665 | uint32 Rosenfeld_UF_Org1_8C(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 *A, uint32 nemax, RegionStats *Stats) |
---|
666 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
667 | { |
---|
668 | uint32 ne, na=-1; // nombre d'etiquettes, d'ancetres |
---|
669 | //uint32 nemax = height * width /2; |
---|
670 | |
---|
671 | ECC_VERBOSE(printf("====================================\n")); |
---|
672 | ECC_VERBOSE(printf("=== Rosenfeld Union-Find Org1 8C ===\n")); |
---|
673 | ECC_VERBOSE(printf("====================================\n")); |
---|
674 | // version de WU avec union find |
---|
675 | // correct: on remonte a la racine |
---|
676 | |
---|
677 | ne = Rosenfeld_UF_Org1_8C_pass1(X, height, width, E, T, nemax, Stats); |
---|
678 | |
---|
679 | ECC_VERBOSE2(display_ui32vector_number(T, 0, ne, "%3d", "T")); |
---|
680 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E0")); |
---|
681 | |
---|
682 | //Flatten(T, ne); na = ne; |
---|
683 | ECC_SOLVE(na = FlattenL(T, ne)); |
---|
684 | |
---|
685 | ECC_LABEL2(applyTable(E, height, width, T, E)); |
---|
686 | |
---|
687 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E1")); |
---|
688 | |
---|
689 | ECC_VERBOSE(printf("%d -> %d\n", ne, na)); |
---|
690 | if(Stats) { ECC_FEATURES(featuresComputation(E, height, width, Stats)); } |
---|
691 | |
---|
692 | // optimal table reset for next call |
---|
693 | initT(T, ne); |
---|
694 | |
---|
695 | return na; |
---|
696 | } |
---|
697 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
698 | uint32 Rosenfeld_UF_Org2_4C(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 *A, uint32 nemax, RegionStats *Stats) |
---|
699 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
700 | { |
---|
701 | uint32 ne, na = -1; // nombre d'etiquettes, d'ancetres |
---|
702 | |
---|
703 | ECC_VERBOSE(printf("====================================\n")); |
---|
704 | ECC_VERBOSE(printf("=== Rosenfeld Union-Find Org2 4C ===\n")); |
---|
705 | ECC_VERBOSE(printf("====================================\n")); |
---|
706 | // version de WU avec union find |
---|
707 | // correct: on remonte a la racine |
---|
708 | |
---|
709 | // avec traitement des cas particuliers qd e2 ou e4 est nulle et pas l'autre |
---|
710 | // fait gagner sur les petites granularites |
---|
711 | |
---|
712 | ne = Rosenfeld_UF_Org2_4C_pass1(X, height, width, E, T, nemax, Stats); |
---|
713 | |
---|
714 | ECC_VERBOSE2(display_ui32vector_number(T, 0, ne, "%3d", "T")); |
---|
715 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E0")); |
---|
716 | |
---|
717 | //Flatten(T, ne); na = ne; |
---|
718 | ECC_SOLVE(na = FlattenL(T, ne)); |
---|
719 | |
---|
720 | ECC_LABEL2(applyTable(E, height, width, T, E)); |
---|
721 | |
---|
722 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E1")); |
---|
723 | |
---|
724 | ECC_VERBOSE(printf("%d -> %d\n", ne, na)); |
---|
725 | if(Stats) { ECC_FEATURES(featuresComputation(E, height, width, Stats)); } |
---|
726 | |
---|
727 | // optimal table reset for next call |
---|
728 | initT(T, ne); |
---|
729 | |
---|
730 | return na; |
---|
731 | } |
---|
732 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
733 | uint32 Rosenfeld_UF_Org3_4C(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 *A, uint32 nemax, RegionStats *Stats) |
---|
734 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
735 | { |
---|
736 | uint32 ne, na = -1; // nombre d'etiquettes, d'ancetres |
---|
737 | //uint32 nemax = height * width /2; |
---|
738 | |
---|
739 | ECC_VERBOSE(printf("====================================\n")); |
---|
740 | ECC_VERBOSE(printf("=== Rosenfeld Union-Find Org3 4C ===\n")); |
---|
741 | ECC_VERBOSE(printf("====================================\n")); |
---|
742 | // version de WU avec union find |
---|
743 | // correct: on remonte a la racine |
---|
744 | |
---|
745 | ne = Rosenfeld_UF_Org3_4C_pass1(X, height, width, E, T, nemax, Stats); |
---|
746 | |
---|
747 | ECC_VERBOSE2(display_ui32vector_number(T, 0, ne, "%3d", "T")); |
---|
748 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E0")); |
---|
749 | |
---|
750 | //Flatten(T, ne); na = ne; |
---|
751 | ECC_SOLVE(na = FlattenL(T, ne)); |
---|
752 | |
---|
753 | ECC_LABEL2(applyTable(E, height, width, T, E)); |
---|
754 | |
---|
755 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E1")); |
---|
756 | |
---|
757 | ECC_VERBOSE(printf("%d -> %d\n", ne, na)); |
---|
758 | if(Stats) { ECC_FEATURES(featuresComputation(E, height, width, Stats)); } |
---|
759 | |
---|
760 | // optimal table reset for next call |
---|
761 | initT(T, ne); |
---|
762 | |
---|
763 | return na; |
---|
764 | } |
---|
765 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
766 | uint32 Rosenfeld_UF_Org3_8C(uint8 **X, int height, int width, uint32 **E, uint32 *T, uint32 *A, uint32 nemax, RegionStats *Stats) |
---|
767 | // --------------------------------------------------------------------------------------------------------------------------- |
---|
768 | { |
---|
769 | uint32 ne, na=-1; // nombre d'etiquettes, d'ancetres |
---|
770 | //uint32 nemax = height * width /2; |
---|
771 | |
---|
772 | ECC_VERBOSE(printf("====================================\n")); |
---|
773 | ECC_VERBOSE(printf("=== Rosenfeld Union-Find Org1 8C ===\n")); |
---|
774 | ECC_VERBOSE(printf("====================================\n")); |
---|
775 | // version de WU avec union find |
---|
776 | // correct: on remonte a la racine |
---|
777 | |
---|
778 | ne = Rosenfeld_UF_Org3_8C_pass1(X, height, width, E, T, nemax, Stats); |
---|
779 | |
---|
780 | ECC_VERBOSE2(display_ui32vector_number(T, 0, ne, "%3d", "T")); |
---|
781 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E0")); |
---|
782 | |
---|
783 | //Flatten(T, ne); na = ne; |
---|
784 | ECC_SOLVE(na = FlattenL(T, ne)); |
---|
785 | |
---|
786 | ECC_LABEL2(applyTable(E, height, width, T, E)); |
---|
787 | |
---|
788 | ECC_VERBOSE2(display_ui32matrix_positive(E,0, height-1, 0, width-1, 3, "E1")); |
---|
789 | |
---|
790 | ECC_VERBOSE(printf("%d -> %d\n", ne, na)); |
---|
791 | if(Stats) { ECC_FEATURES(featuresComputation(E, height, width, Stats)); } |
---|
792 | |
---|
793 | // optimal table reset for next call |
---|
794 | initT(T, ne); |
---|
795 | |
---|
796 | return na; |
---|
797 | } |
---|
798 | |
---|