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