⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cips6.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 5 页
字号:
      }  /* ends if filter_type == 6 */

      if(filter_type == 9){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = lpf_filter_9[i][j];
           }
         }
      }  /* ends if filter_type == 9 */

      if(filter_type == 10){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = lpf_filter_10[i][j];
           }
         }
      }  /* ends if filter_type == 10 */


      if(filter_type == 16){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = lpf_filter_16[i][j];
           }
         }
      }  /* ends if filter_type == 16 */


      if(filter_type == 32){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = lpf_filter_32[i][j];
           }
         }
      }  /* ends if filter_type == 32 */
   }  /* ends low pass filter */




   if(low_high[0] == 'h'  || low_high[0] =='H'){
      if(filter_type == 1){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = hpf_filter_1[i][j];
           }
         }
      }  /* ends if filter_type == 1 */

      if(filter_type == 2){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = hpf_filter_2[i][j];
           }
         }
      }  /* ends if filter_type == 2 */

      if(filter_type == 3){
         for(i=0; i<3; i++){
           for(j=0; j<3; j++){
             filter[i][j] = hpf_filter_3[i][j];
           }
         }
      }  /* ends if filter_type == 3 */
   }  /* ends high pass filter */

}  /* ends setup_filters */



    /***********************************************
    *
    *    get_filter_options(...
    *
    *    This function queries the user for the
    *    parameters needed to perform filtering.
    *
    ***********************************************/


get_filter_options(filter_type, low_high)
    char low_high[];
    int  *filter_type;
{
    int not_finished, response;
    not_finished = 1;
    while(not_finished){

      printf("\nThe filter options are:\n");
      printf("\n\t1. Type of filter is %d",
              *filter_type);
      printf(
         "\n\t      (6, 9, 10, 16, 32 for low pass)");
      printf("\n\t      (1, 2, 3 for high pass)");
      printf("\n\t2. Low or High Pass filter is %s",
             low_high);
      printf("\n\t      l=low pass h=high pass "
             "m=median filter "
             "\n\t      i=high pixel o=low pixel");
      printf("\n\t      Type is the nxn size for"
            " median, high pixel, and low pixel");
      printf("\n\nEnter choice (0 = no change) _\b");


      get_integer(&response);

      if(response == 0){
        not_finished = 0;
      }

      if(response == 1){
        printf("\n\nEnter type of filter");
        printf("\n  _\b");
        get_integer(filter_type);
      }

      if(response == 2){
        printf("\n\nEnter l=low pass h=high pass "
              "m=median filter i=high pixel "
              "o=low pixel");
        printf("\n  _\b");
        gets(low_high);
      }
    }  /* ends while not_finished */

}  /* ends get_filter_options */


   /**************************************************
   *
   *   file d:\cips\display.c
   *
   *   Functions: This file contains
   *      display_image
   *      display_image_portion
   *      display_menu_for_display_image
   *      map_16_shades_of_gray
   *      my_map_64_shades_of_gray
   *      transform_the_colors
   *
   *   Purpose:
   *      These functions display images on a the
   *      monitor.
   *
   *      NOTE: This file is full of Microsoft
   *            specific code.  The PC C compiler
   *            makers all have their own routines
   *            for making dots appear on the
   *            screen.  I put the statement
   *            MSC 6.0 next to these calls.
   *
   *
   *   External Calls:
   *      rtiff.c - read_tiff_image
   *      cips.c - my_clear_text_screen
   *      hist.c - zero_histogram
   *               calculate_histogram
   *               perform_histogram_equalization
   *               display_histogram
   *
   *   Modifications:
   *      17 June 1987 - created
   *      August 1990 - extension modifications for use
   *          in the C Image Processing System.
   *
   ***************************************************/







   /***************************
   *
   *   display_image(...
   *
   ****************************/


display_image(file_name, image, il, ie, ll, le,
              image_header, monitor_type, 
              color_transform, invert, image_colors, 
              display_colors, show_hist, title)
   char    color_transform[],
           file_name[],
           monitor_type[],
           title[];
   int     display_colors,
           image_colors,
           invert,
           il,
           ie,
           ll,
           le,
           show_hist;
   short   image[ROWS][COLS];
   struct  tiff_header_struct *image_header;
{
   char  channels[80],
         response[80];

   int   a,
         b,
         c,
         channel,
         count,
         display_mode,
         dx_offset,
         dy_offset,
         key,
         horizontal,
         len,
         max_horizontal,
         max_vertical,
         not_finished,
         q,
         r,
         vertical,
         x_offset,
         y_offset;

   unsigned int block,
                color,
                i,
                j,
                x,
                y;
   unsigned long histogram[256], new_hist[256];


     /**********************************************
     *
     *   If you want to display the histogram and 
     *   do not want to perform hist equalization, 
     *   then zero the histogram for calculations.
     *
     **********************************************/

   if(  (show_hist == 1)   &&
        (color_transform[0] != 'H'))
      zero_histogram(histogram);

