home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillips / average.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  5.3 KB  |  184 lines

  1. #include "cips.h"
  2.  
  3. non_zero_overlay(in1_name, in2_name, out_name,
  4.           the_image, out_image,
  5.           il1, ie1, ll1, le1,
  6.           il2, ie2, ll2, le2,
  7.           il3, ie3, ll3, le3)
  8.    char   in1_name[], in2_name[], out_name[];
  9.    int    il1, ie1, ll1, le1,
  10.           il2, ie2, ll2, le2,
  11.           il3, ie3, ll3, le3;
  12.    short  the_image[ROWS][COLS],
  13.           out_image[ROWS][COLS];
  14. {
  15.    int    i, j, length, width;
  16.    struct tiff_header_struct image_header;
  17.  
  18.    create_file_if_needed(in1_name, out_name, out_image);
  19.  
  20.    read_tiff_image(in1_name, the_image,
  21.                    il1, ie1, ll1, le1);
  22.    read_tiff_image(in2_name, out_image,
  23.                    il2, ie2, ll2, le2);
  24.  
  25.    for(i=0; i<ROWS; i++){
  26.       if ( (i%10) == 0) printf(" %d", i);
  27.       for(j=0; j<COLS; j++){
  28.          if(the_image[i][j] != 0)
  29.             out_image[i][j] = the_image[i][j];
  30.       }  /* ends loop over j */
  31.    }  /* ends loop over i */
  32.  
  33.    write_array_into_tiff_image(out_name, out_image,
  34.                                il3, ie3, ll3, le3);
  35.  
  36. } /* ends non_zero_overlay */
  37.  
  38. /****************************************************/
  39.  
  40. zero_overlay(in1_name, in2_name, out_name,
  41.          the_image, out_image,
  42.          il1, ie1, ll1, le1,
  43.          il2, ie2, ll2, le2,
  44.          il3, ie3, ll3, le3)
  45.    char  in1_name[], in2_name[], out_name[];
  46.    int   il1, ie1, ll1, le1,
  47.          il2, ie2, ll2, le2,
  48.          il3, ie3, ll3, le3;
  49.    short the_image[ROWS][COLS],
  50.          out_image[ROWS][COLS];
  51. {
  52.    int    i, j, length, width;
  53.    struct tiff_header_struct image_header;
  54.  
  55.    create_file_if_needed(in1_name, out_name, out_image);
  56.  
  57.    read_tiff_image(in1_name, the_image,
  58.                    il1, ie1, ll1, le1);
  59.    read_tiff_image(in2_name, out_image,
  60.                    il2, ie2, ll2, le2);
  61.  
  62.    for(i=0; i<ROWS; i++){
  63.       if ( (i%10) == 0) printf(" %d", i);
  64.       for(j=0; j<COLS; j++){
  65.          if(the_image[i][j] == 0)
  66.             out_image[i][j] = the_image[i][j];
  67.       }  /* ends loop over j */
  68.    }  /* ends loop over i */
  69.  
  70.    write_array_into_tiff_image(out_name, out_image,
  71.                                il3, ie3, ll3, le3);
  72.  
  73. } /* ends zero_overlay */
  74.  
  75. /****************************************************/
  76.  
  77. greater_overlay(in1_name, in2_name, out_name,
  78.          the_image, out_image,
  79.          il1, ie1, ll1, le1,
  80.          il2, ie2, ll2, le2,
  81.          il3, ie3, ll3, le3)
  82.    char  in1_name[], in2_name[], out_name[];
  83.    int   il1, ie1, ll1, le1,
  84.          il2, ie2, ll2, le2,
  85.          il3, ie3, ll3, le3;
  86.    short the_image[ROWS][COLS],
  87.          out_image[ROWS][COLS];
  88. {
  89.    int    i, j, length, width;
  90.    struct tiff_header_struct image_header;
  91.  
  92.    create_file_if_needed(in1_name, out_name, out_image);
  93.  
  94.    read_tiff_image(in1_name, the_image,
  95.                    il1, ie1, ll1, le1);
  96.    read_tiff_image(in2_name, out_image,
  97.                    il2, ie2, ll2, le2);
  98.  
  99.    for(i=0; i<ROWS; i++){
  100.       if ( (i%10) == 0) printf(" %d", i);
  101.       for(j=0; j<COLS; j++){
  102.          if(the_image[i][j] > out_image[i][j])
  103.             out_image[i][j] = the_image[i][j];
  104.       }  /* ends loop over j */
  105.    }  /* ends loop over i */
  106.  
  107.    write_array_into_tiff_image(out_name, out_image,
  108.                                il3, ie3, ll3, le3);
  109.  
  110. } /* ends greater_overlay */
  111.  
  112. /****************************************************/
  113.  
  114. less_overlay(in1_name, in2_name, out_name,
  115.          the_image, out_image,
  116.          il1, ie1, ll1, le1,
  117.          il2, ie2, ll2, le2,
  118.          il3, ie3, ll3, le3)
  119.    char  in1_name[], in2_name[], out_name[];
  120.    int   il1, ie1, ll1, le1,
  121.          il2, ie2, ll2, le2,
  122.          il3, ie3, ll3, le3;
  123.    short the_image[ROWS][COLS],
  124.          out_image[ROWS][COLS];
  125. {
  126.    int    i, j, length, width;
  127.    struct tiff_header_struct image_header;
  128.  
  129.    create_file_if_needed(in1_name, out_name, out_image);
  130.  
  131.    read_tiff_image(in1_name, the_image,
  132.                    il1, ie1, ll1, le1);
  133.    read_tiff_image(in2_name, out_image,
  134.                    il2, ie2, ll2, le2);
  135.  
  136.    for(i=0; i<ROWS; i++){
  137.       if ( (i%10) == 0) printf(" %d", i);
  138.       for(j=0; j<COLS; j++){
  139.          if(the_image[i][j] < out_image[i][j])
  140.             out_image[i][j] = the_image[i][j];
  141.       }  /* ends loop over j */
  142.    }  /* ends loop over i */
  143.  
  144.    write_array_into_tiff_image(out_name, out_image,
  145.                                il3, ie3, ll3, le3);
  146.  
  147. } /* ends less_overlay */
  148.  
  149. /****************************************************/
  150.  
  151. average_overlay(in1_name, in2_name, out_name,
  152.          the_image, out_image,
  153.          il1, ie1, ll1, le1,
  154.          il2, ie2, ll2, le2,
  155.          il3, ie3, ll3, le3)
  156.    char  in1_name[], in2_name[], out_name[];
  157.    int   il1, ie1, ll1, le1,
  158.          il2, ie2, ll2, le2,
  159.          il3, ie3, ll3, le3;
  160.    short the_image[ROWS][COLS],
  161.          out_image[ROWS][COLS];
  162. {
  163.    int    i, j, length, width;
  164.    struct tiff_header_struct image_header;
  165.  
  166.    create_file_if_needed(in1_name, out_name, out_image);
  167.  
  168.    read_tiff_image(in1_name, the_image,
  169.                    il1, ie1, ll1, le1);
  170.    read_tiff_image(in2_name, out_image,
  171.                    il2, ie2, ll2, le2);
  172.  
  173.    for(i=0; i<ROWS; i++){
  174.       if ( (i%10) == 0) printf(" %d", i);
  175.       for(j=0; j<COLS; j++){
  176.          out_image[i][j] =
  177.             (the_image[i][j] + out_image[i][j])/2;
  178.       }  /* ends loop over j */
  179.    }  /* ends loop over i */
  180.  
  181.    write_array_into_tiff_image(out_name, out_image,
  182.                                il3, ie3, ll3, le3);
  183. } /* ends average_overlay */
  184.