[772] | 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 | |
---|
[791] | 94 | // allocation memoire |
---|
[772] | 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); |
---|
[791] | 98 | |
---|
| 99 | // initialisation de la memoire |
---|
[772] | 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); |
---|
[791] | 103 | |
---|
[772] | 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 |
---|
[777] | 107 | generate_path_filename(dst_path, "verif.pgm", complete_filename, 1024); |
---|
[772] | 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 | |
---|
[805] | 122 | S = ui32vector(0, 2 * nermax); |
---|
[772] | 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 |
---|
[777] | 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); |
---|
[772] | 134 | |
---|
| 135 | |
---|
[777] | 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); |
---|
[772] | 137 | |
---|
| 138 | |
---|
[777] | 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); |
---|
[772] | 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 | { |
---|
[798] | 161 | printf("[---------------------------]\n"); |
---|
| 162 | printf("[--- main_rosenfeld_file ---]\n"); |
---|
| 163 | printf("[---------------------------]\n"); |
---|
[772] | 164 | |
---|
[798] | 165 | char * pathSrc = src_path; |
---|
| 166 | char * pathDst = dst_path; |
---|
[772] | 167 | |
---|
[798] | 168 | uint8 ** X0; |
---|
| 169 | uint8 ** X; |
---|
| 170 | uint8 ** E8; |
---|
[772] | 171 | |
---|
[798] | 172 | uint32 ** E32; |
---|
| 173 | uint32 * S; // Stack for Bailey algorithm |
---|
[772] | 174 | |
---|
[798] | 175 | uint32 * T; |
---|
| 176 | uint32 * A; |
---|
| 177 | uint32 * N; |
---|
| 178 | //uint32 * SNE; // memorisation de la somme des ne: sne |
---|
[772] | 179 | |
---|
| 180 | int i0, i1, j0, j1; |
---|
[798] | 181 | int height, width, border = 1; |
---|
[772] | 182 | uint32 nemax, nermax; |
---|
| 183 | int na; |
---|
| 184 | |
---|
[791] | 185 | RegionStats * Stats = NULL; |
---|
[772] | 186 | |
---|
| 187 | RGBQuad palette[256]; |
---|
| 188 | char complete_filename[1024]; |
---|
| 189 | |
---|
| 190 | Palette_18ColorsBW(palette); |
---|
[777] | 191 | generate_path_filename(pathSrc, filename, complete_filename, 1024); |
---|
[772] | 192 | |
---|
| 193 | // chargement d'une image depuis le disque |
---|
[798] | 194 | printf("Loading file %s... ", filename); |
---|
| 195 | X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); |
---|
| 196 | //init_forme_boulon1(&X0, &i0, &i1, &j0, &j1); |
---|
| 197 | printf("done.\n"); |
---|
| 198 | |
---|
| 199 | printf("Allocating memory... "); |
---|
[791] | 200 | // allocation memoire |
---|
| 201 | X = ui8matrix (i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 202 | E8 = ui8matrix (i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 203 | E32 = ui32matrix(i0 - border, i1 + border, j0 - border, j1 + border); |
---|
[772] | 204 | |
---|
[791] | 205 | // initialisation de la memoire |
---|
| 206 | zero_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 207 | zero_ui8matrix (E8, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 208 | zero_ui8matrix (X, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
[772] | 209 | |
---|
| 210 | // pre-traitements |
---|
| 211 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 1, X); // pour le traitement |
---|
[798] | 212 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 255, X0); // pour la verif visuelle |
---|
| 213 | printf("done.\n"); |
---|
[772] | 214 | |
---|
[798] | 215 | printf("Saving file %s for verification... ", complete_filename); |
---|
| 216 | generate_path_filename(pathDst, "verif.pgm", complete_filename, 1024); |
---|
| 217 | SavePGM_ui8matrix(X0, i0, i1, j0, j1, complete_filename); |
---|
| 218 | printf("done.\n"); |
---|
| 219 | |
---|
[791] | 220 | height = i1 - i0 + 1; |
---|
| 221 | width = j1 - j0 + 1; |
---|
[772] | 222 | |
---|
[791] | 223 | nemax = ((height + 1) * (width + 1)) / 2; // majorant strict |
---|
| 224 | nermax = (width + 1) / 2; |
---|
[772] | 225 | |
---|
| 226 | // alloc init des tables d'equivalences pour UF, Suzuki et Bailey |
---|
| 227 | T = ui32vector(0, nemax); |
---|
| 228 | A = ui32vector(0, nemax); |
---|
| 229 | N = ui32vector(0, nemax); |
---|
| 230 | |
---|
| 231 | S = ui32vector(0, 2 * nermax); |
---|
| 232 | |
---|
| 233 | initT(T, nemax); |
---|
| 234 | initT(A, nemax); |
---|
| 235 | initZ(N, nemax); |
---|
| 236 | |
---|
| 237 | Stats = RegionStatsVector(0, nemax); |
---|
| 238 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
| 239 | |
---|
| 240 | // traitement: desactiver FlattenL dans Rosenfeld |
---|
| 241 | // pour voir l'image d'etiquettes sans re-etiquetage |
---|
| 242 | /*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);*/ |
---|
| 243 | |
---|
| 244 | na = Rosenfeld_UF_Org1_8C(X, height, width, E32, T, A, nemax, Stats); |
---|
| 245 | printf("na = %d\n", na); |
---|
[791] | 246 | //filename = "Rosenfeld_UF_Org1_8C.bmp"; |
---|
[772] | 247 | mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); |
---|
[791] | 248 | //generate_path_filename(pathDst, filename, complete_filename, 1024); |
---|
| 249 | //SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); |
---|
[772] | 250 | zero_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 251 | display_RegionStatsVector(Stats, 1, na, "Stats"); |
---|
| 252 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
| 253 | |
---|
| 254 | /*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);*/ |
---|
| 255 | |
---|
[798] | 256 | free_ui8matrix (X0, i0, i1, j0, j1); |
---|
| 257 | free_ui8matrix (X, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 258 | free_ui8matrix (E8, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 259 | free_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
[772] | 260 | |
---|
| 261 | free_ui32vector(T, 0, nemax); |
---|
| 262 | free_ui32vector(A, 0, nemax); |
---|
| 263 | free_ui32vector(N, 0, nemax); |
---|
| 264 | |
---|
[798] | 265 | free_ui32vector(S, 0, 2 * nermax); |
---|
[772] | 266 | |
---|
| 267 | return; |
---|
| 268 | } |
---|
| 269 | // --------------------------------------- |
---|
| 270 | int main_rosenfeld(int argc, char* argv[]) |
---|
| 271 | // --------------------------------------- |
---|
| 272 | { |
---|
| 273 | char *src_path; |
---|
| 274 | char *filename; |
---|
| 275 | char *dst_path; |
---|
| 276 | |
---|
[798] | 277 | printf("[======================]\n"); |
---|
| 278 | printf("[=== main_rosenfeld ===]\n"); |
---|
| 279 | printf("[======================]\n"); |
---|
[772] | 280 | |
---|
[798] | 281 | src_path = "/misc/"; // ne pas oublier le / a la fin |
---|
[772] | 282 | dst_path = ""; |
---|
| 283 | |
---|
| 284 | filename = "boulons.pgm"; |
---|
| 285 | |
---|
| 286 | //main_rosenfeld_forme(dst_path); |
---|
| 287 | main_rosenfeld_file(src_path, filename, dst_path); |
---|
| 288 | |
---|
| 289 | return 0; |
---|
| 290 | } |
---|
| 291 | // ------------------------------------- |
---|
| 292 | void display_arg(int argc, char* argv[]) |
---|
| 293 | // ------------------------------------- |
---|
| 294 | { |
---|
| 295 | int i; |
---|
| 296 | |
---|
[798] | 297 | printf("=================\n"); |
---|
| 298 | printf("== display_arg ==\n"); |
---|
| 299 | printf("=================\n"); |
---|
| 300 | printf("\n"); |
---|
[772] | 301 | |
---|
| 302 | printf("argc = %d\n", argc); |
---|
| 303 | |
---|
| 304 | for (i = 0; i < argc; i++) { |
---|
| 305 | printf("%s ", argv[i]); |
---|
| 306 | } |
---|
[798] | 307 | printf("\n"); |
---|
[772] | 308 | } |
---|
| 309 | // ----------------------- |
---|
| 310 | void ecc_info_define(void) |
---|
| 311 | // ----------------------- |
---|
| 312 | { |
---|
[798] | 313 | printf("=====================\n"); |
---|
| 314 | printf("== ecc_info_define ==\n"); |
---|
| 315 | printf("=====================\n"); |
---|
| 316 | printf("\n"); |
---|
[772] | 317 | ecc_info_omp(); |
---|
| 318 | //Label_Display_Info(); |
---|
[798] | 319 | printf("\n"); |
---|
[772] | 320 | } |
---|
| 321 | // ----------------------------- |
---|
[798] | 322 | __attribute__((constructor)) void main(int argc, char* argv[]) |
---|
[772] | 323 | // ----------------------------- |
---|
| 324 | { |
---|
[798] | 325 | #if TARGET_OS == GIETVM |
---|
[791] | 326 | giet_tty_alloc(1); |
---|
[798] | 327 | heap_init(0, 0); |
---|
[791] | 328 | #endif |
---|
[772] | 329 | display_arg(argc, argv); |
---|
| 330 | ecc_info_define(); |
---|
| 331 | main_rosenfeld(argc, argv); |
---|
| 332 | printf("[main]: bye"); |
---|
[798] | 333 | exit(0); |
---|
[772] | 334 | } |
---|