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

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : ima1.c
  3.  Purpose    : reading, writing and correlation of images
  4.  Date     : Aug 31,1995
  5. GSNAKE API is jointly developed by the Information Technology Institute (ITI), Singapore, and the School of Applied Science, Nanyang Technological
  6. University (NTU), Singapore. 
  7. 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.
  8. 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 :
  9. kflai@iti.gov.sg
  10. asschan@ntu.ac.sg
  11. ***************************************************************************/
  12. #include "xwindow.h"
  13. #include "gsnake.h"
  14. void testmain(char *,char *,char *,int );
  15. void printhelp();
  16. void getparam(int, char **, int *, char **, char **);
  17. main(int argc, char *argv[])
  18. {
  19. int i, j;
  20. int magnify;
  21. char *imgfile;
  22. char *tempfile=NULL;
  23. char *outfile = NULL;
  24. magnify =1;
  25. if (argc==1) printhelp();
  26. else {
  27. getparam(argc,argv,&magnify,&tempfile,&outfile);
  28. testmain(argv[1], tempfile,outfile,magnify);
  29. return(0);
  30. }
  31. }
  32. void testmain( char *imgfile, /* input image file */
  33.        char *tmpfile, /* image template */
  34.        char *outfile, /* output image file */
  35.        int mag ) /* magnification factor */
  36. {  
  37. IMAGE test1,test2;
  38. IMAGE *test3;
  39. /* Read test images */
  40. if ( test1.read(imgfile) )  exit(-1);
  41. printf("Showing test image : %s",imgfile);
  42. test1.show(mag);
  43. /* If user did not specify template image, use a gaussian template */
  44. if (tmpfile) {
  45. if( test2.read(tmpfile) ) exit( -1 ); 
  46. }
  47. else
  48. test2.initAsGauss();
  49. test2.show(mag); 
  50. printf("nCorrelating image..");
  51.    test3=test1.correlate(&test2,2,2,1); 
  52. /* Show all three images horizontally */
  53. /* Allocate window space for three images */
  54. test1.show(mag,3,0,0);
  55. /* Show images with offsets */
  56. test2.show(mag,1,test1.getCol());
  57. test3->show(mag,1,test2.getCol()+test1.getCol());
  58. printf("nPress enter to continue ");
  59. getchar();
  60. /* write result to file */
  61. if (outfile)
  62.    test3->write(outfile) ;
  63. else
  64.    test3->write("out.bin");
  65. printf("End of test..");
  66. xwin_close();
  67. }
  68. void getparam(int ac, char **av, int *Mfactor, char **temp, char **outfile)
  69. {   
  70. register int i;
  71. char *inputstr;
  72. for (i=2; i<ac; i++) 
  73. {
  74. if (*(av[i]) != '-') continue;
  75. inputstr = av[i]+2;
  76. switch( *(av[i]+1) ) {
  77.    case 'M' :
  78. *Mfactor=atoi(inputstr);
  79. break;
  80.    case 'T' :
  81.      *temp=inputstr;
  82.  break;
  83.    case 'O' :
  84.     *outfile = inputstr;
  85.     break;
  86.     default: break;
  87. };
  88. };
  89. };
  90. void printhelp()
  91. {
  92. printf("nnCorrelation of two images");
  93. printf("n Usage :OOima1 <image> -T<template> [ option ] ");
  94. printf("n [ option ]");
  95. printf("n -M    :Magnification factor, default 1 ");
  96. printf("n -O    :Output image file");
  97. printf("nn");
  98. }