con2.c
Upload User: shhuayu888
Upload Date: 2013-03-28
Package Size: 1788k
Code Size: 5k
Category:

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : con2.c
  3.  Purpose    : 1. affine transformation of contour
  4.       2. learning of shape matrix
  5.  Date     : Aug 31,1995
  6. GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
  7. University (NTU), Singapore. 
  8. These software programs are available to the user without any license or royalty fees. Permission is hereby granted to use, copy, modify, and distribute this software and its documentation for any purpose. ITI and NTU gives no warranty, express, implied, or statuary for the software and/or documentation provided, including, without limitation, waranty of merchantibility and warranty of fitness for a particular purpose. The software provided hereunder is on an "as is"  basis, and ITI and NTU has no obligation to provide maintenance, support, updates, enhancements, or modifications.
  9. GSNAKE API is available for any UNIX compatible system. User feedback, bugs, or software and manual suggestions should be sent via electronic mail to one of the following, who may or may not act on them as he/she desires :
  10. asschan@ntu.ac.sg
  11. kflai@iti.gov.sg
  12. ***************************************************************************/
  13. #include "gsnake.h"
  14. #include "xwindow.h"
  15. void testmain(char *, int, double ,int ,int, double, double, double, double, char*);
  16. void printhelp();
  17. void getparam(int ac, char** av,double *ang, int *tx,int *ty, 
  18.       double *sx, double *sy, double *dx,double *dy, int *mag, char **outfile);
  19. main(int argc,char **argv)
  20. {
  21. double Rangle;
  22. int tx,ty;
  23. double dx,dy;
  24. double sx, sy;
  25. int mag =1;
  26. char *outfile = NULL;
  27. Rangle = 0;
  28. tx = ty = 0;
  29. sx = sy = 1;
  30. dx = dy = 0.0;
  31. if (argc==1) printhelp();
  32. else {
  33. getparam(argc,argv,&Rangle, &tx, &ty, &sx, &sy,
  34.  &dx, &dy, &mag, &outfile);
  35. testmain(argv[1], mag, Rangle,tx,ty,sx,sy,dx,dy,outfile);
  36. return(0);
  37. }
  38. }
  39. void testmain( char *confile,  /* contour file */
  40.        int mag,  /* magnification factor */
  41.        double angle, /* rotation angle */
  42.        int tx, int ty, /* translation vector */
  43.        double sx, double sy, /* scaling factor */
  44.        double dx, double dy,  /* dilution vector */
  45.        char *outfile) /* output file */
  46. {
  47. CONTOUR mycontour; /* CONTOUR object */
  48. SNAXEL *sptr; /* SNAXEL object */
  49. register short i;
  50. double temp;
  51. /* read a contour file */
  52. if (mycontour.read(confile)) exit(-1);
  53. mycontour.display(mag);
  54. /* Calculate average length and internal energy of snaxel */
  55. temp = mycontour.computeAvgLength();
  56. mycontour.computeShape();
  57. mycontour.print();
  58. for(i=0, sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
  59. printf("nEmodel of snaxel %d = %f",i,mycontour.EInternal(sptr));
  60. printf("nPress enter to continue");
  61. getchar();
  62. /* affine transformation should be done in contour centered formed */
  63. mycontour.contourCentered();
  64. mycontour.affineTransform( sx, sy, angle, tx, ty, dx, dy );
  65. printf("nShowing contour after transformations.");
  66. mycontour.imageCentered();
  67. mycontour.computeCG();
  68. mycontour.display(mag);
  69. printf("nPress enter to continue");
  70. getchar();
  71. /* internal energy should be invariant to affine transforms */
  72. printf("nPerforming internal energy calculation after transforms.n");
  73. for(i=0, sptr=mycontour.getHead(); sptr; sptr=sptr->getNext(), i++)
  74. printf("nEmodel of snaxel %d = %f", i, mycontour.EInternal(sptr));
  75. /* Performing shape learning */
  76. printf("nnContour and snaxel co-efficients after learning.n");
  77. printf("nAverage distance: %fn",temp);
  78. mycontour.computeShape();
  79. mycontour.display();
  80. mycontour.print();
  81. printf("nPress enter to continue");
  82. getchar();
  83. /* write contour to output file */
  84. if (outfile) {
  85.     printf("nWriting contour to file %s", outfile);
  86.     mycontour.write(outfile); 
  87. }
  88. }
  89. void getparam( int ac, char** av,
  90.        double *ang, int *tx, int *ty, 
  91.        double *sx, double *sy, 
  92.        double *dx,double *dy, 
  93.        int *mag, char **outfile)
  94. {   
  95. register int i;
  96. char *inputstr;
  97. for (i=1; i<ac; i++) {
  98. if( *av[i] != '-' )
  99. continue; /* illegal input */
  100. inputstr = av[i]+2;
  101. switch( *(av[i]+1) ) {
  102.  
  103.    case 't' :
  104. inputstr=av[i]+3;
  105. switch (*(av[i]+2)) {
  106.    case 'x': *tx = atoi(inputstr); break;
  107.    case 'y': *ty = atoi(inputstr);break;
  108. }
  109. break;
  110.       case 's' :
  111. inputstr=av[i]+3;
  112. switch (*(av[i]+2)) {
  113.    case 'x': *sx = atof(inputstr); break;
  114.    case 'y': *sy = atof(inputstr);break;
  115. }
  116. break;
  117.   case 'd' :
  118. inputstr=av[i]+3;
  119. switch (*(av[i]+2)) {
  120.    case 'x': *dx = atof(inputstr); break;
  121.    case 'y': *dy = atof(inputstr);break;
  122. }
  123. break;
  124.    case 'M' :
  125. *mag=atoi(inputstr);
  126. break;
  127.    case 'O' :
  128.    *outfile=inputstr;
  129. break;
  130.    case 'r' :
  131.     *ang = atof(inputstr);
  132.     break;
  133.     default: break;
  134. }
  135. }
  136. }
  137. void printhelp()
  138. {
  139. printf("nnTransformation of arbitrary contour");
  140. printf("n Usage :OOcon2 <contour> [ option ]");
  141. printf("n [ option]");
  142. printf("n -M    : Magnification factor, default 1");
  143. printf("n -r    : Rotation. Angle in degrees.");
  144. printf("n -t    : Translation in x or y direction");
  145. printf("n -s    : Scaling in x or y direction");
  146. printf("n -d    : Dilation in x and y direction");
  147. printf("n -O    : Output image filenn");
  148. }