   not_finished = 1;
   while(not_finished){


      if(display_colors == 16){
         if(monitor_type[0] == 'V'){
            horizontal   = 4;
        vertical = 6;
        display_mode = VRES16COLOR; /* MSC 6.0 */
         }  /* ends if V */
         if(monitor_type[0] == 'E'){
            horizontal   = 3;
            vertical     = 6;
            display_mode = ERESCOLOR; /* MSC 6.0 */
         }  /* ends if E */

      }  /* ends if colors == 16 */

      else{
         horizontal   = 2;
         vertical     = 2;
         display_mode = MAXCOLORMODE; /* MSC 6.0 */
      }

        /********************************************
        *
        *   Somehow, my dx and dy offsets are 
        *   backwards from my horizontal and vertical 
        *   variables. Trying to center the images 
        *   on the screen. March 21 1992
        *
        ********************************************/

      max_horizontal = (image_header->image_length+50)
                       /COLS;
      max_vertical   = (image_header->image_width+50)
                       /ROWS;

      dy_offset = ((horizontal-max_horizontal)/2)
                  *COLS + 50;
      dx_offset = ((vertical-max_vertical)/2)
                  *ROWS + 20;

      if(max_horizontal > horizontal) dy_offset = 0;
      if(max_vertical > vertical)     dx_offset = 0;

      if(horizontal > max_horizontal) 
         horizontal = max_horizontal;
      if(vertical > max_vertical)     
         vertical   = max_vertical;


        /****************************************
        *
        *   If color transform wants histogram
        *   equalization, then read in the
        *   image arrays and calculate the
        *   histogram.   Zero both the histogram
        *   and the new_hist.  You will need the
        *   new_hist if you want to display the
        *   equalized hist.
        *
        *****************************************/

      if(color_transform[0] == 'H'){
         count = 1;
         zero_histogram(histogram);
         zero_histogram(new_hist);
         for(a=0; a<vertical; a++){
            for(b=0; b<horizontal; b++){

               x = a*COLS;
               y = b*ROWS;

               printf(
                  "\nDISPLAY> Calculating histogram");
               printf(" %d of %d",
                  count,vertical*horizontal);
               count++;
               read_tiff_image(file_name, image, il+y,
                            ie+x, ll+y, le+x);
               calculate_histogram(image, histogram);

            }  /* ends loop over b */
         }  /* ends loop over a */
      }  /* ends if display_mode == H */


        /* set graphics mode */

   my_setvideomode(display_mode); /* MSC 6.0 */
   if(display_colors == 16) 
      map_16_shades_of_gray(display_mode);
   if(display_colors == 256) 
      my_map_64_shades_of_gray();


        /****************************************
        *
        *   Loop over this size and
        *   read and display ROWSxCOLS arrays.
        *
        *   If you want to show the histogram AND
        *   do not want to do hist equalization
        *   then calculate the hist from the
        *   original image array.
        *
        *   If you want to do hist equalization
        *   then calculate the new_hist AFTER
        *   the image has been equalized by the
        *   the transform_the_colors function.
        *
        *   NOTE: Remember that the function
        *   transform_the_colors changes the
        *   gray shade values in image array.
        *
        *****************************************/

        /*****************************************
        *
        *   These statements place a gray 
        *   background across the display area of 
        *   a VGA screen.  This reduces the 
        *   contrast between the screen background 
        *   and the images you display. This makes 
        *   it easier to take photos.
        *
        *******************************************/

      /* MSC 6.0 */
      my_setlinestyle(0xFFFF);
      my_setcolor(10);
      for(i=0; i<640;i++){
         my_moveto(i, 0);
         my_lineto(i, 480);
      }

      for(a=0; a<vertical; a++){
         for(b=0; b<horizontal; b++){

            x = a*COLS;
            y = b*ROWS;
            read_tiff_image(file_name, image, il+y,
                            ie+x, ll+y, le+x);
            if(  (show_hist == 1)  &&
                 (color_transform[0] != 'H'))
               calculate_histogram(image, histogram);

            transform_the_colors(image, 
                                 color_transform,
                                 display_colors,
                                 image_colors, 
                                 histogram,
                                 horizontal, 
                                 vertical);

            if(color_transform[0] == 'H')
               calculate_histogram(image, new_hist);
          display_image_portion(image, x+dx_offset,
                                y+dy_offset, 
                                display_colors,
                                image_colors, invert);
         }        /* ends loop over b */
      }        /* ends loop over a */

          /*******************************************
          *
          *   Put in these statements to print a title 
          *   at the bottom of the display.  This is 
          *   nice for taking photos or articles 
          *   because it tells the reader what you 
          *   are trying to do.
          *
          ********************************************/

      /* MSC 6.0 */
      my_settextcolor(10);
      my_setbkcolor(1L);
      len = strlen(title);
      len = 40 - (len/2);
      my_settextposition(28, len);
      my_outtext(title);

         /***************************
         *
         *   if show_hist == 1 then
         *   display the histogram
         *   in the lower right hand
         *   corner of screen
         *
         *   If hist equalization was
         *   performed then show the
         *   new_hist.  If it wasn't
         *   done then show the original
         *   histogram.
         *
         ****************************/

      if(show_hist == 1){
         if(monitor_type[0] == 'V')
            y_offset = 470;
         if(monitor_type[0] == 'E')
            y_offset = 310;
         x_offset = 380;
         if(color_transform[0] == 'H')
            display_histogram(new_hist, x_offset,
                   y_offset, 5, 9);
         else{
            display_histogram(histogram, x_offset,
                   y_offset, 5, 9);
               /* xtra stuff for cips9
            display_histogram(histogram, 45,
                   370, 5, 9); */

               /*********************************
               *
               *   Change to show smoothed
               *   histogram next to the regular
               *   histogram.
               *
               **********************************/

               /* xtra stuff for cips9
            smooth_histogram(histogram);
            display_histogram(histogram, 345,
                   370, 5, 9); */
         }
      }

      gets(response);
      printf("\nEnter 0 to quit 1 to do again");
      get_integer(&not_finished);

          /* set display back to text mode */
      my_clear_text_screen();


   }  /* ends while not_finished  */

}  /* ends main  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -