質問編集履歴
5
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
プログラムを全てはっていますが、メイン分のzyusin関数以外は全て完成しているので
|
2
|
-
|
3
|
-
zyusin関数
|
1
|
+
zyusin関数が全く機能していないみたいです。
|
4
|
-
|
5
|
-
先生から元々あるプログラムを真似しながら重心を求める関数を作ってみなさいと言われたのですがコンパイルは通るもののzyusin関数が全く機能していないみたいです。
|
6
2
|
|
7
3
|
どうか助けてください。
|
8
4
|
|
4
いろいろ
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,652 +78,258 @@
|
|
78
78
|
|
79
79
|
メイン部分
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
fputimg(stdout, img);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
printf("Filtering with (l_i, u_i). (Eq.(4))\n");
|
156
|
-
|
157
|
-
himg = func_h_i(img, param);
|
158
|
-
|
159
|
-
fputimg(stdout, himg);
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
printf("Merging and binarizing. (Eqs. (3) and (2))\n");
|
164
|
-
|
165
|
-
hhimg = func_h(himg);
|
166
|
-
|
167
|
-
fputimg(stdout, hhimg);
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
printf("Averaging. (Eq.(5))\n");
|
174
|
-
|
175
|
-
aimg = func_av(hhimg, param);
|
176
|
-
|
177
|
-
fputimg_uni(stdout, aimg, 0);
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
printf("Binarizing. (Eq.(6))\n");
|
182
|
-
|
183
|
-
bimg = func_bin(aimg, param);
|
184
|
-
|
185
|
-
fputimg_uni(stdout, bimg, 0);
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
printf("Labeling.\n");
|
190
|
-
|
191
|
-
limg = lbl(bimg);
|
192
|
-
|
193
|
-
fputimg_uni(stdout, limg, 0);
|
194
|
-
|
195
|
-
********新たにfputzを追加しました!!!!****
|
196
|
-
|
197
|
-
printf("zyusin.\n");
|
198
|
-
|
199
|
-
z=zyusin(limg);
|
200
|
-
|
201
|
-
fputz(stdout,z);
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
return 0;
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
*****新たに変えました**
|
86
|
+
|
87
|
+
ラベル数に応じて返す値を増やしたりしたいのですがそこができません
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
Zahyou zyusin(Img img){
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
Zahyou zahyou;
|
98
|
+
|
99
|
+
int sx,sy;
|
100
|
+
|
101
|
+
int x,y,label1x=0,label1y=0,label2x=0,label2y=0,label3x=0,label3y=0,label4x=0,label4y=0;
|
102
|
+
|
103
|
+
int label1=0,label2=0,label3=0,label4=0;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
img.sx=sx; img.sy=sy;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
for(y=0;y<sy;y++){
|
116
|
+
|
117
|
+
for(x=0;x<sx;x++){
|
118
|
+
|
119
|
+
if(img.d[0][y][x]==1){
|
120
|
+
|
121
|
+
label1++;
|
122
|
+
|
123
|
+
label1x=label1x+x;
|
124
|
+
|
125
|
+
label1y=label1y+y;
|
126
|
+
|
127
|
+
}else if(img.d[0][y][x]==2){
|
128
|
+
|
129
|
+
label2++;
|
130
|
+
|
131
|
+
label2x=label2x+x;
|
132
|
+
|
133
|
+
label2y=label2y+y;
|
134
|
+
|
135
|
+
}else if(img.d[0][y][x]==3){
|
136
|
+
|
137
|
+
label3++;
|
138
|
+
|
139
|
+
label3x=label3x+x;
|
140
|
+
|
141
|
+
label3y=label3y+y;
|
142
|
+
|
143
|
+
}else if(img.d[0][y][x]==4){
|
144
|
+
|
145
|
+
label4++;
|
146
|
+
|
147
|
+
label4x=label4x+x;
|
148
|
+
|
149
|
+
label4y=label4y+y;
|
206
150
|
|
207
151
|
}
|
208
152
|
|
209
|
-
|
210
|
-
|
211
|
-
Img func_bin(Img img, Param p) {
|
212
|
-
|
213
|
-
省略
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
return bimg;
|
218
|
-
|
219
153
|
}
|
220
154
|
|
221
|
-
|
222
|
-
|
223
|
-
Img func_av(Img img, Param p) {
|
224
|
-
|
225
|
-
省略
|
226
|
-
|
227
|
-
return aimg;
|
228
|
-
|
229
155
|
}
|
230
156
|
|
231
157
|
|
232
158
|
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
233
|
-
|
165
|
+
label1x=label1x/label1;
|
166
|
+
|
234
|
-
|
167
|
+
label1y=label1y/label1;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
label2x=label2x/label2;
|
174
|
+
|
175
|
+
label2y=label2y/label2;
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
label3x=label3x/label3;
|
182
|
+
|
183
|
+
label3y=label3y/label3;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
label4x=label4x/label4;
|
190
|
+
|
191
|
+
label4y=label4y/label4;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
235
|
-
|
197
|
+
Zahyou.px=label1x;
|
198
|
+
|
236
|
-
|
199
|
+
Zahyou.py=label1y;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
237
|
-
|
205
|
+
return zahyou;
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
******新たに追加しました*****
|
224
|
+
|
225
|
+
void fputz(FILE *fp, Zahyou zahyou){
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
int i;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
for(i=0;i<4;i++){ //4はラベルの数だけ分にしたい今回の例だと2
|
234
|
+
|
235
|
+
fprintf(fp,"%d %d",zahyou.px,zahyou.py);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
fprintf(fp,"\n");
|
244
|
+
|
245
|
+
|
238
246
|
|
239
247
|
}
|
240
248
|
|
241
249
|
|
242
250
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
Zahyou zyusin(Img img){
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
Zahyou zahyou;
|
292
|
-
|
293
|
-
int sx,sy;
|
294
|
-
|
295
|
-
int x,y,label1x=0,label1y=0,label2x=0,label2y=0,label3x=0,label3y=0,label4x=0,label4y=0;
|
296
|
-
|
297
|
-
int label1=0,label2=0,label3=0,label4=0;
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
img.sx=sx; img.sy=sy;
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
for(y=0;y<sy;y++){
|
310
|
-
|
311
|
-
for(x=0;x<sx;x++){
|
312
|
-
|
313
|
-
if(img.d[0][y][x]==1){
|
314
|
-
|
315
|
-
label1++;
|
316
|
-
|
317
|
-
label1x=label1x+x;
|
318
|
-
|
319
|
-
label1y=label1y+y;
|
320
|
-
|
321
|
-
}else if(img.d[0][y][x]==2){
|
322
|
-
|
323
|
-
label2++;
|
324
|
-
|
325
|
-
label2x=label2x+x;
|
326
|
-
|
327
|
-
label2y=label2y+y;
|
328
|
-
|
329
|
-
}else if(img.d[0][y][x]==3){
|
330
|
-
|
331
|
-
label3++;
|
332
|
-
|
333
|
-
label3x=label3x+x;
|
334
|
-
|
335
|
-
label3y=label3y+y;
|
336
|
-
|
337
|
-
}else if(img.d[0][y][x]==4){
|
338
|
-
|
339
|
-
label4++;
|
340
|
-
|
341
|
-
label4x=label4x+x;
|
342
|
-
|
343
|
-
label4y=label4y+y;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
label1x=label1x/label1;
|
360
|
-
|
361
|
-
label1y=label1y/label1;
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
label2x=label2x/label2;
|
368
|
-
|
369
|
-
label2y=label2y/label2;
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
label3x=label3x/label3;
|
376
|
-
|
377
|
-
label3y=label3y/label3;
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
label4x=label4x/label4;
|
384
|
-
|
385
|
-
label4y=label4y/label4;
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
Zahyou.px=label1x;
|
392
|
-
|
393
|
-
Zahyou.py=label1y;
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
return zahyou;
|
400
|
-
|
401
|
-
|
251
|
+
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
```ここに言語を入力
|
268
|
+
|
269
|
+
格納される部分
|
270
|
+
|
271
|
+
#define MAX 255
|
272
|
+
|
273
|
+
#define MX 20
|
274
|
+
|
275
|
+
#define MY 20
|
276
|
+
|
277
|
+
#define R 0
|
278
|
+
|
279
|
+
#define G 1
|
280
|
+
|
281
|
+
#define B 2
|
282
|
+
|
283
|
+
#define MC 3
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
typedef struct zahyou{
|
402
290
|
|
403
291
|
|
404
292
|
|
293
|
+
int px,py;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
405
|
-
|
299
|
+
} Zahyou;
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
300
|
+
|
301
|
+
|
302
|
+
|
413
|
-
|
303
|
+
typedef struct img {
|
414
304
|
|
415
305
|
int sx, sy;
|
416
306
|
|
307
|
+
int d[MC][MY][MX];
|
308
|
+
|
309
|
+
} Img;
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
typedef struct param {
|
314
|
+
|
315
|
+
int low[MC], up[MC];
|
316
|
+
|
417
|
-
int
|
317
|
+
int n, t;
|
318
|
+
|
418
|
-
|
319
|
+
} Param;
|
419
|
-
|
420
|
-
|
320
|
+
|
321
|
+
|
322
|
+
|
421
|
-
|
323
|
+
Img fgetimg(FILE *);
|
422
|
-
|
423
|
-
|
324
|
+
|
424
|
-
|
425
|
-
|
325
|
+
Param fgetparam(FILE *);
|
426
|
-
|
326
|
+
|
427
|
-
|
327
|
+
void fputimg(FILE *, Img);
|
428
|
-
|
429
|
-
|
328
|
+
|
430
|
-
|
431
|
-
}
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
void fputimg_uni(FILE *
|
329
|
+
void fputimg_uni(FILE *, Img, int);
|
436
|
-
|
437
|
-
|
330
|
+
|
438
|
-
|
439
|
-
int x, y;
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
sx = img.sx; sy = img.sy;
|
444
|
-
|
445
|
-
for(y = 0; y < sy; y++) {
|
446
|
-
|
447
|
-
for(x = 0; x < sx; x++) {
|
448
|
-
|
449
|
-
fprintf(fp, "%3d ", img.d[c][y][x]);
|
450
|
-
|
451
|
-
}
|
452
|
-
|
453
|
-
fprintf(fp, "\n");
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
fprintf(fp, "\n");
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
******新たに追加しました*****
|
466
|
-
|
467
|
-
void fputz(FILE *
|
331
|
+
void fputz(FILE *, Zahyou);
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
int i;
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
for(i=0;i<4;i++){ //4はラベルの数だけ分にしたい今回の例だと2
|
476
|
-
|
477
|
-
fprintf(fp,"%d %d",zahyou.px,zahyou.py);
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
fprintf(fp,"\n");
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
}
|
490
|
-
|
491
|
-
|
492
332
|
|
493
333
|
|
494
334
|
|
495
335
|
```
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
```
|
504
|
-
|
505
|
-
ラベリング部分 ここは質問とは関係ないですが参考にして考えろと言われたところです
|
506
|
-
|
507
|
-
#include <stdio.h>
|
508
|
-
|
509
|
-
#include "img.h"
|
510
|
-
|
511
|
-
#define NBR 4
|
512
|
-
|
513
|
-
#define TBLSIZ 63
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
int nbrlbl(Img img, Img limg, int x, int y, int l[]) {
|
518
|
-
|
519
|
-
int ml, i;
|
520
|
-
|
521
|
-
int sx, sy;
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
sx = img.sx; sy = img.sy;
|
526
|
-
|
527
|
-
l[3] = x > 0 ? limg.d[0][y][x-1] : 0;
|
528
|
-
|
529
|
-
if(y > 0) {
|
530
|
-
|
531
|
-
l[1] = limg.d[0][y-1][x];
|
532
|
-
|
533
|
-
l[0] = x > 0 ? limg.d[0][y-1][x-1] : 0;
|
534
|
-
|
535
|
-
l[2] = x < sx - 1 ? limg.d[0][y-1][x+1] : 0;
|
536
|
-
|
537
|
-
} else {
|
538
|
-
|
539
|
-
l[0] = l[1] = l[2] = 0;
|
540
|
-
|
541
|
-
}
|
542
|
-
|
543
|
-
ml = TBLSIZ;
|
544
|
-
|
545
|
-
//printf("%d %d: %d ", x, y, ml);
|
546
|
-
|
547
|
-
for(i = 0; i < NBR; i++) {
|
548
|
-
|
549
|
-
if(l[i] > 0 && l[i] < ml) ml = l[i];
|
550
|
-
|
551
|
-
//printf(" %d ", l[i]);
|
552
|
-
|
553
|
-
}
|
554
|
-
|
555
|
-
if(ml == TBLSIZ) ml = 0;
|
556
|
-
|
557
|
-
//printf(" min: %d\n", ml);
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
return ml;
|
562
|
-
|
563
|
-
}
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
Img lbl(Img img) {
|
568
|
-
|
569
|
-
Img limg;
|
570
|
-
|
571
|
-
int nbrlbl(Img, Img, int, int, int []);
|
572
|
-
|
573
|
-
int sx, sy;
|
574
|
-
|
575
|
-
int x, y, i;
|
576
|
-
|
577
|
-
int tbl[TBLSIZ], l[NBR], ml, ll;
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
sx = img.sx; sy = img.sy;
|
582
|
-
|
583
|
-
limg.sx = sx; limg.sy = sy;
|
584
|
-
|
585
|
-
tbl[0] = 0;
|
586
|
-
|
587
|
-
ll = 0;
|
588
|
-
|
589
|
-
for(y = 0; y < sy; y++) {
|
590
|
-
|
591
|
-
for(x = 0; x < sx; x++) {
|
592
|
-
|
593
|
-
if(img.d[0][y][x] > 0) {
|
594
|
-
|
595
|
-
ml = nbrlbl(img, limg, x, y, l);
|
596
|
-
|
597
|
-
//printf("\t>>%d %d: %d\n", x, y, ml);
|
598
|
-
|
599
|
-
if(ml == 0) {
|
600
|
-
|
601
|
-
limg.d[0][y][x] = ++ll;
|
602
|
-
|
603
|
-
tbl[ll] = ll;
|
604
|
-
|
605
|
-
} else {
|
606
|
-
|
607
|
-
limg.d[0][y][x] = ml;
|
608
|
-
|
609
|
-
for(i = 0; i < NBR; i++) {
|
610
|
-
|
611
|
-
if(l[i] > ml) {
|
612
|
-
|
613
|
-
tbl[l[i]] = ml;
|
614
|
-
|
615
|
-
}
|
616
|
-
|
617
|
-
}
|
618
|
-
|
619
|
-
}
|
620
|
-
|
621
|
-
} else {
|
622
|
-
|
623
|
-
limg.d[0][y][x] = 0;
|
624
|
-
|
625
|
-
}
|
626
|
-
|
627
|
-
}
|
628
|
-
|
629
|
-
}
|
630
|
-
|
631
|
-
/* For debug.
|
632
|
-
|
633
|
-
for(i = 1; i <= ll; i++) {
|
634
|
-
|
635
|
-
printf("(%3d %3d)\n", i, tbl[i]);
|
636
|
-
|
637
|
-
}
|
638
|
-
|
639
|
-
*/
|
640
|
-
|
641
|
-
for(y = 0; y < sy; y++) {
|
642
|
-
|
643
|
-
for(x = 0; x < sx; x++) {
|
644
|
-
|
645
|
-
limg.d[0][y][x] = tbl[limg.d[0][y][x]];
|
646
|
-
|
647
|
-
}
|
648
|
-
|
649
|
-
}
|
650
|
-
|
651
|
-
return limg;
|
652
|
-
|
653
|
-
}
|
654
|
-
|
655
|
-
```
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
```ここに言語を入力
|
662
|
-
|
663
|
-
格納される部分
|
664
|
-
|
665
|
-
#define MAX 255
|
666
|
-
|
667
|
-
#define MX 20
|
668
|
-
|
669
|
-
#define MY 20
|
670
|
-
|
671
|
-
#define R 0
|
672
|
-
|
673
|
-
#define G 1
|
674
|
-
|
675
|
-
#define B 2
|
676
|
-
|
677
|
-
#define MC 3
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
typedef struct zahyou{
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
int px,py;
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
} Zahyou;
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
typedef struct img {
|
698
|
-
|
699
|
-
int sx, sy;
|
700
|
-
|
701
|
-
int d[MC][MY][MX];
|
702
|
-
|
703
|
-
} Img;
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
typedef struct param {
|
708
|
-
|
709
|
-
int low[MC], up[MC];
|
710
|
-
|
711
|
-
int n, t;
|
712
|
-
|
713
|
-
} Param;
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
Img fgetimg(FILE *);
|
718
|
-
|
719
|
-
Param fgetparam(FILE *);
|
720
|
-
|
721
|
-
void fputimg(FILE *, Img);
|
722
|
-
|
723
|
-
void fputimg_uni(FILE *, Img, int);
|
724
|
-
|
725
|
-
void fputz(FILE *, Zahyou);
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
```
|
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
プログラムを全てはっていますが、メイン分のzyusin関数以外は全て完成しているので
|
2
2
|
|
3
|
-
zyusin関数部分
|
3
|
+
zyusin関数部分と構造体の部分のアドバイスをお願いします。
|
4
4
|
|
5
5
|
先生から元々あるプログラムを真似しながら重心を求める関数を作ってみなさいと言われたのですがコンパイルは通るもののzyusin関数が全く機能していないみたいです。
|
6
6
|
|
@@ -8,9 +8,13 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
|
12
|
-
|
12
|
+
|
13
|
-
|
13
|
+
ちなみにzyusin関数は全て自分で作っています泣
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
14
18
|
|
15
19
|
|
16
20
|
|
2
構造体の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -74,738 +74,652 @@
|
|
74
74
|
|
75
75
|
メイン部分
|
76
76
|
|
77
|
+
int main(int argc, char *argv[]) {
|
78
|
+
|
79
|
+
Img func_h_i(Img, Param); // Eq.(4)
|
80
|
+
|
81
|
+
Img func_h(Img); // Eqs.(2) and (3)
|
82
|
+
|
83
|
+
Img func_av(Img, Param); // Eq.(5)
|
84
|
+
|
85
|
+
Img func_bin(Img, Param); // Eq.(6)
|
86
|
+
|
87
|
+
Img lbl(Img);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
****構造体を増やしました****
|
92
|
+
|
93
|
+
Zahyou zyusin(Img);
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
FILE *fp;
|
98
|
+
|
99
|
+
int i;
|
100
|
+
|
101
|
+
Img img, himg, hhimg, aimg, bimg;
|
102
|
+
|
103
|
+
Param param;
|
104
|
+
|
105
|
+
Zahyou z;
|
106
|
+
|
107
|
+
Img limg,zimg;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if(argc != 3) {
|
112
|
+
|
113
|
+
fprintf(stderr, "Usage: %s file_param file_img.\n", argv[0]);
|
114
|
+
|
115
|
+
return 1;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
if(NULL == (fp = fopen(argv[1], "r"))) {
|
120
|
+
|
121
|
+
fprintf(stderr, "Cannot open %s.\n", argv[1]);
|
122
|
+
|
123
|
+
return 2;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
param = fgetparam(fp);
|
128
|
+
|
129
|
+
fclose(fp);
|
130
|
+
|
131
|
+
if(NULL == (fp = fopen(argv[2], "r"))) {
|
132
|
+
|
133
|
+
fprintf(stderr, "Cannot open %s.\n", argv[1]);
|
134
|
+
|
135
|
+
return 3;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
img = fgetimg(fp);
|
140
|
+
|
141
|
+
fclose(fp);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
printf("Input image. (RGB)\n");
|
146
|
+
|
147
|
+
fputimg(stdout, img);
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
printf("Filtering with (l_i, u_i). (Eq.(4))\n");
|
152
|
+
|
153
|
+
himg = func_h_i(img, param);
|
154
|
+
|
155
|
+
fputimg(stdout, himg);
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
printf("Merging and binarizing. (Eqs. (3) and (2))\n");
|
160
|
+
|
161
|
+
hhimg = func_h(himg);
|
162
|
+
|
163
|
+
fputimg(stdout, hhimg);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
printf("Averaging. (Eq.(5))\n");
|
170
|
+
|
171
|
+
aimg = func_av(hhimg, param);
|
172
|
+
|
173
|
+
fputimg_uni(stdout, aimg, 0);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
printf("Binarizing. (Eq.(6))\n");
|
178
|
+
|
179
|
+
bimg = func_bin(aimg, param);
|
180
|
+
|
181
|
+
fputimg_uni(stdout, bimg, 0);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
printf("Labeling.\n");
|
186
|
+
|
187
|
+
limg = lbl(bimg);
|
188
|
+
|
189
|
+
fputimg_uni(stdout, limg, 0);
|
190
|
+
|
191
|
+
********新たにfputzを追加しました!!!!****
|
192
|
+
|
193
|
+
printf("zyusin.\n");
|
194
|
+
|
195
|
+
z=zyusin(limg);
|
196
|
+
|
197
|
+
fputz(stdout,z);
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
return 0;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
Img func_bin(Img img, Param p) {
|
208
|
+
|
209
|
+
省略
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
return bimg;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
Img func_av(Img img, Param p) {
|
220
|
+
|
221
|
+
省略
|
222
|
+
|
223
|
+
return aimg;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
Img func_h_i(Img img, Param p) {
|
230
|
+
|
231
|
+
省略
|
232
|
+
|
233
|
+
return himg;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
Img func_h(Img img) {
|
240
|
+
|
241
|
+
省略
|
242
|
+
|
243
|
+
return himg ;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
Param fgetparam(FILE *fp) {
|
250
|
+
|
251
|
+
Param param;
|
252
|
+
|
253
|
+
省略
|
254
|
+
|
255
|
+
return param;
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
Img fgetimg(FILE *fp) {
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
省略
|
266
|
+
|
267
|
+
return img;
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
*****新たに変えました**
|
276
|
+
|
277
|
+
ラベル数に応じて返す値を増やしたりしたいのですがそこができません
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
Zahyou zyusin(Img img){
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
Zahyou zahyou;
|
288
|
+
|
289
|
+
int sx,sy;
|
290
|
+
|
291
|
+
int x,y,label1x=0,label1y=0,label2x=0,label2y=0,label3x=0,label3y=0,label4x=0,label4y=0;
|
292
|
+
|
293
|
+
int label1=0,label2=0,label3=0,label4=0;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
img.sx=sx; img.sy=sy;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
for(y=0;y<sy;y++){
|
306
|
+
|
307
|
+
for(x=0;x<sx;x++){
|
308
|
+
|
309
|
+
if(img.d[0][y][x]==1){
|
310
|
+
|
311
|
+
label1++;
|
312
|
+
|
313
|
+
label1x=label1x+x;
|
314
|
+
|
315
|
+
label1y=label1y+y;
|
316
|
+
|
317
|
+
}else if(img.d[0][y][x]==2){
|
318
|
+
|
319
|
+
label2++;
|
320
|
+
|
321
|
+
label2x=label2x+x;
|
322
|
+
|
323
|
+
label2y=label2y+y;
|
324
|
+
|
325
|
+
}else if(img.d[0][y][x]==3){
|
326
|
+
|
327
|
+
label3++;
|
328
|
+
|
329
|
+
label3x=label3x+x;
|
330
|
+
|
331
|
+
label3y=label3y+y;
|
332
|
+
|
333
|
+
}else if(img.d[0][y][x]==4){
|
334
|
+
|
335
|
+
label4++;
|
336
|
+
|
337
|
+
label4x=label4x+x;
|
338
|
+
|
339
|
+
label4y=label4y+y;
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
label1x=label1x/label1;
|
356
|
+
|
357
|
+
label1y=label1y/label1;
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
label2x=label2x/label2;
|
364
|
+
|
365
|
+
label2y=label2y/label2;
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
label3x=label3x/label3;
|
372
|
+
|
373
|
+
label3y=label3y/label3;
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
label4x=label4x/label4;
|
380
|
+
|
381
|
+
label4y=label4y/label4;
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
Zahyou.px=label1x;
|
388
|
+
|
389
|
+
Zahyou.py=label1y;
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
return zahyou;
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
void fputimg(FILE *fp, Img img) {
|
410
|
+
|
411
|
+
int sx, sy;
|
412
|
+
|
413
|
+
int c, x, y;
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
sx = img.sx; sy = img.sy;
|
418
|
+
|
419
|
+
fprintf(fp, "%d %d\n", sx, sy);
|
420
|
+
|
421
|
+
for(c = 0; c < MC; c++) {
|
422
|
+
|
423
|
+
fputimg_uni(fp, img, c);
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
void fputimg_uni(FILE *fp, Img img, int c) {
|
432
|
+
|
433
|
+
int sx, sy;
|
434
|
+
|
435
|
+
int x, y;
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
sx = img.sx; sy = img.sy;
|
440
|
+
|
441
|
+
for(y = 0; y < sy; y++) {
|
442
|
+
|
443
|
+
for(x = 0; x < sx; x++) {
|
444
|
+
|
445
|
+
fprintf(fp, "%3d ", img.d[c][y][x]);
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
fprintf(fp, "\n");
|
450
|
+
|
451
|
+
}
|
452
|
+
|
453
|
+
fprintf(fp, "\n");
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
******新たに追加しました*****
|
462
|
+
|
463
|
+
void fputz(FILE *fp, Zahyou zahyou){
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
int i;
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
for(i=0;i<4;i++){ //4はラベルの数だけ分にしたい今回の例だと2
|
472
|
+
|
473
|
+
fprintf(fp,"%d %d",zahyou.px,zahyou.py);
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
fprintf(fp,"\n");
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
}
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
```
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
```
|
500
|
+
|
501
|
+
ラベリング部分 ここは質問とは関係ないですが参考にして考えろと言われたところです
|
502
|
+
|
77
|
-
#include
|
503
|
+
#include <stdio.h>
|
78
504
|
|
79
505
|
#include "img.h"
|
80
506
|
|
81
|
-
|
507
|
+
#define NBR 4
|
508
|
+
|
82
|
-
|
509
|
+
#define TBLSIZ 63
|
510
|
+
|
511
|
+
|
512
|
+
|
83
|
-
int m
|
513
|
+
int nbrlbl(Img img, Img limg, int x, int y, int l[]) {
|
84
|
-
|
85
|
-
|
514
|
+
|
86
|
-
|
87
|
-
Img func_h(Img); // Eqs.(2) and (3)
|
88
|
-
|
89
|
-
Img func_av(Img, Param); // Eq.(5)
|
90
|
-
|
91
|
-
Img func_bin(Img, Param); // Eq.(6)
|
92
|
-
|
93
|
-
Img lbl(Img);
|
94
|
-
|
95
|
-
Img zyusin(Img);
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
FILE *fp;
|
100
|
-
|
101
|
-
|
515
|
+
int ml, i;
|
102
|
-
|
103
|
-
|
516
|
+
|
104
|
-
|
105
|
-
Param param;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
517
|
+
int sx, sy;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if(argc != 3) {
|
114
|
-
|
115
|
-
fprintf(stderr, "Usage: %s file_param file_img.\n", argv[0]);
|
116
|
-
|
117
|
-
return 1;
|
118
|
-
|
119
|
-
}
|
120
|
-
|
121
|
-
if(NULL == (fp = fopen(argv[1], "r"))) {
|
122
|
-
|
123
|
-
fprintf(stderr, "Cannot open %s.\n", argv[1]);
|
124
|
-
|
125
|
-
return 2;
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
param = fgetparam(fp);
|
130
|
-
|
131
|
-
fclose(fp);
|
132
|
-
|
133
|
-
if(NULL == (fp = fopen(argv[2], "r"))) {
|
134
|
-
|
135
|
-
fprintf(stderr, "Cannot open %s.\n", argv[1]);
|
136
|
-
|
137
|
-
return 3;
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
img = fgetimg(fp);
|
142
|
-
|
143
|
-
fclose(fp);
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
printf("Input image. (RGB)\n");
|
148
|
-
|
149
|
-
fputimg(stdout, img);
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
printf("Filtering with (l_i, u_i). (Eq.(4))\n");
|
154
|
-
|
155
|
-
himg = func_h_i(img, param);
|
156
|
-
|
157
|
-
fputimg(stdout, himg);
|
158
518
|
|
159
519
|
|
160
520
|
|
161
|
-
printf("Merging and binarizing. (Eqs. (3) and (2))\n");
|
162
|
-
|
163
|
-
hhimg = func_h(himg);
|
164
|
-
|
165
|
-
|
521
|
+
sx = img.sx; sy = img.sy;
|
522
|
+
|
166
|
-
|
523
|
+
l[3] = x > 0 ? limg.d[0][y][x-1] : 0;
|
524
|
+
|
167
|
-
|
525
|
+
if(y > 0) {
|
526
|
+
|
168
|
-
|
527
|
+
l[1] = limg.d[0][y-1][x];
|
528
|
+
|
169
|
-
|
529
|
+
l[0] = x > 0 ? limg.d[0][y-1][x-1] : 0;
|
530
|
+
|
170
|
-
|
531
|
+
l[2] = x < sx - 1 ? limg.d[0][y-1][x+1] : 0;
|
532
|
+
|
533
|
+
} else {
|
534
|
+
|
535
|
+
l[0] = l[1] = l[2] = 0;
|
536
|
+
|
537
|
+
}
|
538
|
+
|
539
|
+
ml = TBLSIZ;
|
540
|
+
|
541
|
+
//printf("%d %d: %d ", x, y, ml);
|
542
|
+
|
543
|
+
for(i = 0; i < NBR; i++) {
|
544
|
+
|
545
|
+
if(l[i] > 0 && l[i] < ml) ml = l[i];
|
546
|
+
|
547
|
+
//printf(" %d ", l[i]);
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
if(ml == TBLSIZ) ml = 0;
|
552
|
+
|
171
|
-
|
553
|
+
//printf(" min: %d\n", ml);
|
172
|
-
|
554
|
+
|
555
|
+
|
556
|
+
|
173
|
-
|
557
|
+
return ml;
|
558
|
+
|
174
|
-
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
|
175
|
-
|
563
|
+
Img lbl(Img img) {
|
564
|
+
|
565
|
+
Img limg;
|
566
|
+
|
567
|
+
int nbrlbl(Img, Img, int, int, int []);
|
568
|
+
|
569
|
+
int sx, sy;
|
570
|
+
|
571
|
+
int x, y, i;
|
572
|
+
|
573
|
+
int tbl[TBLSIZ], l[NBR], ml, ll;
|
176
574
|
|
177
575
|
|
178
576
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
f
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
577
|
+
sx = img.sx; sy = img.sy;
|
578
|
+
|
579
|
+
limg.sx = sx; limg.sy = sy;
|
580
|
+
|
581
|
+
tbl[0] = 0;
|
582
|
+
|
583
|
+
ll = 0;
|
584
|
+
|
585
|
+
for(y = 0; y < sy; y++) {
|
586
|
+
|
587
|
+
for(x = 0; x < sx; x++) {
|
588
|
+
|
589
|
+
if(img.d[0][y][x] > 0) {
|
590
|
+
|
591
|
+
ml = nbrlbl(img, limg, x, y, l);
|
592
|
+
|
593
|
+
//printf("\t>>%d %d: %d\n", x, y, ml);
|
594
|
+
|
595
|
+
if(ml == 0) {
|
596
|
+
|
597
|
+
limg.d[0][y][x] = ++ll;
|
598
|
+
|
599
|
+
tbl[ll] = ll;
|
600
|
+
|
601
|
+
} else {
|
602
|
+
|
603
|
+
limg.d[0][y][x] = ml;
|
604
|
+
|
605
|
+
for(i = 0; i < NBR; i++) {
|
606
|
+
|
607
|
+
if(l[i] > ml) {
|
608
|
+
|
609
|
+
tbl[l[i]] = ml;
|
610
|
+
|
611
|
+
}
|
612
|
+
|
613
|
+
}
|
614
|
+
|
615
|
+
}
|
616
|
+
|
617
|
+
} else {
|
618
|
+
|
619
|
+
limg.d[0][y][x] = 0;
|
620
|
+
|
621
|
+
}
|
622
|
+
|
623
|
+
}
|
624
|
+
|
625
|
+
}
|
626
|
+
|
627
|
+
/* For debug.
|
628
|
+
|
629
|
+
for(i = 1; i <= ll; i++) {
|
630
|
+
|
631
|
+
printf("(%3d %3d)\n", i, tbl[i]);
|
632
|
+
|
633
|
+
}
|
634
|
+
|
635
|
+
*/
|
636
|
+
|
637
|
+
for(y = 0; y < sy; y++) {
|
638
|
+
|
639
|
+
for(x = 0; x < sx; x++) {
|
640
|
+
|
641
|
+
limg.d[0][y][x] = tbl[limg.d[0][y][x]];
|
642
|
+
|
643
|
+
}
|
644
|
+
|
645
|
+
}
|
646
|
+
|
647
|
+
return limg;
|
648
|
+
|
649
|
+
}
|
650
|
+
|
651
|
+
```
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
```ここに言語を入力
|
658
|
+
|
659
|
+
格納される部分
|
660
|
+
|
661
|
+
#define MAX 255
|
662
|
+
|
663
|
+
#define MX 20
|
664
|
+
|
665
|
+
#define MY 20
|
666
|
+
|
667
|
+
#define R 0
|
668
|
+
|
669
|
+
#define G 1
|
670
|
+
|
671
|
+
#define B 2
|
672
|
+
|
673
|
+
#define MC 3
|
674
|
+
|
675
|
+
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
typedef struct zahyou{
|
680
|
+
|
681
|
+
|
682
|
+
|
683
|
+
int px,py;
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
} Zahyou;
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
typedef struct img {
|
212
694
|
|
213
695
|
int sx, sy;
|
214
696
|
|
215
|
-
int
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
Img aimg;
|
244
|
-
|
245
|
-
int sx, sy;
|
246
|
-
|
247
|
-
int c, x, y;
|
248
|
-
|
249
|
-
int n, nn, d;
|
250
|
-
|
251
|
-
int m, xs, xe, ys, ye, mx, my, cc, s;
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
*計算は省略
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
return aimg;
|
260
|
-
|
261
|
-
}
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
Img func_h_i(Img img, Param p) {
|
266
|
-
|
267
|
-
Img himg;
|
268
|
-
|
269
|
-
int sx, sy;
|
270
|
-
|
271
|
-
int c, x, y;
|
272
|
-
|
273
|
-
int d, h;
|
274
|
-
|
275
|
-
int l, u;
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
sx = img.sx; sy = img.sy;
|
280
|
-
|
281
|
-
himg.sx = sx; himg.sy = sy;
|
282
|
-
|
283
|
-
for(c = 0; c < MC; c++) {
|
284
|
-
|
285
|
-
l = p.low[c];
|
286
|
-
|
287
|
-
u = p.up[c];
|
288
|
-
|
289
|
-
for(y = 0; y < sy; y++) {
|
290
|
-
|
291
|
-
for(x = 0; x < sx; x++) {
|
292
|
-
|
293
|
-
d = img.d[c][y][x];
|
294
|
-
|
295
|
-
h = (d >= l && d <= u) ? 1 : 0;
|
296
|
-
|
297
|
-
himg.d[c][y][x] = h;
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
}
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
return himg;
|
308
|
-
|
309
|
-
}
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
Img func_h(Img img) {
|
314
|
-
|
315
|
-
Img himg;
|
316
|
-
|
317
|
-
int sx, sy;
|
318
|
-
|
319
|
-
int c, x, y;
|
320
|
-
|
321
|
-
int d;
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
sx = img.sx; sy = img.sy;
|
326
|
-
|
327
|
-
himg.sx = sx; himg.sy = sy;
|
328
|
-
|
329
|
-
for(y = 0; y < sy; y++) {
|
330
|
-
|
331
|
-
for(x = 0; x < sx; x++) {
|
332
|
-
|
333
|
-
d = MAX;
|
334
|
-
|
335
|
-
for(c = 0; c < MC; c++) {
|
336
|
-
|
337
|
-
d *= img.d[c][y][x];
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
for(c = 0; c < MC; c++) {
|
342
|
-
|
343
|
-
himg.d[c][y][x] = d;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
return himg ;
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
Param fgetparam(FILE *fp) {
|
360
|
-
|
361
|
-
Param param;
|
362
|
-
|
363
|
-
int c;
|
364
|
-
|
365
|
-
for(c = 0; c < MC; c++) {
|
366
|
-
|
367
|
-
fscanf(fp, "%d", &(param.low[c]));
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
for(c = 0; c < MC; c++) {
|
372
|
-
|
373
|
-
fscanf(fp, "%d", &(param.up[c]));
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
fscanf(fp, "%d", &(param.n));
|
378
|
-
|
379
|
-
fscanf(fp, "%d", &(param.t));
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
return param;
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
Img fgetimg(FILE *fp) {
|
390
|
-
|
391
|
-
Img img;
|
392
|
-
|
393
|
-
int sx, sy;
|
394
|
-
|
395
|
-
int c, x, y;
|
396
|
-
|
397
|
-
int tmp;
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
fscanf(fp, "%d %d", &sx, &sy);
|
402
|
-
|
403
|
-
img.sx = sx; img.sy = sy;
|
404
|
-
|
405
|
-
for(c = 0; c < MC; c++) {
|
406
|
-
|
407
|
-
for(y = 0; y < sy; y++) {
|
408
|
-
|
409
|
-
for(x = 0; x < sx; x++) {
|
410
|
-
|
411
|
-
fscanf(fp, "%d", &tmp);
|
412
|
-
|
413
|
-
img.d[c][y][x] = tmp;
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
}
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
return img;
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
*****ここから見てください*****
|
434
|
-
|
435
|
-
Img zyusin(Img img){
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
int sx=0,sy=0;
|
442
|
-
|
443
|
-
int x,y,label1x=0,label1y=0,label2x=0,label2y=0;
|
444
|
-
|
445
|
-
int label1=0,label2=0;
|
446
|
-
|
447
|
-
sx=img.sx; sy=img.sy;
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
for(y=0;y<sy;y++){
|
458
|
-
|
459
|
-
for(x=0;x<sx;x++){
|
460
|
-
|
461
|
-
if(img.d[0][y][x]==1){
|
462
|
-
|
463
|
-
label1++;
|
464
|
-
|
465
|
-
}else if(img.d[0][y][x]==2){
|
466
|
-
|
467
|
-
label2++;
|
468
|
-
|
469
|
-
}
|
470
|
-
|
471
|
-
}
|
472
|
-
|
473
|
-
}
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
for(y=0;y<sy;y++){
|
480
|
-
|
481
|
-
for(x=0;x<sx;x++){
|
482
|
-
|
483
|
-
if(img.d[0][y][x]==1){
|
484
|
-
|
485
|
-
label1x=label1x+x;
|
486
|
-
|
487
|
-
label1y=label1y+y;
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
}if(img.d[0][y][x]==2){
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
label2x=label2x+x;
|
496
|
-
|
497
|
-
label2y=label2y+y;
|
498
|
-
|
499
|
-
}
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
}
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
label1x=label1x/label1;
|
514
|
-
|
515
|
-
label1y=label1y/label1;
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
label2x=label2x/label2;
|
520
|
-
|
521
|
-
label2y=label2y/label2;
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
return label1x;
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
}
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
void fputimg(FILE *fp, Img img) {
|
546
|
-
|
547
|
-
int sx, sy;
|
548
|
-
|
549
|
-
int c, x, y;
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
sx = img.sx; sy = img.sy;
|
554
|
-
|
555
|
-
fprintf(fp, "%d %d\n", sx, sy);
|
556
|
-
|
557
|
-
for(c = 0; c < MC; c++) {
|
558
|
-
|
559
|
-
fputimg_uni(fp, img, c);
|
560
|
-
|
561
|
-
}
|
562
|
-
|
563
|
-
}
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
void fputimg_uni(FILE *fp, Img img, int c) {
|
568
|
-
|
569
|
-
int sx, sy;
|
570
|
-
|
571
|
-
int x, y;
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
sx = img.sx; sy = img.sy;
|
576
|
-
|
577
|
-
for(y = 0; y < sy; y++) {
|
578
|
-
|
579
|
-
for(x = 0; x < sx; x++) {
|
580
|
-
|
581
|
-
fprintf(fp, "%3d ", img.d[c][y][x]);
|
582
|
-
|
583
|
-
}
|
584
|
-
|
585
|
-
fprintf(fp, "\n");
|
586
|
-
|
587
|
-
}
|
588
|
-
|
589
|
-
fprintf(fp, "\n");
|
590
|
-
|
591
|
-
}
|
697
|
+
int d[MC][MY][MX];
|
698
|
+
|
699
|
+
} Img;
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
typedef struct param {
|
704
|
+
|
705
|
+
int low[MC], up[MC];
|
706
|
+
|
707
|
+
int n, t;
|
708
|
+
|
709
|
+
} Param;
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
Img fgetimg(FILE *);
|
714
|
+
|
715
|
+
Param fgetparam(FILE *);
|
716
|
+
|
717
|
+
void fputimg(FILE *, Img);
|
718
|
+
|
719
|
+
void fputimg_uni(FILE *, Img, int);
|
720
|
+
|
721
|
+
void fputz(FILE *, Zahyou);
|
722
|
+
|
723
|
+
|
592
724
|
|
593
725
|
```
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
```
|
602
|
-
|
603
|
-
ラベリング部分 ここは質問とは関係ないですが参考にして考えろと言われたところです
|
604
|
-
|
605
|
-
#include <stdio.h>
|
606
|
-
|
607
|
-
#include "img.h"
|
608
|
-
|
609
|
-
#define NBR 4
|
610
|
-
|
611
|
-
#define TBLSIZ 63
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
int nbrlbl(Img img, Img limg, int x, int y, int l[]) {
|
616
|
-
|
617
|
-
int ml, i;
|
618
|
-
|
619
|
-
int sx, sy;
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
sx = img.sx; sy = img.sy;
|
624
|
-
|
625
|
-
l[3] = x > 0 ? limg.d[0][y][x-1] : 0;
|
626
|
-
|
627
|
-
if(y > 0) {
|
628
|
-
|
629
|
-
l[1] = limg.d[0][y-1][x];
|
630
|
-
|
631
|
-
l[0] = x > 0 ? limg.d[0][y-1][x-1] : 0;
|
632
|
-
|
633
|
-
l[2] = x < sx - 1 ? limg.d[0][y-1][x+1] : 0;
|
634
|
-
|
635
|
-
} else {
|
636
|
-
|
637
|
-
l[0] = l[1] = l[2] = 0;
|
638
|
-
|
639
|
-
}
|
640
|
-
|
641
|
-
ml = TBLSIZ;
|
642
|
-
|
643
|
-
//printf("%d %d: %d ", x, y, ml);
|
644
|
-
|
645
|
-
for(i = 0; i < NBR; i++) {
|
646
|
-
|
647
|
-
if(l[i] > 0 && l[i] < ml) ml = l[i];
|
648
|
-
|
649
|
-
//printf(" %d ", l[i]);
|
650
|
-
|
651
|
-
}
|
652
|
-
|
653
|
-
if(ml == TBLSIZ) ml = 0;
|
654
|
-
|
655
|
-
//printf(" min: %d\n", ml);
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
return ml;
|
660
|
-
|
661
|
-
}
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
Img lbl(Img img) {
|
666
|
-
|
667
|
-
Img limg;
|
668
|
-
|
669
|
-
int nbrlbl(Img, Img, int, int, int []);
|
670
|
-
|
671
|
-
int sx, sy;
|
672
|
-
|
673
|
-
int x, y, i;
|
674
|
-
|
675
|
-
int tbl[TBLSIZ], l[NBR], ml, ll;
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
sx = img.sx; sy = img.sy;
|
680
|
-
|
681
|
-
limg.sx = sx; limg.sy = sy;
|
682
|
-
|
683
|
-
tbl[0] = 0;
|
684
|
-
|
685
|
-
ll = 0;
|
686
|
-
|
687
|
-
for(y = 0; y < sy; y++) {
|
688
|
-
|
689
|
-
for(x = 0; x < sx; x++) {
|
690
|
-
|
691
|
-
if(img.d[0][y][x] > 0) {
|
692
|
-
|
693
|
-
ml = nbrlbl(img, limg, x, y, l);
|
694
|
-
|
695
|
-
//printf("\t>>%d %d: %d\n", x, y, ml);
|
696
|
-
|
697
|
-
if(ml == 0) {
|
698
|
-
|
699
|
-
limg.d[0][y][x] = ++ll;
|
700
|
-
|
701
|
-
tbl[ll] = ll;
|
702
|
-
|
703
|
-
} else {
|
704
|
-
|
705
|
-
limg.d[0][y][x] = ml;
|
706
|
-
|
707
|
-
for(i = 0; i < NBR; i++) {
|
708
|
-
|
709
|
-
if(l[i] > ml) {
|
710
|
-
|
711
|
-
tbl[l[i]] = ml;
|
712
|
-
|
713
|
-
}
|
714
|
-
|
715
|
-
}
|
716
|
-
|
717
|
-
}
|
718
|
-
|
719
|
-
} else {
|
720
|
-
|
721
|
-
limg.d[0][y][x] = 0;
|
722
|
-
|
723
|
-
}
|
724
|
-
|
725
|
-
}
|
726
|
-
|
727
|
-
}
|
728
|
-
|
729
|
-
/* For debug.
|
730
|
-
|
731
|
-
for(i = 1; i <= ll; i++) {
|
732
|
-
|
733
|
-
printf("(%3d %3d)\n", i, tbl[i]);
|
734
|
-
|
735
|
-
}
|
736
|
-
|
737
|
-
*/
|
738
|
-
|
739
|
-
for(y = 0; y < sy; y++) {
|
740
|
-
|
741
|
-
for(x = 0; x < sx; x++) {
|
742
|
-
|
743
|
-
limg.d[0][y][x] = tbl[limg.d[0][y][x]];
|
744
|
-
|
745
|
-
}
|
746
|
-
|
747
|
-
}
|
748
|
-
|
749
|
-
return limg;
|
750
|
-
|
751
|
-
}
|
752
|
-
|
753
|
-
```
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
```ここに言語を入力
|
760
|
-
|
761
|
-
格納される部分
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
#define MAX 255
|
766
|
-
|
767
|
-
#define MX 20
|
768
|
-
|
769
|
-
#define MY 20
|
770
|
-
|
771
|
-
#define R 0
|
772
|
-
|
773
|
-
#define G 1
|
774
|
-
|
775
|
-
#define B 2
|
776
|
-
|
777
|
-
#define MC 3
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
typedef struct img {
|
782
|
-
|
783
|
-
int sx, sy;
|
784
|
-
|
785
|
-
int d[MC][MY][MX];
|
786
|
-
|
787
|
-
} Img;
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
typedef struct param {
|
792
|
-
|
793
|
-
int low[MC], up[MC];
|
794
|
-
|
795
|
-
int n, t;
|
796
|
-
|
797
|
-
} Param;
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
Img fgetimg(FILE *);
|
802
|
-
|
803
|
-
Param fgetparam(FILE *);
|
804
|
-
|
805
|
-
void fputimg(FILE *, Img);
|
806
|
-
|
807
|
-
void fputimg_uni(FILE *, Img, int);
|
808
|
-
|
809
|
-
void zyusin(Img);
|
810
|
-
|
811
|
-
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
Img lbl(Img);
|
94
94
|
|
95
|
-
|
95
|
+
Img zyusin(Img);
|
96
96
|
|
97
97
|
|
98
98
|
|
@@ -432,11 +432,11 @@
|
|
432
432
|
|
433
433
|
*****ここから見てください*****
|
434
434
|
|
435
|
-
|
435
|
+
Img zyusin(Img img){
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
440
|
|
441
441
|
int sx=0,sy=0;
|
442
442
|
|
@@ -444,10 +444,10 @@
|
|
444
444
|
|
445
445
|
int label1=0,label2=0;
|
446
446
|
|
447
|
+
sx=img.sx; sy=img.sy;
|
448
|
+
|
447
449
|
|
448
450
|
|
449
|
-
limg.sx=sx; limg.sy=sy;
|
450
|
-
|
451
451
|
|
452
452
|
|
453
453
|
|
@@ -458,11 +458,11 @@
|
|
458
458
|
|
459
459
|
for(x=0;x<sx;x++){
|
460
460
|
|
461
|
-
if(
|
461
|
+
if(img.d[0][y][x]==1){
|
462
462
|
|
463
463
|
label1++;
|
464
464
|
|
465
|
-
}else if(
|
465
|
+
}else if(img.d[0][y][x]==2){
|
466
466
|
|
467
467
|
label2++;
|
468
468
|
|
@@ -480,7 +480,7 @@
|
|
480
480
|
|
481
481
|
for(x=0;x<sx;x++){
|
482
482
|
|
483
|
-
if(
|
483
|
+
if(img.d[0][y][x]==1){
|
484
484
|
|
485
485
|
label1x=label1x+x;
|
486
486
|
|
@@ -488,7 +488,7 @@
|
|
488
488
|
|
489
489
|
|
490
490
|
|
491
|
-
}if(
|
491
|
+
}if(img.d[0][y][x]==2){
|
492
492
|
|
493
493
|
|
494
494
|
|
@@ -524,7 +524,7 @@
|
|
524
524
|
|
525
525
|
|
526
526
|
|
527
|
-
|
527
|
+
return label1x;
|
528
528
|
|
529
529
|
|
530
530
|
|