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