00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040
00041 #include "io_png/io_png.h"
00042 #include "rgbprocess_lib.h"
00043
00044 #define VERSION "0.20110518"
00045
00151 int main(int argc, char *const *argv)
00152 {
00153 unsigned char *img, *img2, *img3, *imgOut1=NULL, *imgOut2=NULL,
00154 *imgOut3=NULL;
00155 int wOut, hOut;
00156 size_t nx = 0, ny = 0, nc = 0;
00157
00158
00159 if (2 <= argc && 0 == strcmp("-v", argv[1]))
00160 {
00161 fprintf(stdout, "%s version " VERSION
00162 ", compiled " __DATE__ "\n", argv[0]);
00163 return EXIT_SUCCESS;
00164 }
00165
00166 if (argc < 2)
00167 {
00168 fprintf(stderr,
00169 "usage : %s [filter in.png out.png]\n",
00170 argv[0]);
00171 fprintf(stderr,
00172 "usage : %s [rmisolated in.png out.png]\n",
00173 argv[0]);
00174 fprintf(stderr,
00175 "usage : %s [pcaviews in1.png in2.png out1.png out2.png \
00176 out3.png wOut hOut]\n",
00177 argv[0]);
00178 fprintf(stderr,
00179 "usage : %s [pcaviewsB in1.png in2.png out123.png \
00180 wOut hOut]\n",
00181 argv[0]);
00182 fprintf(stderr,
00183 "usage : %s [densityimage in1.png density.png\n",
00184 argv[0]);
00185 fprintf(stderr,
00186 "usage : %s [densityviews in1.png in2.png out123.png \
00187 wOut hOut [optional: density.png]]\n",
00188 argv[0]);
00189 fprintf(stderr,
00190 "usage : %s [mergeimages in1.png in2.png out.png]\n",
00191 argv[0]);
00192 fprintf(stderr,
00193 "usage : %s [RGBviewsparams nameparams.txt]\n",
00194 argv[0]);
00195 fprintf(stderr,
00196 "usage : %s [RGBviews in1.png nameparams.txt nameviews \
00197 wOut hOut displaydensity=0/1 [optional: density.png]]\n",
00198 argv[0]);
00199 fprintf(stderr,
00200 "usage : %s [combineviews nameparams.txt nameviews1 \
00201 nameview2 nameview3 nameviewsOut]\n",
00202 argv[0]);
00203 fprintf(stderr,
00204 "usage : %s [computeRMSE in1.png in2.png]\n",
00205 argv[0]);
00206 fprintf(stderr,
00207 "usage : %s [countcolors in1.png]\n",
00208 argv[0]);
00209 fprintf(stderr,
00210 "usage : %s [RGB2VRML2 in1.png out.wrl displaydensity=0/1 \
00211 [optional: density.png]]\n",
00212 argv[0]);
00213 return EXIT_FAILURE;
00214 }
00215
00216 if (!strcmp(argv[1], "filter")) {
00217
00218
00219
00220 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00221
00222 if (!img)
00223 {
00224 fprintf(stderr, "Error reading input image or not a color image!\n");
00225 return EXIT_FAILURE;
00226 }
00227
00228
00229 rgbprocess(img, NULL, NULL, nx, ny, img, NULL, NULL, nx, ny, "filter");
00230
00231
00232 nc=3;
00233 io_png_write_u8(argv[3], img, nx, ny, nc);
00234
00235
00236 free(img);
00237
00238 }
00239
00240 if (!strcmp(argv[1], "rmisolated")) {
00241
00242
00243
00244 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00245
00246 if (!img)
00247 {
00248 fprintf(stderr, "Error reading input image or not a color image!\n");
00249 return EXIT_FAILURE;
00250 }
00251
00252
00253 rgbprocess(img, NULL, NULL, nx, ny, img, NULL, NULL,
00254 nx, ny, "rmisolated");
00255
00256
00257 nc=3;
00258 io_png_write_u8(argv[3], img, nx, ny, nc);
00259
00260
00261 free(img);
00262
00263 }
00264
00265
00266 if (!strcmp(argv[1], "pcaviews")) {
00267
00268
00269
00270 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00271 if (!img)
00272 {
00273 fprintf(stderr, "Error reading input image or not a color image!\n");
00274 return EXIT_FAILURE;
00275 }
00276
00277
00278 img2 = io_png_read_u8_rgb(argv[3], &nx, &ny);
00279 if (!img2)
00280 {
00281 fprintf(stderr,
00282 "Error reading reference input image or not a color image!\n");
00283 free(img);
00284 return EXIT_FAILURE;
00285 }
00286
00287 wOut = atoi(argv[7]);
00288 hOut = atoi(argv[8]);
00289
00290 imgOut1=(unsigned char *) malloc(3*wOut*hOut);
00291 imgOut2=(unsigned char *) malloc(3*wOut*hOut);
00292 imgOut3=(unsigned char *) malloc(3*wOut*hOut);
00293
00294
00295 rgbprocess(img, img2, NULL, nx, ny,
00296 imgOut1, imgOut2, imgOut3, wOut, hOut, "pcaviews");
00297
00298
00299 nc=3;
00300 io_png_write_u8(argv[4], imgOut1, wOut, hOut, nc);
00301 io_png_write_u8(argv[5], imgOut2, wOut, hOut, nc);
00302 io_png_write_u8(argv[6], imgOut3, wOut, hOut, nc);
00303
00304
00305 free(img);
00306 free(img2);
00307 free(imgOut1);
00308 free(imgOut2);
00309 free(imgOut3);
00310 }
00311
00312 if (!strcmp(argv[1], "pcaviewsB")) {
00313
00314
00315
00316 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00317 if (!img)
00318 {
00319 fprintf(stderr, "Error reading input image or not a color image!\n");
00320 return EXIT_FAILURE;
00321 }
00322
00323
00324 img2 = io_png_read_u8_rgb(argv[3], &nx, &ny);
00325 if (!img2)
00326 {
00327 fprintf(stderr,
00328 "Error reading reference input image or not a color image!\n");
00329 free(img);
00330 return EXIT_FAILURE;
00331 }
00332
00333 wOut = atoi(argv[5]);
00334 hOut = atoi(argv[6]);
00335
00336 imgOut1=(unsigned char *) malloc(3*3*wOut*hOut);
00337
00338
00339 rgbprocess(img, img2, NULL, nx, ny,
00340 imgOut1, NULL, NULL, wOut, hOut, "pcaviewsB");
00341
00342
00343 nc=3;
00344 io_png_write_u8(argv[4], imgOut1, 3*wOut, hOut, nc);
00345
00346
00347 free(img);
00348 free(img2);
00349 free(imgOut1);
00350 }
00351
00352 if (!strcmp(argv[1], "densityimage")) {
00353
00354
00355
00356 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00357
00358 if (!img)
00359 {
00360 fprintf(stderr, "Error reading input image or not a color image!\n");
00361 return EXIT_FAILURE;
00362 }
00363
00364 imgOut1=(unsigned char *) malloc(nx*ny);
00365
00366
00367 rgbprocess(img, NULL, NULL, nx, ny,
00368 imgOut1, NULL, NULL, nx, ny, "densityImage");
00369
00370
00371 nc=1;
00372 io_png_write_u8(argv[3], imgOut1, nx, ny, nc);
00373
00374
00375 free(img);
00376 free(imgOut1);
00377 }
00378
00379
00380 if (!strcmp(argv[1], "densityviews")) {
00381
00382
00383
00384 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00385 if (!img)
00386 {
00387 fprintf(stderr, "Error reading input image or not a color image!\n");
00388 return EXIT_FAILURE;
00389 }
00390
00391
00392 img2 = io_png_read_u8_rgb(argv[3], &nx, &ny);
00393 if (!img2)
00394 {
00395 fprintf(stderr,
00396 "Error reading reference input image or not a color image!\n");
00397 free(img);
00398 return EXIT_FAILURE;
00399 }
00400
00401 wOut = atoi(argv[5]);
00402 hOut = atoi(argv[6]);
00403
00404 img3=NULL;
00405 if (argc > 7) {
00406
00407 img3 = io_png_read_u8_gray(argv[7], &nx, &ny);
00408 if (!img3)
00409 {
00410 fprintf(stderr, "Error reading density input image!\n");
00411 free(img);
00412 free(img2);
00413 return EXIT_FAILURE;
00414 }
00415 }
00416
00417 imgOut1=(unsigned char *) malloc(3*3*wOut*hOut);
00418
00419
00420 rgbprocess(img, img2, img3, nx, ny,
00421 imgOut1, NULL, NULL, wOut, hOut, "densityviews");
00422
00423
00424 nc=3;
00425 io_png_write_u8(argv[4], imgOut1, 3*wOut, hOut, nc);
00426
00427
00428 free(img);
00429 free(img2);
00430 if (img3) free(img3);
00431 free(imgOut1);
00432 }
00433
00434 if (!strcmp(argv[1], "mergeimages")) {
00435
00436
00437
00438 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00439 if (!img)
00440 {
00441 fprintf(stderr, "Error reading input image or not a color image!\n");
00442 return EXIT_FAILURE;
00443 }
00444
00445
00446 img2 = io_png_read_u8_rgb(argv[3], &nx, &ny);
00447 if (!img2)
00448 {
00449 fprintf(stderr,
00450 "Error reading reference input image or not a color image!\n");
00451 free(img);
00452 return EXIT_FAILURE;
00453 }
00454
00455 imgOut1=(unsigned char *) malloc(3*nx*ny);
00456
00457
00458 rgbprocess(img, img2, NULL, nx, ny,
00459 imgOut1, NULL, NULL, nx, ny, "mergeimages");
00460
00461
00462 nc=3;
00463 io_png_write_u8(argv[4], imgOut1, nx, ny, nc);
00464
00465
00466 free(img);
00467 free(img2);
00468 free(imgOut1);
00469 }
00470
00471 if (!strcmp(argv[1], "RGBviewsparams")) {
00472 RGBviewsparams(argv[2]);
00473 }
00474
00475 if (!strcmp(argv[1], "RGBviews")) {
00476
00477
00478
00479 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00480 if (!img)
00481 {
00482 fprintf(stderr, "Error reading input image or not a color image!\n");
00483 return EXIT_FAILURE;
00484 }
00485
00486
00487 int wview, hview;
00488 sscanf(argv[5], "%i", &wview);
00489 sscanf(argv[6], "%i", &hview);
00490
00491 imgOut1=(unsigned char *) malloc(3*wview*hview);
00492
00493
00494 unsigned char *Idsty=NULL;
00495 int displayDensity;
00496 sscanf(argv[7], "%i", &displayDensity);
00497 if (displayDensity == 1) {
00498 if (argc > 8) {
00499
00500 Idsty = io_png_read_u8_gray(argv[8], &nx, &ny);
00501 if (!Idsty) {
00502 fprintf(stderr, "Error reading density input image!\n");
00503 free(img);
00504 free(imgOut1);
00505 return EXIT_FAILURE;
00506 }
00507 } else {
00508 printf("compute density\n");
00509 Idsty=(unsigned char *) malloc(nx*ny);
00510 rgbprocess(img, NULL, NULL, nx, ny,
00511 Idsty, NULL, NULL, 0, 0, "densityImage");
00512 }
00513 }
00514
00515 const char *nameviews=argv[4];
00516 char nameview[128];
00517
00518
00519 FILE *params;
00520 int nviews;
00521 float P[3], u[3], v[3];
00522 params=fopen(argv[3], "r");
00523 int nread;
00524 nread=fscanf(params, "%i", &nviews);
00525 for (int n=0; n < nviews; n++) {
00526 nread=fscanf(params, "%f %f %f %f %f %f %f %f %f",
00527 &P[0], &P[1], &P[2], &u[0], &u[1], &u[2],
00528 &v[0], &v[1], &v[2]);
00529 getRGBview(img, nx, ny, Idsty, imgOut1, wview, hview, P, u, v);
00530
00531 nc=3;
00532 sprintf(nameview, "%s_%i.png", nameviews, 100+n);
00533 io_png_write_u8(nameview, imgOut1, wview, hview, nc);
00534 }
00535
00536 fclose(params);
00537
00538 free(img);
00539 free(imgOut1);
00540 if (Idsty) free(Idsty);
00541 }
00542
00543 if (!strcmp(argv[1], "combineviews")) {
00544
00545 int nviews;
00546 FILE *params=fopen(argv[2], "r");
00547 int nread;
00548 nread=fscanf(params, "%i", &nviews);
00549 fclose(params);
00550
00551 int wview, hview;
00552 unsigned char *img1, *img2, *img3, *imgOut1;
00553 imgOut1=NULL;
00554
00555 const char *nameviews1=argv[3];
00556 const char *nameviews2=argv[4];
00557 const char *nameviews3=argv[5];
00558 const char *nameviewsOut=argv[6];
00559 char nameview1[128], nameview2[128], nameview3[128], nameviewOut[128];
00560 for (int n=0; n < nviews; n++) {
00561 sprintf(nameview1, "%s_%i.png", nameviews1, 100+n);
00562 sprintf(nameview2, "%s_%i.png", nameviews2, 100+n);
00563 sprintf(nameview3, "%s_%i.png", nameviews3, 100+n);
00564 sprintf(nameviewOut, "%s_%i.png", nameviewsOut, 100+n);
00565
00566
00567 img1 = io_png_read_u8_rgb(nameview1, &nx, &ny);
00568 if (!img1) {
00569 fprintf(stderr, "Error reading input image or not a color image!\n");
00570 return EXIT_FAILURE;
00571 }
00572 img2 = io_png_read_u8_rgb(nameview2, &nx, &ny);
00573 if (!img2)
00574 {
00575 fprintf(stderr, "Error reading input image or not a color image!\n");
00576 free(img1);
00577 return EXIT_FAILURE;
00578 }
00579 img3 = io_png_read_u8_rgb(nameview3, &nx, &ny);
00580 if (!img3)
00581 {
00582 fprintf(stderr, "Error reading input image or not a color image!\n");
00583 free(img1);
00584 free(img2);
00585 return EXIT_FAILURE;
00586 }
00587 wview=(int) nx;
00588 hview=(int) ny;
00589
00590
00591 if (!imgOut1) imgOut1=(unsigned char *) malloc(3*(2*wview)*(2*hview));
00592
00593
00594 rgbprocess(img1, img2, img3, nx, ny,
00595 imgOut1, NULL, NULL, 0, 0, "combineviewsB");
00596
00597
00598
00599 nc=3;
00600 io_png_write_u8(nameviewOut, imgOut1, 2*nx, 2*ny, nc);
00601
00602
00603
00604 free(img1);
00605 free(img2);
00606 free(img3);
00607
00608 }
00609 free(imgOut1);
00610
00611 }
00612
00613 if (!strcmp(argv[1], "computeRMSE")) {
00614
00615
00616
00617 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00618 if (!img) {
00619 fprintf(stderr, "Error reading input image or not a color image!\n");
00620 return EXIT_FAILURE;
00621 }
00622
00623
00624 img2 = io_png_read_u8_rgb(argv[3], &nx, &ny);
00625 if (!img2) {
00626 fprintf(stderr,
00627 "Error reading reference input image or not a color image!\n");
00628 free(img);
00629 return EXIT_FAILURE;
00630 }
00631
00632 float rmse, dmean;
00633 rmse=computeRMSE(img, img2, nx, ny, dmean);
00634
00635 printf("The Root Mean Square Error (RMSE) between the original and \
00636 filtered color clouds is: %2.2f\n", rmse);
00637 printf("The Average Distance (dmean) between the original and filtered \
00638 color clouds is: %2.2f\n", dmean);
00639
00640
00641 free(img);
00642 free(img2);
00643 }
00644
00645 if (!strcmp(argv[1], "countcolors")) {
00646
00647
00648
00649 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00650 if (!img)
00651 {
00652 fprintf(stderr, "Error reading input image or not a color image!\n");
00653 return EXIT_FAILURE;
00654 }
00655
00656
00657 int nRGB;
00658 nRGB=countcolors(img, nx, ny);
00659
00660 printf("Number of colors of filtered image: %i\n", nRGB);
00661
00662
00663 free(img);
00664 }
00665
00666 if (!strcmp(argv[1], "RGB2VRML2")) {
00667
00668
00669
00670 img = io_png_read_u8_rgb(argv[2], &nx, &ny);
00671 if (!img)
00672 {
00673 fprintf(stderr, "Error reading input image or not a color image!\n");
00674 return EXIT_FAILURE;
00675 }
00676
00677
00678 unsigned char *Idsty=NULL;
00679 int displayDensity;
00680 sscanf(argv[4], "%i", &displayDensity);
00681 if (displayDensity == 1) {
00682 if (argc > 5) {
00683
00684 Idsty = io_png_read_u8_gray(argv[5], &nx, &ny);
00685 if (!Idsty) {
00686 fprintf(stderr, "Error reading density input image!\n");
00687 free(img);
00688 return EXIT_FAILURE;
00689 }
00690 } else {
00691 printf("compute density\n");
00692 Idsty=(unsigned char *) malloc(nx*ny);
00693 rgbprocess(img, NULL, NULL, nx, ny,
00694 Idsty, NULL, NULL, 0, 0, "densityImage");
00695 }
00696 }
00697
00698 RGB2VRML2(img, nx, ny, Idsty, argv[3]);
00699
00700
00701 free(img);
00702 if (Idsty) free(Idsty);
00703 }
00704
00705 return EXIT_SUCCESS;
00706 }