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

Windows Develop

Development Platform:

Unix_Linux

  1. /****************************************************************************
  2.  File Name  : imgcond.c
  3.  Purpose    : histogram conditioning
  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. asschan@ntu.ac.sg
  10. kflai@iti.gov.sg
  11. ***************************************************************************/
  12. #include "xwindow.h"
  13. #include "gsnake.h"
  14. void printhelp();
  15. void getparam(int, char** ,char **,int *, int *,float*, float*,float*, float*, float*);
  16. main(int argc, char *argv[])
  17. {
  18. IMAGE myimage; /* image object */
  19. int magnify = 1; /* magnification factor */
  20. int filetype = _ras; /* image file format */
  21. float low_p = 0; /* low percentage */
  22. float high_p = 1; /* high percentage */
  23. float low_v = 0; /* low intensity value */
  24. float high_v = 1; /* high intensity value */
  25. float epow = 1; /* exponential power */
  26. char *filename = NULL; /* output file name */
  27. char Title[30] = "imgcond : ";
  28. short register i, j;
  29. if ( argc==1 ) printhelp();
  30. else {
  31.     xwin_setTitle(strcat(Title,argv[1]));
  32.     getparam( argc, argv, &filename, &filetype, &magnify,
  33.       &low_p, &high_p, &low_v,&high_v, &epow);
  34.     if  (!(myimage.read(argv[1]))) { 
  35. printf("Histogram Specification parameters :n");
  36. printf("ntLow Percent:%ftHigh Percent:%f",low_p,high_p);
  37. printf("ntLow Value  :%ftHigh Value  :%f",low_v,high_v);
  38. printf("ntExponent   :%ftMagnification:%d",epow,magnify);
  39. myimage.show( magnify, 2 );
  40. myimage.condition( low_p, high_p, low_v, high_v, epow );
  41. myimage.show( magnify, 1, myimage.getCol()*magnify );
  42. printf("Press enter to continuen");
  43. getchar();
  44. if (filename)
  45.    if ( myimage.write(filename,filetype) ) 
  46. printf("nnUnable to write file %sn", filename);
  47.     }
  48.     xwin_close();
  49.     return NOERROR;
  50. }
  51. }
  52. void getparam( int ac, char** av,
  53.        char **fname, /* output file name */
  54.        int *ftype, /* output file type */
  55.        int *Mfactor, /* magnification factor */
  56.        float* lp, /* low percentage */
  57.        float *hp, /* high percentage */
  58.        float *lv, /* low intensity */
  59.        float*hv, /* high intensity */
  60.        float *e_pow ) /* exponential power */
  61. {   
  62. register int i;
  63. char *inputstr;
  64. for (i=2; i<ac; i++) {
  65. if (*(av[i]) != '-') continue;
  66. inputstr = av[i]+2;
  67. switch( *(av[i]+1) ) {
  68.    case 'O':
  69. if (*(av[i]+2) =='/') 
  70. {
  71.  *ftype =_ras;
  72.  inputstr = av[i]+3;
  73. }
  74. else *ftype =_bin;
  75. *fname = inputstr;
  76. break;
  77.    case 'M' :
  78. *Mfactor=atoi(inputstr);
  79. break;
  80.    case 'P' :
  81. inputstr=av[i]+3;
  82. switch (*(av[i]+2)) {
  83.    case 'l': *lp=atof(inputstr); break;
  84.    case 'h': *hp=atof(inputstr);break;
  85. }
  86. break;
  87.    case 'V' :
  88. inputstr = av[i]+3;
  89. switch( *(av[i]+2) ) {
  90.    
  91.    case 'l' :  *lv = atof(inputstr);break;
  92.    case 'h' :  *hv = atof(inputstr);break;
  93. }
  94. break;
  95.    case 'E' :
  96. *e_pow=atof(inputstr);
  97.  break;
  98.     default: break;
  99. }
  100. }
  101. }
  102. void printhelp()
  103. {
  104. printf("nn Histogram conditioning of image");
  105. printf("n Usage :imgcond <image> -[option]<value>");
  106. printf("n [ option ]");
  107. printf("n O    : Output filename,");
  108. printf("n /    : Save file as sun rasterfile type");
  109. printf("n M    : Magnification factor, default 1 ");
  110. printf("n Pl,Ph: Low and High Percentage values ");
  111. printf("n      : Default Pl = 0 , Ph = 1");
  112. printf("n Vl,Vh: Low and High Pixel values ");
  113. printf("n      : Default Vl = 0 , Vh = 1n");
  114. printf("n Using imgcond with defaults is equivalent to histogram equalisation.nn") ;
  115. }