| 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("[---------------------------]\n"); |
|---|
| 162 | printf("[--- main_rosenfeld_file ---]\n"); |
|---|
| 163 | printf("[---------------------------]\n"); |
|---|
| 164 | |
|---|
| 165 | char * pathSrc = src_path; |
|---|
| 166 | char * pathDst = dst_path; |
|---|
| 167 | |
|---|
| 168 | uint8 ** X0; |
|---|
| 169 | uint8 ** X; |
|---|
| 170 | uint8 ** E8; |
|---|
| 171 | |
|---|
| 172 | uint32 ** E32; |
|---|
| 173 | uint32 * S; // Stack for Bailey algorithm |
|---|
| 174 | |
|---|
| 175 | uint32 * T; |
|---|
| 176 | uint32 * A; |
|---|
| 177 | uint32 * N; |
|---|
| 178 | //uint32 * SNE; // memorisation de la somme des ne: sne |
|---|
| 179 | |
|---|
| 180 | int i0, i1, j0, j1; |
|---|
| 181 | int height, width, border = 1; |
|---|
| 182 | uint32 nemax, nermax; |
|---|
| 183 | int na; |
|---|
| 184 | |
|---|
| 185 | RegionStats * Stats = NULL; |
|---|
| 186 | |
|---|
| 187 | RGBQuad palette[256]; |
|---|
| 188 | char complete_filename[1024]; |
|---|
| 189 | |
|---|
| 190 | Palette_18ColorsBW(palette); |
|---|
| 191 | generate_path_filename(pathSrc, filename, complete_filename, 1024); |
|---|
| 192 | |
|---|
| 193 | // chargement d'une image depuis le disque |
|---|
| 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... "); |
|---|
| 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); |
|---|
| 204 | |
|---|
| 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); |
|---|
| 209 | |
|---|
| 210 | // pre-traitements |
|---|
| 211 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 1, X); // pour le traitement |
|---|
| 212 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 255, X0); // pour la verif visuelle |
|---|
| 213 | printf("done.\n"); |
|---|
| 214 | |
|---|
| 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 | |
|---|
| 220 | height = i1 - i0 + 1; |
|---|
| 221 | width = j1 - j0 + 1; |
|---|
| 222 | |
|---|
| 223 | nemax = ((height + 1) * (width + 1)) / 2; // majorant strict |
|---|
| 224 | nermax = (width + 1) / 2; |
|---|
| 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); |
|---|
| 246 | //filename = "Rosenfeld_UF_Org1_8C.bmp"; |
|---|
| 247 | mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); |
|---|
| 248 | //generate_path_filename(pathDst, filename, complete_filename, 1024); |
|---|
| 249 | //SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); |
|---|
| 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 | |
|---|
| 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); |
|---|
| 260 | |
|---|
| 261 | free_ui32vector(T, 0, nemax); |
|---|
| 262 | free_ui32vector(A, 0, nemax); |
|---|
| 263 | free_ui32vector(N, 0, nemax); |
|---|
| 264 | |
|---|
| 265 | free_ui32vector(S, 0, 2 * nermax); |
|---|
| 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 | |
|---|
| 277 | printf("[======================]\n"); |
|---|
| 278 | printf("[=== main_rosenfeld ===]\n"); |
|---|
| 279 | printf("[======================]\n"); |
|---|
| 280 | |
|---|
| 281 | src_path = "/misc/"; // ne pas oublier le / a la fin |
|---|
| 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 | |
|---|
| 297 | printf("=================\n"); |
|---|
| 298 | printf("== display_arg ==\n"); |
|---|
| 299 | printf("=================\n"); |
|---|
| 300 | printf("\n"); |
|---|
| 301 | |
|---|
| 302 | printf("argc = %d\n", argc); |
|---|
| 303 | |
|---|
| 304 | for (i = 0; i < argc; i++) { |
|---|
| 305 | printf("%s ", argv[i]); |
|---|
| 306 | } |
|---|
| 307 | printf("\n"); |
|---|
| 308 | } |
|---|
| 309 | // ----------------------- |
|---|
| 310 | void ecc_info_define(void) |
|---|
| 311 | // ----------------------- |
|---|
| 312 | { |
|---|
| 313 | printf("=====================\n"); |
|---|
| 314 | printf("== ecc_info_define ==\n"); |
|---|
| 315 | printf("=====================\n"); |
|---|
| 316 | printf("\n"); |
|---|
| 317 | ecc_info_omp(); |
|---|
| 318 | //Label_Display_Info(); |
|---|
| 319 | printf("\n"); |
|---|
| 320 | } |
|---|
| 321 | // ----------------------------- |
|---|
| 322 | __attribute__((constructor)) void main(int argc, char* argv[]) |
|---|
| 323 | // ----------------------------- |
|---|
| 324 | { |
|---|
| 325 | #if TARGET_OS == GIETVM |
|---|
| 326 | giet_tty_alloc(1); |
|---|
| 327 | heap_init(0, 0); |
|---|
| 328 | #endif |
|---|
| 329 | display_arg(argc, argv); |
|---|
| 330 | ecc_info_define(); |
|---|
| 331 | main_rosenfeld(argc, argv); |
|---|
| 332 | printf("[main]: bye"); |
|---|
| 333 | exit(0); |
|---|
| 334 | } |
|---|