[772] | 1 | /* ------------------------ */ |
---|
| 2 | /* --- ecc_generation.c --- */ |
---|
| 3 | /* ------------------------ */ |
---|
| 4 | |
---|
| 5 | #include <stdio.h> |
---|
| 6 | #include <stdlib.h> |
---|
| 7 | #include <math.h> |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | #ifdef CLI |
---|
| 11 | #include "nrc_os_config.h" |
---|
| 12 | #include "nrc.h" |
---|
| 13 | #endif |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #include "lutNR.h" // pour conversion 0,1 <-> 0,255 |
---|
| 17 | |
---|
| 18 | #include "ecc_common.h" |
---|
| 19 | #include "ecc_features.h" |
---|
| 20 | |
---|
| 21 | #include "mt19937.h" // Mersenne Twister generator |
---|
| 22 | #include "ecc_generation.h" |
---|
| 23 | |
---|
[791] | 24 | |
---|
[822] | 25 | // -------------------------------------------------------------------------------------------------------------------------- |
---|
| 26 | void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed) |
---|
| 27 | // -------------------------------------------------------------------------------------------------------------------------- |
---|
[772] | 28 | { |
---|
| 29 | uint8 x; |
---|
| 30 | double r; |
---|
| 31 | |
---|
| 32 | //srand(seed); // pour toujours generer les meme sequences |
---|
| 33 | init_genrand(seed); |
---|
| 34 | |
---|
[822] | 35 | for (int i = i0; i <= i1; i += granularity) { |
---|
| 36 | for (int j = j0; j <= j1; j += granularity) { |
---|
[772] | 37 | |
---|
| 38 | //r = 100.0*(double)rand() / rmax; |
---|
| 39 | //r = 100.0*(double)rand() / rmax; |
---|
[822] | 40 | r = 100.0 * (double) genrand_real2(); |
---|
| 41 | if (r <= density) { |
---|
| 42 | x = 1; |
---|
| 43 | } |
---|
| 44 | else { |
---|
| 45 | x = 0; |
---|
| 46 | } |
---|
[772] | 47 | |
---|
[822] | 48 | for (int di = 0; di < granularity; di++) { |
---|
| 49 | for (int dj = 0; dj < granularity; dj++) { |
---|
| 50 | if ((i + di <= i1) && (j + dj <= j1)) { |
---|
| 51 | X[i + di][j + dj] = x; |
---|
| 52 | } |
---|
[772] | 53 | } // dj |
---|
| 54 | } // di |
---|
[822] | 55 | } // j |
---|
[772] | 56 | } // i |
---|
| 57 | } |
---|
[822] | 58 | |
---|
| 59 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
| 60 | void generate_granularity_density_int(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, int density, int seed) |
---|
| 61 | // ---------------------------------------------------------------------------------------------------------------------- |
---|
[772] | 62 | { |
---|
| 63 | generate_granularity_density_float(X, i0, i1, j0, j1, granularity, (float) density, seed); |
---|
| 64 | } |
---|
[822] | 65 | |
---|
| 66 | // ----------------------------------------------------------------------------------------------------------- |
---|
| 67 | void generate_granularity_density_name(char * name, int granularity, int density, char * filename, int maxlen) |
---|
| 68 | // ----------------------------------------------------------------------------------------------------------- |
---|
[772] | 69 | { |
---|
[777] | 70 | snprintf(filename, maxlen, "%s_%02d_%03d.pgm", name, granularity, density); |
---|
[772] | 71 | } |
---|
[822] | 72 | |
---|
| 73 | // --------------------------------------------------------------------------------------------------------------------------------- |
---|
| 74 | void generate_granularity_density_ext_name(char * name, int granularity, int density, char * extension, char * filename, int maxlen) |
---|
| 75 | // --------------------------------------------------------------------------------------------------------------------------------- |
---|
[772] | 76 | { |
---|
[777] | 77 | snprintf(filename, maxlen, "%s_%02d_%03d.%s", name, granularity, density, extension); |
---|
[772] | 78 | } |
---|
[822] | 79 | // -------------------------------------------------------------------------------------------------------------------------- |
---|
| 80 | void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char * filename, int maxlen) |
---|
| 81 | // -------------------------------------------------------------------------------------------------------------------------- |
---|
[772] | 82 | { |
---|
[777] | 83 | snprintf(filename, maxlen, "%s_%d_%02d_%03d.pgm", name, size, granularity, density); |
---|
[772] | 84 | } |
---|
[822] | 85 | // ----------------------------------------------------------------------------------------------------------------------------------------------- |
---|
| 86 | void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char * filename, int maxlen) |
---|
| 87 | // ----------------------------------------------------------------------------------------------------------------------------------------------- |
---|
[772] | 88 | { |
---|
[777] | 89 | snprintf(filename, maxlen, "%s_%d_%02d_%03d.%s", name, size, granularity, density, extension); |
---|
[772] | 90 | } |
---|
[822] | 91 | // ----------------------------------------------------------------------------------------------------- |
---|
| 92 | void generate_size_granularity_name(char * name, int size, int granularity, char * filename, int maxlen) |
---|
| 93 | // ----------------------------------------------------------------------------------------------------- |
---|
[772] | 94 | { |
---|
[777] | 95 | snprintf(filename, maxlen, "%s_%d_%02d.pgm", name, size, granularity); |
---|
[822] | 96 | }// ------------------------------------------------------------------------------------------ |
---|
| 97 | void generate_name100(char * name, int granularity, float density, char *filename, int maxlen) |
---|
| 98 | // ------------------------------------------------------------------------------------------- |
---|
[772] | 99 | { |
---|
| 100 | // density en pourcentage: 0:100 |
---|
| 101 | // mais aussi <1, par exe 0.01 |
---|
| 102 | int d = (int) ceil(100 * density); |
---|
[777] | 103 | snprintf(filename, maxlen, "%s_%02d_%05d.pgm", name, granularity, d); |
---|
[772] | 104 | } |
---|
| 105 | // ---------------------------------------- |
---|
[822] | 106 | int test_generation(int argc, char * argv[]) |
---|
[772] | 107 | // ---------------------------------------- |
---|
| 108 | { |
---|
[822] | 109 | uint8 ** X; |
---|
| 110 | uint8 ** X255; |
---|
[772] | 111 | char filename[32]; |
---|
| 112 | |
---|
| 113 | int n = 1024; |
---|
| 114 | int border = 2; |
---|
| 115 | |
---|
| 116 | int d; // density |
---|
| 117 | int dmin = 5; |
---|
| 118 | int dmax = 95; |
---|
| 119 | int dstep = 5; |
---|
| 120 | |
---|
| 121 | int g; // granularity |
---|
| 122 | int gmin = 1; |
---|
| 123 | int gmax = 16; |
---|
| 124 | |
---|
| 125 | int seed = 0; |
---|
| 126 | |
---|
| 127 | n = 256; |
---|
| 128 | n = 2048; |
---|
| 129 | n = 4096; |
---|
| 130 | |
---|
[822] | 131 | X = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border); |
---|
| 132 | X255 = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border); |
---|
[772] | 133 | |
---|
[822] | 134 | for (g = gmin; g <= gmax; g *= 2) { |
---|
| 135 | for (d = dmin; d <= dmax; d += dstep) { |
---|
| 136 | generate_granularity_density_int(X, 0, n - 1, 0, n - 1, g, d, seed); |
---|
[777] | 137 | generate_granularity_density_name("I", g, d, filename, 32); |
---|
[772] | 138 | printf(filename); |
---|
[822] | 139 | bin2gray_ui8matrix(X, 0, n - 1, 0, n - 1, X255); |
---|
| 140 | SavePGM_ui8matrix(X255, 0, n - 1, 0, n - 1, filename); |
---|
[772] | 141 | } |
---|
| 142 | } |
---|
[822] | 143 | free_ui8matrix(X, 0 - border, n - 1 + border, 0 - border, n - 1 + border); |
---|
| 144 | free_ui8matrix(X255, 0 - border, n - 1 + border, 0 - border, n - 1 + border); |
---|
[772] | 145 | |
---|
| 146 | return 0; |
---|
| 147 | } |
---|
[822] | 148 | |
---|
| 149 | // ------------------------------------------ |
---|
| 150 | void hline(uint8 ** X, int i, int j0, int j1) |
---|
| 151 | // ------------------------------------------ |
---|
[772] | 152 | { |
---|
[822] | 153 | for (int j = j0; j <= j1; j++) { |
---|
| 154 | X[i][j] = 1; |
---|
| 155 | } |
---|
[772] | 156 | } |
---|
[822] | 157 | // ------------------------------------------ |
---|
| 158 | void vline(uint8 ** X, int i0, int i1, int j) |
---|
| 159 | // ------------------------------------------ |
---|
[772] | 160 | { |
---|
[822] | 161 | for (int i = i0; i <= i1; i++) { |
---|
| 162 | X[i][j] = 1; |
---|
| 163 | } |
---|
[772] | 164 | } |
---|
[822] | 165 | |
---|
| 166 | // ------------------------------------------------------------ |
---|
| 167 | void draw_rectangle(uint8 ** X, int i0, int i1, int j0, int j1) |
---|
| 168 | // ------------------------------------------------------------ |
---|
[772] | 169 | { |
---|
| 170 | hline(X, i0, j0, j1); |
---|
| 171 | vline(X, i0, i1, j0); |
---|
| 172 | vline(X, i0, i1, j1); |
---|
| 173 | hline(X, i1, j0, j1); |
---|
| 174 | } |
---|
[822] | 175 | |
---|
| 176 | // --------------------------------------------------- |
---|
| 177 | void spirale_simple(uint8 ** X, int height, int width) |
---|
| 178 | // --------------------------------------------------- |
---|
[772] | 179 | { |
---|
| 180 | int i0, j0; // point de depart haut |
---|
| 181 | int i1, j1; //point de depart haut |
---|
| 182 | int c, nc; // nombre de carres |
---|
| 183 | int n; //min(height, width) |
---|
| 184 | |
---|
[822] | 185 | zero_ui8matrix(X, 0, height - 1, 0, width - 1); |
---|
[772] | 186 | |
---|
[822] | 187 | if (height < width) { |
---|
[772] | 188 | n = height; |
---|
[822] | 189 | } |
---|
| 190 | else { |
---|
[772] | 191 | n = width; |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | // sans correction |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | // avec correction |
---|
[822] | 198 | i0 = 0; |
---|
| 199 | i1 = 2 * (n / 2) - 1; |
---|
| 200 | j0 = 0; |
---|
| 201 | j1 = 2 * (n / 2) - 1; |
---|
[772] | 202 | |
---|
| 203 | nc = n / 4; |
---|
| 204 | |
---|
[822] | 205 | for (c = 0; c < nc; c++) { |
---|
| 206 | draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c); |
---|
| 207 | X[1 + 2 * c ][0 + 2 * c ] = 0; |
---|
| 208 | X[1 + 2 * c + 1][0 + 2 * c + 1] = 1; |
---|
[772] | 209 | } |
---|
| 210 | |
---|
| 211 | // centre |
---|
| 212 | //X[n/2][n/2] = 1; |
---|
[822] | 213 | for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) { |
---|
| 214 | hline(X, c, j0 + 2 * nc, j1 - 2 * nc); |
---|
[772] | 215 | } |
---|
| 216 | } |
---|
[822] | 217 | |
---|
[772] | 218 | // -------------------------------------------------- |
---|
| 219 | void spirale_double(uint8 **X, int height, int width) |
---|
| 220 | // -------------------------------------------------- |
---|
| 221 | { |
---|
| 222 | int i0, j0; // point de depart haut |
---|
| 223 | int i1, j1; //point de depart haut |
---|
| 224 | int c, nc; // nombre de carres |
---|
| 225 | int n; //min(height, width) |
---|
| 226 | |
---|
| 227 | zero_ui8matrix(X, 0, height-1, 0, width-1); |
---|
| 228 | |
---|
[822] | 229 | if (height < width) { |
---|
[772] | 230 | n = height; |
---|
[822] | 231 | } |
---|
| 232 | else { |
---|
[772] | 233 | n = width; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | // correction |
---|
| 237 | //n = ((n-1) & (~0x3))+1; |
---|
| 238 | |
---|
[822] | 239 | i0 = 0; |
---|
| 240 | i1 = 2 * (n / 2) - 1; |
---|
| 241 | j0 = 0; |
---|
| 242 | j1 = 2 * (n / 2) - 1; |
---|
[772] | 243 | |
---|
| 244 | nc = n / 4; |
---|
| 245 | |
---|
[822] | 246 | for (c = 0; c < nc; c++) { |
---|
| 247 | draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c); |
---|
[772] | 248 | } |
---|
[822] | 249 | for (c = 0; c < nc; c++) { |
---|
| 250 | X[(i0 + 1) + (2 * c )][(j0) + (2 * c )] = 0; |
---|
| 251 | X[(i0 + 1) + (2 * c + 1)][(j0) + (2 * c + 1)] = 1; |
---|
[772] | 252 | |
---|
[822] | 253 | X[(i1 - 1) - (2 * c )][(j1) - (2 * c )] = 0; |
---|
| 254 | X[(i1 - 1) - (2 * c + 1)][(j1) - (2 * c + 1)] = 1; |
---|
[772] | 255 | } |
---|
| 256 | // centre |
---|
| 257 | //X[n/2][n/2] = 1; |
---|
[822] | 258 | for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) { |
---|
| 259 | hline(X, c, j0 + 2 * nc, j1 - 2 * nc); |
---|
[772] | 260 | } |
---|
| 261 | } |
---|
| 262 | // ------------------------ |
---|
| 263 | void routine_spirale(int n) |
---|
| 264 | // ------------------------ |
---|
| 265 | { |
---|
[822] | 266 | uint8 ** X; |
---|
| 267 | uint8 ** X255; |
---|
[772] | 268 | char filename[128]; |
---|
| 269 | //char *ptr = (char*) filename; |
---|
| 270 | |
---|
| 271 | int h, w; |
---|
| 272 | h = w = n; |
---|
| 273 | |
---|
[822] | 274 | X = ui8matrix(0, h - 1, 0, w - 1); |
---|
| 275 | X255 = ui8matrix(0, h - 1, 0, w - 1); |
---|
[772] | 276 | |
---|
[777] | 277 | snprintf(filename, 128, "spirale_simple_%d.pgm", n); |
---|
[772] | 278 | spirale_simple(X, h, w); |
---|
[822] | 279 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); |
---|
| 280 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); |
---|
[772] | 281 | |
---|
[777] | 282 | snprintf(filename, 128, "spirale_double_%d.pgm", n); |
---|
[772] | 283 | spirale_double(X, h, w); |
---|
[822] | 284 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); |
---|
| 285 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);/**/ |
---|
[772] | 286 | |
---|
[822] | 287 | free_ui8matrix(X, 0, h - 1, 0, w - 1); |
---|
| 288 | free_ui8matrix(X255, 0, h - 1, 0, w - 1); |
---|
[772] | 289 | } |
---|
[822] | 290 | |
---|
| 291 | // --------------------------------------- |
---|
| 292 | void test_spirale(int argc, char * argv[]) |
---|
| 293 | // --------------------------------------- |
---|
[772] | 294 | { |
---|
| 295 | routine_spirale(128); |
---|
| 296 | routine_spirale(127); |
---|
| 297 | routine_spirale(126); |
---|
| 298 | routine_spirale(125); |
---|
| 299 | |
---|
| 300 | routine_spirale(256); |
---|
| 301 | routine_spirale(512); |
---|
| 302 | routine_spirale(1024); |
---|
| 303 | } |
---|
[822] | 304 | |
---|
| 305 | // --------------------------------------------- |
---|
| 306 | int test_generation_HGH(int argc, char * argv[]) |
---|
| 307 | // --------------------------------------------- |
---|
[772] | 308 | { |
---|
[822] | 309 | uint8 ** X; |
---|
| 310 | uint8 ** X255; |
---|
[772] | 311 | char filename[32]; |
---|
| 312 | |
---|
| 313 | int h = 1280; |
---|
[822] | 314 | int w = 90 * 1024; |
---|
[772] | 315 | |
---|
| 316 | int border = 2; |
---|
| 317 | |
---|
| 318 | float d = 0.01; // density |
---|
| 319 | int g = 4; // granularity |
---|
| 320 | |
---|
| 321 | int seed = 0; |
---|
| 322 | |
---|
| 323 | //w = h; |
---|
| 324 | |
---|
[822] | 325 | X = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border); |
---|
| 326 | X255 = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border); |
---|
[772] | 327 | |
---|
[822] | 328 | generate_granularity_density_float(X, 0, h - 1, 0, w - 1, g, d, seed); |
---|
[777] | 329 | generate_granularity_density_name("HGH", g, d, filename, 32); |
---|
[772] | 330 | printf(filename); |
---|
[822] | 331 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255); |
---|
| 332 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); |
---|
[772] | 333 | |
---|
[822] | 334 | free_ui8matrix(X, 0 - border, h - 1 + border, 0 - border, w - 1 + border); |
---|
| 335 | free_ui8matrix(X255, 0 - border, h - 1 + border, 0 - border, w - 1 + border); |
---|
[772] | 336 | |
---|
| 337 | return 0; |
---|
| 338 | } |
---|
[822] | 339 | |
---|
| 340 | // --------------------------------------------- |
---|
| 341 | int image_analysis_2014(int argc, char * argv[]) |
---|
| 342 | // --------------------------------------------- |
---|
[772] | 343 | { |
---|
| 344 | // uint8 **X; |
---|
| 345 | // uint8 **X255; |
---|
| 346 | |
---|
| 347 | // char filename[32]; |
---|
| 348 | |
---|
| 349 | // uint32 **E32; //algo pixel |
---|
| 350 | // uint32 **E4; // algo LSL |
---|
| 351 | |
---|
| 352 | // uint32 *T, *A; // tables equivalence |
---|
| 353 | |
---|
| 354 | // // Label *label; |
---|
| 355 | |
---|
| 356 | // uint32 nemax = NEMAX; |
---|
| 357 | |
---|
| 358 | // int neamax = nemax; |
---|
| 359 | // int ncmax = 10; |
---|
| 360 | |
---|
| 361 | // int n = 1024; |
---|
| 362 | // int height, width; |
---|
| 363 | // int border = 2; |
---|
| 364 | // long i0, i1, j0, j1; |
---|
| 365 | |
---|
| 366 | // int d; // density |
---|
| 367 | // int dmin = 1; |
---|
| 368 | // int dmax = 99; |
---|
| 369 | // int dstep = 1; |
---|
| 370 | |
---|
| 371 | // int g; // granularity |
---|
| 372 | // int gmin = 1; |
---|
| 373 | // int gmax = 2; |
---|
| 374 | // int seed = 1; |
---|
| 375 | |
---|
| 376 | // uint32 na; |
---|
| 377 | // uint32 np_pixel, ne_pixel, na_pixel; |
---|
| 378 | // uint32 ns_segment, ne_segment, na_segment; |
---|
| 379 | // uint32 nb_step, nb_concavity; |
---|
| 380 | |
---|
| 381 | // n = 256; |
---|
| 382 | // n = 1024; |
---|
| 383 | // //n = 2048; |
---|
| 384 | // X = ui8matrix(0-border, n-1+border, 0-border, n-1+border); |
---|
| 385 | // X255 = ui8matrix(0-border, n-1+border, 0-border, n-1+border); |
---|
| 386 | |
---|
| 387 | // i0 = 0; i1 = n-1; j0 = 0; j1 = n-1; |
---|
| 388 | // height = n; width = n; |
---|
| 389 | |
---|
| 390 | // E32 = ui32matrix(i0-border, i1+border, j0-border, j1+border); |
---|
| 391 | // E4 = ui32matrix(i0-border, i1+border, j0-border, j1+border); |
---|
| 392 | // zero_ui32matrix(E32, i0-border, i1+border, j0-border, j1+border); |
---|
| 393 | // zero_ui32matrix(E4, i0-border, i1+border, j0-border, j1+border); |
---|
| 394 | |
---|
| 395 | // T = ui32vector(0, nemax); |
---|
| 396 | // A = ui32vector(0, nemax); |
---|
| 397 | |
---|
| 398 | // initT(T, nemax); |
---|
| 399 | // initT(A, nemax); |
---|
| 400 | |
---|
| 401 | // // label = Label_pConstructor_Empty(); |
---|
| 402 | // // Label_Set_ImageB(label, X); |
---|
| 403 | // // Label_Set_ImageL(label, E4); |
---|
| 404 | |
---|
| 405 | // // Label_Set_Parameters (label, width, height, neamax, ncmax); |
---|
| 406 | // // Label_Set_AlgorithmicParameters(label, 32, 8, LABEL_STDZ, LABEL_SELKOW); |
---|
| 407 | // // Label_Set_Optimisation(label, LABEL_RLEZ); |
---|
| 408 | // // Label_Initialize(label); |
---|
| 409 | // //Label_Enable_SecondLabeling(label); |
---|
| 410 | |
---|
| 411 | // printf("image %d x %d\n", n, n); |
---|
| 412 | |
---|
| 413 | // for(g=gmin; g<=gmax; g*=2) { |
---|
| 414 | |
---|
| 415 | // printf("----------------\n"); |
---|
| 416 | // printf("granulariry = %d\n", g); |
---|
| 417 | // printf("----------------\n"); |
---|
| 418 | |
---|
| 419 | // printf("%3s", "d"); |
---|
| 420 | |
---|
| 421 | // printf("%8s", "np"); |
---|
| 422 | // printf("%8s", "ne"); |
---|
| 423 | // printf("%8s", "na"); |
---|
| 424 | |
---|
| 425 | // printf("%6s", ""); |
---|
| 426 | |
---|
| 427 | // printf("%8s", "ns"); |
---|
| 428 | // printf("%8s", "ne"); |
---|
| 429 | // printf("%8s", "na"); |
---|
| 430 | |
---|
| 431 | // printf("%6s", ""); |
---|
| 432 | |
---|
| 433 | // printf("%8s", "nc"); |
---|
| 434 | // printf("%8s", "ns"); |
---|
| 435 | |
---|
| 436 | // printf(""); |
---|
| 437 | |
---|
| 438 | // for(d=dmin; d<=dmax; d+=dstep) { |
---|
| 439 | |
---|
| 440 | // zero_ui8matrix(X, 0, n-1, 0, n-1); |
---|
| 441 | // zero_ui32matrix(E32, 0, n-1, 0, n-1); |
---|
| 442 | // zero_ui32matrix(E4, 0, n-1, 0, n-1); |
---|
| 443 | // initT(T, nemax); |
---|
| 444 | // initT(A, nemax); |
---|
| 445 | // //printf("seed = %d\n", seed); |
---|
| 446 | // generate_granularity_density_int(X, 0, n-1, 0, n-1, g, d, seed); |
---|
| 447 | |
---|
| 448 | // //na = Rosenfeld_Analysis_8C(X, height, width, E32, T, A, nemax, Stats); |
---|
| 449 | // na = Rosenfeld_Analysis_8C(X, height, width, E32, T, A, nemax, &np_pixel, &ne_pixel, &na_pixel); |
---|
| 450 | // //Label32_Rosenfeld8_Features_SPEED(label); |
---|
| 451 | |
---|
| 452 | // ns_segment = label->ns; |
---|
| 453 | // ne_segment = label->nea; |
---|
| 454 | // na_segment = label->na; |
---|
| 455 | |
---|
| 456 | // nb_concavity = ne_segment - na_segment; |
---|
| 457 | // nb_step = ne_pixel - ne_segment; |
---|
| 458 | |
---|
| 459 | // printf("%3d", d); |
---|
| 460 | |
---|
| 461 | // printf("%8d", np_pixel); |
---|
| 462 | // printf("%8d", ne_pixel); |
---|
| 463 | // printf("%8d", na_pixel); |
---|
| 464 | |
---|
| 465 | // printf("%6s", ""); |
---|
| 466 | |
---|
| 467 | // printf("%8d", ns_segment); |
---|
| 468 | // printf("%8d", ne_segment); |
---|
| 469 | // printf("%8d", na_segment); |
---|
| 470 | |
---|
| 471 | // printf("%6s", ""); |
---|
| 472 | |
---|
| 473 | // printf("%8d", nb_concavity); |
---|
| 474 | // printf("%8d", nb_step); |
---|
| 475 | |
---|
| 476 | // printf(""); |
---|
| 477 | // } |
---|
| 478 | // printf(""); |
---|
| 479 | // } |
---|
| 480 | // free_ui8matrix(X, 0-border, n-1+border, 0-border, n-1+border); |
---|
| 481 | // free_ui8matrix(X255, 0-border, n-1+border, 0-border, n-1+border); |
---|
| 482 | |
---|
| 483 | return 0; |
---|
| 484 | } |
---|
| 485 | // -------------------------- |
---|
| 486 | void test_generation_mt(void) |
---|
| 487 | // -------------------------- |
---|
| 488 | { |
---|
[822] | 489 | int n = 32; |
---|
[772] | 490 | |
---|
| 491 | printf("---------------------------"); |
---|
| 492 | printf("-- test_mersenne_twister --"); |
---|
| 493 | printf("---------------------------"); |
---|
| 494 | |
---|
| 495 | |
---|
| 496 | init_genrand(0); |
---|
[822] | 497 | for (int i = 0; i < n; i++) { |
---|
[772] | 498 | printf("%10lu ", genrand_int32()); |
---|
[822] | 499 | if (i % 8 == 7) { |
---|
| 500 | printf("\n"); |
---|
| 501 | } |
---|
[772] | 502 | } |
---|
| 503 | printf("\n---"); |
---|
| 504 | |
---|
| 505 | init_genrand(1); |
---|
[822] | 506 | for (int i = 0; i < n; i++) { |
---|
[772] | 507 | printf("%10lu ", genrand_int32()); |
---|
[822] | 508 | if (i % 8== 7) { |
---|
| 509 | printf("\n"); |
---|
| 510 | } |
---|
[772] | 511 | } |
---|
| 512 | printf("\n---"); |
---|
| 513 | |
---|
| 514 | init_genrand(0); |
---|
[822] | 515 | for (int i = 0; i < n; i++) { |
---|
[772] | 516 | printf("%10lu ", genrand_int32()); |
---|
[822] | 517 | if (i % 8== 7) { |
---|
| 518 | printf("\n"); |
---|
| 519 | } |
---|
[772] | 520 | } |
---|
| 521 | printf("\n---"); |
---|
| 522 | |
---|
| 523 | init_genrand(1); |
---|
[822] | 524 | for (int i = 0; i < n; i++) { |
---|
[772] | 525 | printf("%10lu ", genrand_int32()); |
---|
[822] | 526 | if (i % 8 == 7) { |
---|
| 527 | printf("\n"); |
---|
| 528 | } |
---|
[772] | 529 | } |
---|
| 530 | } |
---|
[822] | 531 | |
---|
| 532 | // -------------------------------------- |
---|
| 533 | void image_zoom2(int argc, char * argv[]) |
---|
| 534 | // -------------------------------------- |
---|
[772] | 535 | { |
---|
[822] | 536 | uint8 x, ** X, ** Y; |
---|
| 537 | int i0, i1, j0, j1; |
---|
[772] | 538 | int height, width; |
---|
[822] | 539 | char * src_filename; |
---|
| 540 | char * dst_filename; |
---|
[772] | 541 | |
---|
[822] | 542 | if (argc < 3) { |
---|
[772] | 543 | printf("too few arguments"); |
---|
| 544 | printf("%s src.pgm dst.pgm\n", argv[0]); |
---|
| 545 | return; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | src_filename = argv[1]; |
---|
| 549 | dst_filename = argv[2]; |
---|
| 550 | |
---|
| 551 | X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1); |
---|
| 552 | |
---|
[822] | 553 | height = i1 - i0 + 1; |
---|
| 554 | width = j1 - j0 + 1; |
---|
[772] | 555 | |
---|
| 556 | printf("width = %d height = %d\n", width, height); |
---|
| 557 | |
---|
[822] | 558 | Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1); |
---|
[772] | 559 | |
---|
[822] | 560 | for (int i = 0; i <= height - 1; i++) { |
---|
| 561 | for (int j = 0; j <= width - 1; j++) { |
---|
[772] | 562 | x = X[i][j]; |
---|
[822] | 563 | Y[2 * i + 0][2 * j + 0] = x; |
---|
| 564 | Y[2 * i + 0][2 * j + 1] = x; |
---|
| 565 | Y[2 * i + 1][2 * j + 0] = x; |
---|
| 566 | Y[2 * i + 1][2 * j + 1] = x; |
---|
[772] | 567 | } |
---|
| 568 | } |
---|
[822] | 569 | SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename); |
---|
[772] | 570 | |
---|
[822] | 571 | free_ui8matrix(X, 0, height - 1, 0, width - 1); |
---|
| 572 | free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1); |
---|
[772] | 573 | } |
---|
[822] | 574 | |
---|
| 575 | |
---|
| 576 | // --------------------------------------------- |
---|
| 577 | void image_duplication2(int argc, char * argv[]) |
---|
| 578 | // --------------------------------------------- |
---|
[772] | 579 | { |
---|
[822] | 580 | uint8 x, ** X, ** Y; |
---|
| 581 | int i0, i1, j0, j1; |
---|
[772] | 582 | int height, width; |
---|
[822] | 583 | char * src_filename; |
---|
| 584 | char * dst_filename; |
---|
[772] | 585 | |
---|
| 586 | if (argc < 3) { |
---|
| 587 | printf("too few arguments"); |
---|
| 588 | printf("%s src.pgm dst.pgm\n", argv[0]); |
---|
| 589 | return; |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | src_filename = argv[1]; |
---|
| 593 | dst_filename = argv[2]; |
---|
| 594 | |
---|
| 595 | X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1); |
---|
| 596 | |
---|
[822] | 597 | height = i1 - i0 + 1; |
---|
| 598 | width = j1 - j0 + 1; |
---|
[772] | 599 | |
---|
| 600 | printf("width = %d height = %d\n", width, height); |
---|
| 601 | |
---|
[822] | 602 | Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1); |
---|
[772] | 603 | |
---|
| 604 | // horizontal duplication |
---|
[822] | 605 | for (int i = 0; i <= height - 1; i++) { |
---|
| 606 | for (int j = 0; j <= width - 1; j++) { |
---|
[772] | 607 | x = X[i][j]; |
---|
[822] | 608 | Y[i][width + j] = x; |
---|
[772] | 609 | } |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | // vertical duplication |
---|
[822] | 613 | for (int i = 0; i <= height - 1; i++) { |
---|
| 614 | for (int j = 0; j <= 2 * width - 1; j++) { |
---|
[772] | 615 | x = X[i][j]; |
---|
[822] | 616 | Y[height + i][j] = x; |
---|
[772] | 617 | } |
---|
| 618 | } |
---|
[822] | 619 | SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename); |
---|
[772] | 620 | |
---|
[822] | 621 | free_ui8matrix(X, 0, height - 1, 0, width - 1); |
---|
| 622 | free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1); |
---|
[772] | 623 | } |
---|
[822] | 624 | |
---|
| 625 | |
---|
| 626 | |
---|
| 627 | |
---|