home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CUJJUN93.ZIP / 1106074A < prev    next >
Text File  |  1993-04-08  |  5KB  |  164 lines

  1.      /*******************************************
  2.      *
  3.      *   high_pixel(..
  4.      *
  5.      *   This function replaces the pixel at
  6.      *   the center of a 3x3, 5x5, etc. area
  7.      *   with the max for that area.
  8.      *
  9.      *******************************************/
  10.  
  11. high_pixel(in_name, out_name, the_image, out_image,
  12.            il, ie, ll, le, size)
  13.    char   in_name[], out_name[];
  14.    int    il, ie, ll, le, size;
  15.    short  the_image[ROWS][COLS],
  16.           out_image[ROWS][COLS];
  17. {
  18.    int    a, b, count, i, j, k,
  19.           length, sd2, sd2p1, ss, width;
  20.    short  *elements;
  21.    struct tiff_header_struct image_header;
  22.  
  23.    sd2   = size/2;
  24.    sd2p1 = sd2 + 1;
  25.  
  26.       /**********************************************
  27.       *
  28.       *   Allocate the elements array large enough
  29.       *   to hold size*size shorts.
  30.       *
  31.       **********************************************/
  32.  
  33.    ss       = size*size;
  34.    elements = (short *) malloc(ss * sizeof(short));
  35.  
  36.    if(does_not_exist(out_name)){
  37.       printf("\n\n output file does not exist %s", 
  38.              out_name);
  39.       read_tiff_header(in_name, &image_header);
  40.       round_off_image_size(&image_header,
  41.                            &length, &width);
  42.       image_header.image_length = length*ROWS;
  43.       image_header.image_width  = width*COLS;
  44.       create_allocate_tiff_file(out_name, &image_header,
  45.                                 out_image);
  46.    }  /* ends if does_not_exist */
  47.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  48.  
  49.       /***************************
  50.       *
  51.       *   Loop over image array
  52.       *
  53.       ****************************/
  54.  
  55.    printf("\n");
  56.    for(i=sd2; i<ROWS-sd2; i++){
  57.       if( (i%10) == 0) printf("%d ", i);
  58.       for(j=sd2; j<COLS-sd2; j++){
  59.          count = 0;
  60.          for(a=-sd2; a<sd2p1; a++){
  61.             for(b=-sd2; b<sd2p1; b++){
  62.                elements[count] = the_image[i+a][j+b];
  63.                count++;
  64.             }
  65.          }
  66.          sort_elements(elements, &ss);
  67.          out_image[i][j] = elements[ss-1];
  68.       }  /* ends loop over j */
  69.    }  /* ends loop over i */
  70.  
  71.    fix_edges(out_image, sd2);
  72.  
  73.    write_array_into_tiff_image(out_name, out_image,
  74.                                il, ie, ll, le);
  75.  
  76.    free(elements);
  77.  
  78. }  /* ends high_pixel */
  79.  
  80.  
  81.  
  82.  
  83.      /*******************************************
  84.      *
  85.      *   low_pixel(..
  86.      *
  87.      *   This function replaces the pixel at
  88.      *   the center of a 3x3, 5x5, etc. area
  89.      *   with the min for that area.
  90.      *
  91.      *******************************************/
  92.  
  93. low_pixel(in_name, out_name, the_image, out_image,
  94.           il, ie, ll, le, size)
  95.    char   in_name[], out_name[];
  96.    int    il, ie, ll, le, size;
  97.    short  the_image[ROWS][COLS],
  98.           out_image[ROWS][COLS];
  99.  
  100. {
  101.    int    a, b, count, i, j, k,
  102.           length, sd2, sd2p1, ss, width;
  103.    short  *elements;
  104.    struct tiff_header_struct image_header;
  105.  
  106.    sd2   = size/2;
  107.    sd2p1 = sd2 + 1;
  108.  
  109.       /**********************************************
  110.       *
  111.       *   Allocate the elements array large enough
  112.       *   to hold size*size shorts.
  113.       *
  114.       **********************************************/
  115.  
  116.    ss       = size*size;
  117.    elements = (short *) malloc(ss * sizeof(short));
  118.  
  119.    if(does_not_exist(out_name)){
  120.       printf("\n\n output file does not exist %s", 
  121.              out_name);
  122.       read_tiff_header(in_name, &image_header);
  123.       round_off_image_size(&image_header,
  124.                            &length, &width);
  125.       image_header.image_length = length*ROWS;
  126.       image_header.image_width  = width*COLS;
  127.       create_allocate_tiff_file(out_name, &image_header,
  128.                                 out_image);
  129.    }  /* ends if does_not_exist */
  130.  
  131.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  132.  
  133.       /***************************
  134.       *
  135.       *   Loop over image array
  136.       *
  137.       ****************************/
  138.  
  139.    printf("\n");
  140.    for(i=sd2; i<ROWS-sd2; i++){
  141.       if( (i%10) == 0) printf("%d ", i);
  142.       for(j=sd2; j<COLS-sd2; j++){
  143.          count = 0;
  144.          for(a=-sd2; a<sd2p1; a++){
  145.             for(b=-sd2; b<sd2p1; b++){
  146.                elements[count] = the_image[i+a][j+b];
  147.                count++;
  148.             }
  149.          }
  150.          sort_elements(elements, &ss);
  151.          out_image[i][j] = elements[0];
  152.       }  /* ends loop over j */
  153.    }  /* ends loop over i */
  154.  
  155.    fix_edges(out_image, sd2);
  156.  
  157.    write_array_into_tiff_image(out_name, out_image,
  158.                                il, ie, ll, le);
  159.  
  160.    free(elements);
  161.  
  162. }  /* ends low_pixel */
  163.  
  164.