| 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 |
|
|---|
| 24 |
|
|---|
| 25 | // --------------------------------------------------------------------------------------------------------------------------
|
|---|
| 26 | void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)
|
|---|
| 27 | // --------------------------------------------------------------------------------------------------------------------------
|
|---|
| 28 | {
|
|---|
| 29 | uint8 x;
|
|---|
| 30 | double r;
|
|---|
| 31 |
|
|---|
| 32 | //srand(seed); // pour toujours generer les meme sequences
|
|---|
| 33 | init_genrand(seed);
|
|---|
| 34 |
|
|---|
| 35 | for (int i = i0; i <= i1; i += granularity) {
|
|---|
| 36 | for (int j = j0; j <= j1; j += granularity) {
|
|---|
| 37 |
|
|---|
| 38 | //r = 100.0*(double)rand() / rmax;
|
|---|
| 39 | //r = 100.0*(double)rand() / rmax;
|
|---|
| 40 | r = 100.0 * (double) genrand_real2();
|
|---|
| 41 | if (r <= density) {
|
|---|
| 42 | x = 1;
|
|---|
| 43 | }
|
|---|
| 44 | else {
|
|---|
| 45 | x = 0;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 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 | }
|
|---|
| 53 | } // dj
|
|---|
| 54 | } // di
|
|---|
| 55 | } // j
|
|---|
| 56 | } // i
|
|---|
| 57 | }
|
|---|
| 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 | // ----------------------------------------------------------------------------------------------------------------------
|
|---|
| 62 | {
|
|---|
| 63 | generate_granularity_density_float(X, i0, i1, j0, j1, granularity, (float) density, seed);
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | // -----------------------------------------------------------------------------------------------------------
|
|---|
| 67 | void generate_granularity_density_name(char * name, int granularity, int density, char * filename, int maxlen)
|
|---|
| 68 | // -----------------------------------------------------------------------------------------------------------
|
|---|
| 69 | {
|
|---|
| 70 | snprintf(filename, maxlen, "%s_%02d_%03d.pgm", name, granularity, density);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | // ---------------------------------------------------------------------------------------------------------------------------------
|
|---|
| 74 | void generate_granularity_density_ext_name(char * name, int granularity, int density, char * extension, char * filename, int maxlen)
|
|---|
| 75 | // ---------------------------------------------------------------------------------------------------------------------------------
|
|---|
| 76 | {
|
|---|
| 77 | snprintf(filename, maxlen, "%s_%02d_%03d.%s", name, granularity, density, extension);
|
|---|
| 78 | }
|
|---|
| 79 | // --------------------------------------------------------------------------------------------------------------------------
|
|---|
| 80 | void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char * filename, int maxlen)
|
|---|
| 81 | // --------------------------------------------------------------------------------------------------------------------------
|
|---|
| 82 | {
|
|---|
| 83 | snprintf(filename, maxlen, "%s_%d_%02d_%03d.pgm", name, size, granularity, density);
|
|---|
| 84 | }
|
|---|
| 85 | // -----------------------------------------------------------------------------------------------------------------------------------------------
|
|---|
| 86 | void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char * filename, int maxlen)
|
|---|
| 87 | // -----------------------------------------------------------------------------------------------------------------------------------------------
|
|---|
| 88 | {
|
|---|
| 89 | snprintf(filename, maxlen, "%s_%d_%02d_%03d.%s", name, size, granularity, density, extension);
|
|---|
| 90 | }
|
|---|
| 91 | // -----------------------------------------------------------------------------------------------------
|
|---|
| 92 | void generate_size_granularity_name(char * name, int size, int granularity, char * filename, int maxlen)
|
|---|
| 93 | // -----------------------------------------------------------------------------------------------------
|
|---|
| 94 | {
|
|---|
| 95 | snprintf(filename, maxlen, "%s_%d_%02d.pgm", name, size, granularity);
|
|---|
| 96 | }// ------------------------------------------------------------------------------------------
|
|---|
| 97 | void generate_name100(char * name, int granularity, float density, char *filename, int maxlen)
|
|---|
| 98 | // -------------------------------------------------------------------------------------------
|
|---|
| 99 | {
|
|---|
| 100 | // density en pourcentage: 0:100
|
|---|
| 101 | // mais aussi <1, par exe 0.01
|
|---|
| 102 | int d = (int) ceil(100 * density);
|
|---|
| 103 | snprintf(filename, maxlen, "%s_%02d_%05d.pgm", name, granularity, d);
|
|---|
| 104 | }
|
|---|
| 105 | // ----------------------------------------
|
|---|
| 106 | int test_generation(int argc, char * argv[])
|
|---|
| 107 | // ----------------------------------------
|
|---|
| 108 | {
|
|---|
| 109 | uint8 ** X;
|
|---|
| 110 | uint8 ** X255;
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 133 |
|
|---|
| 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);
|
|---|
| 137 | generate_granularity_density_name("I", g, d, filename, 32);
|
|---|
| 138 | printf(filename);
|
|---|
| 139 | bin2gray_ui8matrix(X, 0, n - 1, 0, n - 1, X255);
|
|---|
| 140 | SavePGM_ui8matrix(X255, 0, n - 1, 0, n - 1, filename);
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 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);
|
|---|
| 145 |
|
|---|
| 146 | return 0;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | // ------------------------------------------
|
|---|
| 150 | void hline(uint8 ** X, int i, int j0, int j1)
|
|---|
| 151 | // ------------------------------------------
|
|---|
| 152 | {
|
|---|
| 153 | for (int j = j0; j <= j1; j++) {
|
|---|
| 154 | X[i][j] = 1;
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 | // ------------------------------------------
|
|---|
| 158 | void vline(uint8 ** X, int i0, int i1, int j)
|
|---|
| 159 | // ------------------------------------------
|
|---|
| 160 | {
|
|---|
| 161 | for (int i = i0; i <= i1; i++) {
|
|---|
| 162 | X[i][j] = 1;
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // ------------------------------------------------------------
|
|---|
| 167 | void draw_rectangle(uint8 ** X, int i0, int i1, int j0, int j1)
|
|---|
| 168 | // ------------------------------------------------------------
|
|---|
| 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 | }
|
|---|
| 175 |
|
|---|
| 176 | // ---------------------------------------------------
|
|---|
| 177 | void spirale_simple(uint8 ** X, int height, int width)
|
|---|
| 178 | // ---------------------------------------------------
|
|---|
| 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 |
|
|---|
| 185 | zero_ui8matrix(X, 0, height - 1, 0, width - 1);
|
|---|
| 186 |
|
|---|
| 187 | if (height < width) {
|
|---|
| 188 | n = height;
|
|---|
| 189 | }
|
|---|
| 190 | else {
|
|---|
| 191 | n = width;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // sans correction
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | // avec correction
|
|---|
| 198 | i0 = 0;
|
|---|
| 199 | i1 = 2 * (n / 2) - 1;
|
|---|
| 200 | j0 = 0;
|
|---|
| 201 | j1 = 2 * (n / 2) - 1;
|
|---|
| 202 |
|
|---|
| 203 | nc = n / 4;
|
|---|
| 204 |
|
|---|
| 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;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | // centre
|
|---|
| 212 | //X[n/2][n/2] = 1;
|
|---|
| 213 | for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
|
|---|
| 214 | hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 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 |
|
|---|
| 229 | if (height < width) {
|
|---|
| 230 | n = height;
|
|---|
| 231 | }
|
|---|
| 232 | else {
|
|---|
| 233 | n = width;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | // correction
|
|---|
| 237 | //n = ((n-1) & (~0x3))+1;
|
|---|
| 238 |
|
|---|
| 239 | i0 = 0;
|
|---|
| 240 | i1 = 2 * (n / 2) - 1;
|
|---|
| 241 | j0 = 0;
|
|---|
| 242 | j1 = 2 * (n / 2) - 1;
|
|---|
| 243 |
|
|---|
| 244 | nc = n / 4;
|
|---|
| 245 |
|
|---|
| 246 | for (c = 0; c < nc; c++) {
|
|---|
| 247 | draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c);
|
|---|
| 248 | }
|
|---|
| 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;
|
|---|
| 252 |
|
|---|
| 253 | X[(i1 - 1) - (2 * c )][(j1) - (2 * c )] = 0;
|
|---|
| 254 | X[(i1 - 1) - (2 * c + 1)][(j1) - (2 * c + 1)] = 1;
|
|---|
| 255 | }
|
|---|
| 256 | // centre
|
|---|
| 257 | //X[n/2][n/2] = 1;
|
|---|
| 258 | for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
|
|---|
| 259 | hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
|
|---|
| 260 | }
|
|---|
| 261 | }
|
|---|
| 262 | // ------------------------
|
|---|
| 263 | void routine_spirale(int n)
|
|---|
| 264 | // ------------------------
|
|---|
| 265 | {
|
|---|
| 266 | uint8 ** X;
|
|---|
| 267 | uint8 ** X255;
|
|---|
| 268 | char filename[128];
|
|---|
| 269 | //char *ptr = (char*) filename;
|
|---|
| 270 |
|
|---|
| 271 | int h, w;
|
|---|
| 272 | h = w = n;
|
|---|
| 273 |
|
|---|
| 274 | X = ui8matrix(0, h - 1, 0, w - 1);
|
|---|
| 275 | X255 = ui8matrix(0, h - 1, 0, w - 1);
|
|---|
| 276 |
|
|---|
| 277 | snprintf(filename, 128, "spirale_simple_%d.pgm", n);
|
|---|
| 278 | spirale_simple(X, h, w);
|
|---|
| 279 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255);
|
|---|
| 280 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);
|
|---|
| 281 |
|
|---|
| 282 | snprintf(filename, 128, "spirale_double_%d.pgm", n);
|
|---|
| 283 | spirale_double(X, h, w);
|
|---|
| 284 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255);
|
|---|
| 285 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);/**/
|
|---|
| 286 |
|
|---|
| 287 | free_ui8matrix(X, 0, h - 1, 0, w - 1);
|
|---|
| 288 | free_ui8matrix(X255, 0, h - 1, 0, w - 1);
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | // ---------------------------------------
|
|---|
| 292 | void test_spirale(int argc, char * argv[])
|
|---|
| 293 | // ---------------------------------------
|
|---|
| 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 | }
|
|---|
| 304 |
|
|---|
| 305 | // ---------------------------------------------
|
|---|
| 306 | int test_generation_HGH(int argc, char * argv[])
|
|---|
| 307 | // ---------------------------------------------
|
|---|
| 308 | {
|
|---|
| 309 | uint8 ** X;
|
|---|
| 310 | uint8 ** X255;
|
|---|
| 311 | char filename[32];
|
|---|
| 312 |
|
|---|
| 313 | int h = 1280;
|
|---|
| 314 | int w = 90 * 1024;
|
|---|
| 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 |
|
|---|
| 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);
|
|---|
| 327 |
|
|---|
| 328 | generate_granularity_density_float(X, 0, h - 1, 0, w - 1, g, d, seed);
|
|---|
| 329 | generate_granularity_density_name("HGH", g, d, filename, 32);
|
|---|
| 330 | printf(filename);
|
|---|
| 331 | bin2gray_ui8matrix(X, 0, h - 1, 0, w - 1, X255);
|
|---|
| 332 | SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);
|
|---|
| 333 |
|
|---|
| 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);
|
|---|
| 336 |
|
|---|
| 337 | return 0;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | // ---------------------------------------------
|
|---|
| 341 | int image_analysis_2014(int argc, char * argv[])
|
|---|
| 342 | // ---------------------------------------------
|
|---|
| 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 | {
|
|---|
| 489 | int n = 32;
|
|---|
| 490 |
|
|---|
| 491 | printf("---------------------------");
|
|---|
| 492 | printf("-- test_mersenne_twister --");
|
|---|
| 493 | printf("---------------------------");
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 | init_genrand(0);
|
|---|
| 497 | for (int i = 0; i < n; i++) {
|
|---|
| 498 | printf("%10lu ", genrand_int32());
|
|---|
| 499 | if (i % 8 == 7) {
|
|---|
| 500 | printf("\n");
|
|---|
| 501 | }
|
|---|
| 502 | }
|
|---|
| 503 | printf("\n---");
|
|---|
| 504 |
|
|---|
| 505 | init_genrand(1);
|
|---|
| 506 | for (int i = 0; i < n; i++) {
|
|---|
| 507 | printf("%10lu ", genrand_int32());
|
|---|
| 508 | if (i % 8== 7) {
|
|---|
| 509 | printf("\n");
|
|---|
| 510 | }
|
|---|
| 511 | }
|
|---|
| 512 | printf("\n---");
|
|---|
| 513 |
|
|---|
| 514 | init_genrand(0);
|
|---|
| 515 | for (int i = 0; i < n; i++) {
|
|---|
| 516 | printf("%10lu ", genrand_int32());
|
|---|
| 517 | if (i % 8== 7) {
|
|---|
| 518 | printf("\n");
|
|---|
| 519 | }
|
|---|
| 520 | }
|
|---|
| 521 | printf("\n---");
|
|---|
| 522 |
|
|---|
| 523 | init_genrand(1);
|
|---|
| 524 | for (int i = 0; i < n; i++) {
|
|---|
| 525 | printf("%10lu ", genrand_int32());
|
|---|
| 526 | if (i % 8 == 7) {
|
|---|
| 527 | printf("\n");
|
|---|
| 528 | }
|
|---|
| 529 | }
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | // --------------------------------------
|
|---|
| 533 | void image_zoom2(int argc, char * argv[])
|
|---|
| 534 | // --------------------------------------
|
|---|
| 535 | {
|
|---|
| 536 | uint8 x, ** X, ** Y;
|
|---|
| 537 | int i0, i1, j0, j1;
|
|---|
| 538 | int height, width;
|
|---|
| 539 | char * src_filename;
|
|---|
| 540 | char * dst_filename;
|
|---|
| 541 |
|
|---|
| 542 | if (argc < 3) {
|
|---|
| 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 |
|
|---|
| 553 | height = i1 - i0 + 1;
|
|---|
| 554 | width = j1 - j0 + 1;
|
|---|
| 555 |
|
|---|
| 556 | printf("width = %d height = %d\n", width, height);
|
|---|
| 557 |
|
|---|
| 558 | Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
|
|---|
| 559 |
|
|---|
| 560 | for (int i = 0; i <= height - 1; i++) {
|
|---|
| 561 | for (int j = 0; j <= width - 1; j++) {
|
|---|
| 562 | x = X[i][j];
|
|---|
| 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;
|
|---|
| 567 | }
|
|---|
| 568 | }
|
|---|
| 569 | SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
|
|---|
| 570 |
|
|---|
| 571 | free_ui8matrix(X, 0, height - 1, 0, width - 1);
|
|---|
| 572 | free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 |
|
|---|
| 576 | // ---------------------------------------------
|
|---|
| 577 | void image_duplication2(int argc, char * argv[])
|
|---|
| 578 | // ---------------------------------------------
|
|---|
| 579 | {
|
|---|
| 580 | uint8 x, ** X, ** Y;
|
|---|
| 581 | int i0, i1, j0, j1;
|
|---|
| 582 | int height, width;
|
|---|
| 583 | char * src_filename;
|
|---|
| 584 | char * dst_filename;
|
|---|
| 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 |
|
|---|
| 597 | height = i1 - i0 + 1;
|
|---|
| 598 | width = j1 - j0 + 1;
|
|---|
| 599 |
|
|---|
| 600 | printf("width = %d height = %d\n", width, height);
|
|---|
| 601 |
|
|---|
| 602 | Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
|
|---|
| 603 |
|
|---|
| 604 | // horizontal duplication
|
|---|
| 605 | for (int i = 0; i <= height - 1; i++) {
|
|---|
| 606 | for (int j = 0; j <= width - 1; j++) {
|
|---|
| 607 | x = X[i][j];
|
|---|
| 608 | Y[i][width + j] = x;
|
|---|
| 609 | }
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | // vertical duplication
|
|---|
| 613 | for (int i = 0; i <= height - 1; i++) {
|
|---|
| 614 | for (int j = 0; j <= 2 * width - 1; j++) {
|
|---|
| 615 | x = X[i][j];
|
|---|
| 616 | Y[height + i][j] = x;
|
|---|
| 617 | }
|
|---|
| 618 | }
|
|---|
| 619 | SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
|
|---|
| 620 |
|
|---|
| 621 | free_ui8matrix(X, 0, height - 1, 0, width - 1);
|
|---|
| 622 | free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
|
|---|
| 627 |
|
|---|