home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_10 / 1010092a < prev    next >
Text File  |  1992-08-11  |  4KB  |  138 lines

  1.        /***********************************************
  2.        *
  3.        *       file d:\cips\mainfilt.c
  4.        *
  5.        *       Functions: This file contains
  6.        *          main
  7.        *
  8.        *       Purpose:
  9.        *          This file contains the main calling
  10.        *          routine in an image filtering program.
  11.        *
  12.        *       External Calls:
  13.        *          gin.c - get_image_name
  14.        *          numcvrt.c - get_integer
  15.        *                      int_convert
  16.        *          tiff.c - read_tiff_header
  17.        *          filter.c - filter_image
  18.        *                     median_filter
  19.        *
  20.        *       Modifications:
  21.        *          15 February 1992 - created
  22.        *
  23.        *************************************************/
  24.  
  25. #include "d:\cips\cips.h"
  26.  
  27.  
  28. short the_image[ROWS][COLS];
  29. short out_image[ROWS][COLS];
  30.  
  31. main(argc, argv)
  32.    int argc;
  33.    char *argv[];
  34. {
  35.  
  36.    char     name[80], name2[80], low_high[80];
  37.    int      count, i, ie, il, j, le, length, ll, lw,
  38.             type, width;
  39.    short    filter[3][3];
  40.    struct   tiff_header_struct image_header;
  41.  
  42.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  43.    _setbkcolor(1);
  44.    _settextcolor(7);
  45.    _clearscreen(_GCLEARSCREEN);
  46.  
  47.        /***********************************************
  48.        *
  49.        *       Interpret the command line parameters.
  50.        *
  51.        ************************************************/
  52.  
  53.    if(argc < 5){
  54.     printf(
  55.  
  56.     "\n\nNot enough parameters:"
  57.      "\n"
  58.      "\n   usage: mainfilt in-file out-file type low-or-high-pass"
  59.      "\n"
  60.      "\n   recall type: 6, 9, 10, 16 for low pass"
  61.      "\n   recall type: 1, 2, 3 for high pass"
  62.      "\n   recall type: is the size of the nxn area for median 
  63. filtering"
  64.      "\n   low-or-high-pass l=low pass h=high pass "
  65.     "\n                    m=median filter "
  66.      "\n");
  67.     exit(0);
  68.    }
  69.  
  70.    strcpy(name, argv[1]);
  71.    strcpy(name2, argv[2]);
  72.    int_convert(argv[3], &type);
  73.    strcpy(low_high, argv[4]);
  74.  
  75.    il = 1;
  76.    ie = 1;
  77.    ll = ROWS+1;
  78.    le = COLS+1;
  79.  
  80.        /***********************************************
  81.        *
  82.        *       Read the input image header and setup 
  83.        *       the looping counters.
  84.        *
  85.        *       If high or low pass filtering, setup
  86.        *       the filter mask array.
  87.        *
  88.        ************************************************/
  89.  
  90.    read_tiff_header(name, &image_header);
  91.  
  92.    length = (90 + image_header.image_length)/ROWS;
  93.    width  = (90 + image_header.image_width)/COLS;
  94.    count  = 1;
  95.    lw     = length*width;
  96.    printf("\nlength=%d  width=%d", length, width);
  97.  
  98.    if(low_high[0] == 'l' ||
  99.       low_high[0] == 'L' ||
  100.       low_high[0] == 'h' ||
  101.       low_high[0] == 'H')
  102.          setup_filters(type, low_high, filter);
  103.  
  104.        /***********************************************
  105.        *
  106.        *       Loop over the input image and filter it
  107.        *       using either the high or low pass filters
  108.        *       using a mask OR using the median filter.
  109.        *
  110.        ************************************************/
  111.  
  112.    for(i=0; i<length; i++){
  113.       for(j=0; j<width; j++){
  114.          printf("\nrunning %d of %d", count, lw);
  115.          count++;
  116.  
  117.  
  118.          if(low_high[0] == 'l' ||
  119.             low_high[0] == 'L' ||
  120.             low_high[0] == 'h' ||
  121.             low_high[0] == 'H')
  122.               filter_image(name, name2, the_image, out_image,
  123.                            il+i*ROWS, ie+j*COLS, ll+i*ROWS,
  124.                            le+j*COLS, filter, type);
  125.  
  126.          if(low_high[0] == 'm' ||
  127.             low_high[0] == 'M')
  128.               median_filter(name, name2, the_image,
  129.                 out_image,
  130.                            il+i*ROWS, ie+j*COLS, ll+i*ROWS,
  131.                            le+j*COLS, type);
  132.  
  133.  
  134.       }  /* ends loop over j */
  135.    }  /* ends loop over i */
  136. }  /* ends main  */
  137.  
  138.