[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 | |
---|
| 94 | // allocatin 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 memoir |
---|
| 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); |
---|
| 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); 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); 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); 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); |
---|
| 191 | |
---|
| 192 | // chargement d'une image depuis le disque |
---|
| 193 | X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); |
---|
| 194 | |
---|
| 195 | // allocatin memoire |
---|
| 196 | X = ui8matrix (i0-border, i1+border, j0-border, j1+border); |
---|
| 197 | E8 = ui8matrix (i0-border, i1+border, j0-border, j1+border); |
---|
| 198 | E32 = ui32matrix(i0-border, i1+border, j0-border, j1+border); |
---|
| 199 | |
---|
| 200 | // initialisation de la memoir |
---|
| 201 | zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
| 202 | zero_ui8matrix (E8, i0-border, i1+border, j0-border, j1+border); |
---|
| 203 | zero_ui8matrix (X, i0-border, i1+border, j0-border, j1+border); |
---|
| 204 | |
---|
| 205 | // pre-traitements |
---|
| 206 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 1, X); // pour le traitement |
---|
| 207 | binarisation_ui8matrix(X0, i0, i1, j0, j1, 20, 255, X0); // pour la verif visuelle |
---|
| 208 | generate_path_filename(pathDst, "verif.pgm", complete_filename); |
---|
| 209 | SavePGM_ui8matrix(X0, i0, i1, j0, j1, complete_filename); |
---|
| 210 | |
---|
| 211 | height = i1-i0+1; width = j1-j0+1; |
---|
| 212 | |
---|
| 213 | nemax = ((height+1)*(width+1)) / 2; // majorant strict |
---|
| 214 | nermax = (width+1) / 2; |
---|
| 215 | |
---|
| 216 | // alloc init des tables d'equivalences pour UF, Suzuki et Bailey |
---|
| 217 | T = ui32vector(0, nemax); |
---|
| 218 | A = ui32vector(0, nemax); |
---|
| 219 | N = ui32vector(0, nemax); |
---|
| 220 | |
---|
| 221 | S = ui32vector(0, 2 * nermax); |
---|
| 222 | |
---|
| 223 | initT(T, nemax); |
---|
| 224 | initT(A, nemax); |
---|
| 225 | initZ(N, nemax); |
---|
| 226 | |
---|
| 227 | Stats = RegionStatsVector(0, nemax); |
---|
| 228 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
| 229 | |
---|
| 230 | // traitement: desactiver FlattenL dans Rosenfeld |
---|
| 231 | // pour voir l'image d'etiquettes sans re-etiquetage |
---|
| 232 | /*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);*/ |
---|
| 233 | |
---|
| 234 | na = Rosenfeld_UF_Org1_8C(X, height, width, E32, T, A, nemax, Stats); |
---|
| 235 | printf("na = %d\n", na); |
---|
| 236 | filename = "Rosenfeld_UF_Org1_8C.bmp"; |
---|
| 237 | mod_ui32matrix_ui8matrix(E32, i0, i1, j0, j1, E8); |
---|
| 238 | generate_path_filename(pathDst, filename, complete_filename); |
---|
| 239 | SaveBMP2_ui8matrix(E8, width, height, palette, complete_filename); |
---|
| 240 | zero_ui32matrix(E32, i0 - border, i1 + border, j0 - border, j1 + border); |
---|
| 241 | display_RegionStatsVector(Stats, 1, na, "Stats"); |
---|
| 242 | zero_RegionStatsVector(Stats, 0, nemax); |
---|
| 243 | |
---|
| 244 | /*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);*/ |
---|
| 245 | |
---|
| 246 | free_ui8matrix (X0, i0, i1, j0, j1); |
---|
| 247 | free_ui8matrix (X, i0-border, i1+border, j0-border, j1+border); |
---|
| 248 | free_ui8matrix (E8, i0-border, i1+border, j0-border, j1+border); |
---|
| 249 | free_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
| 250 | |
---|
| 251 | free_ui32vector(T, 0, nemax); |
---|
| 252 | free_ui32vector(A, 0, nemax); |
---|
| 253 | free_ui32vector(N, 0, nemax); |
---|
| 254 | |
---|
| 255 | free_ui32vector(S, 0, 2*nermax); |
---|
| 256 | |
---|
| 257 | return; |
---|
| 258 | } |
---|
| 259 | // --------------------------------------- |
---|
| 260 | int main_rosenfeld(int argc, char* argv[]) |
---|
| 261 | // --------------------------------------- |
---|
| 262 | { |
---|
| 263 | char *src_path; |
---|
| 264 | char *filename; |
---|
| 265 | char *dst_path; |
---|
| 266 | |
---|
| 267 | printf("[======================]"); |
---|
| 268 | printf("[=== main_rosenfeld ===]"); |
---|
| 269 | printf("[======================]"); |
---|
| 270 | |
---|
| 271 | src_path = "./"; // ne pas oublier le / a la fin |
---|
| 272 | dst_path = ""; |
---|
| 273 | |
---|
| 274 | filename = "boulons.pgm"; |
---|
| 275 | |
---|
| 276 | //main_rosenfeld_forme(dst_path); |
---|
| 277 | main_rosenfeld_file(src_path, filename, dst_path); |
---|
| 278 | |
---|
| 279 | return 0; |
---|
| 280 | } |
---|
| 281 | // ------------------------------------- |
---|
| 282 | void display_arg(int argc, char* argv[]) |
---|
| 283 | // ------------------------------------- |
---|
| 284 | { |
---|
| 285 | int i; |
---|
| 286 | |
---|
| 287 | printf("================="); |
---|
| 288 | printf("== display_arg =="); |
---|
| 289 | printf("================="); |
---|
| 290 | printf(""); |
---|
| 291 | |
---|
| 292 | printf("argc = %d\n", argc); |
---|
| 293 | |
---|
| 294 | for (i = 0; i < argc; i++) { |
---|
| 295 | printf("%s ", argv[i]); |
---|
| 296 | } |
---|
| 297 | printf(""); |
---|
| 298 | } |
---|
| 299 | // ----------------------- |
---|
| 300 | void ecc_info_define(void) |
---|
| 301 | // ----------------------- |
---|
| 302 | { |
---|
| 303 | printf("====================="); |
---|
| 304 | printf("== ecc_info_define =="); |
---|
| 305 | printf("====================="); |
---|
| 306 | printf(""); |
---|
| 307 | ecc_info_omp(); |
---|
| 308 | //Label_Display_Info(); |
---|
| 309 | printf(""); |
---|
| 310 | } |
---|
| 311 | // ----------------------------- |
---|
| 312 | int main(int argc, char* argv[]) |
---|
| 313 | // ----------------------------- |
---|
| 314 | { |
---|
| 315 | display_arg(argc, argv); |
---|
| 316 | ecc_info_define(); |
---|
| 317 | main_rosenfeld(argc, argv); |
---|
| 318 | printf("[main]: bye"); |
---|
| 319 | return 0; |
---|
| 320 | } |
---|