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

📄 ht.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:
         }

         if(monitor_type[0] == 'E'){
            y_offset   = 310;
            x_offset   = 380;
            line_color = 3;
            data_color = 8;
         }

         if(monitor_type[0] == 'M'){
            y_offset   = 190;
            x_offset   = 60;
            line_color = 1;
            data_color = 1;
         }

         if(monitor_type[0] == 'C'){
            y_offset   = 190;
            x_offset   = 60;
            line_color = 1;
            data_color = 3;
         }

         if(color_transform[0] == 'S')
            display_histogram(histogram, x_offset,
                   y_offset, line_color, data_color);

         if(color_transform[0] == 'H')
            display_histogram(new_hist, x_offset,
                   y_offset, line_color, data_color);

      }  /* ends if show_hist == 1 and print == 0 */



      if(print == 1) 
         printf("\n\nHT> Hit ENTER to continue");
      gets(response);
      my_clear_text_screen();

}  /* ends main  */


#endif


       /*********************************************
       *
       *   half_tone(...
       *
       *   ep[m][n] = sum of erros propogated
       *               to position (m,n).
       *   eg[m][n] = total error generated at
       *               location (m,n).
       *
       **********************************************/

half_tone(in_image, out_image,
          threshold, 
          one, zero, 
          rows, cols)
   long  rows, cols;
   short threshold, one, zero;
   short **in_image, **out_image;
{
   float **eg, **ep;
   float c[2][3],
         sum_p,
         t;
   int   i, j, m, n, xx, yy;

   c[0][0] = 0.0;
   c[0][1] = 0.2;
   c[0][2] = 0.0;
   c[1][0] = 0.6;
   c[1][1] = 0.1;
   c[1][2] = 0.1;

      /***********************************************
      *
      *   Calculate the total propogated error
      *   at location(m,n) due to prior
      *   assignment.
      *
      *   Go through the input image.  If the output
      *   should be one then display that pixel as such.
      *   If the output should be zero then display it
      *   that way.
      *
      *   Also set the pixels in the input image array
      *   to 1's and 0's in case the print option
      *   was chosen.
      *
      ************************************************/

   eg = malloc(rows * sizeof(float  *));
   for(i=0; i<rows; i++){
      eg[i] = malloc(cols * sizeof(float ));
      if(eg[i] == '\0'){
         printf("\n\tmalloc of eg[%d] failed", i);
      }  /* ends if */
   }  /* ends loop over i */

   ep = malloc(rows * sizeof(float  *));
   for(i=0; i<rows; i++){
      ep[i] = malloc(cols * sizeof(float ));
      if(ep[i] == '\0'){
         printf("\n\tmalloc of ep[%d] failed", i);
      }  /* ends if */
   }  /* ends loop over i */

   for(i=0; i<rows; i++){
      for(j=0; j<cols; j++){
         eg[i][j] = 0.0;
         ep[i][j] = 0.0;
      }
   }


       /**********************************************
       *
       *   29 February 1988 - Fix to remove a solid 
       *   line at the bottom of each region. Loop 
       *   over ROWS-1 and then draw an extra line.
       *
       **********************************************/

   for(m=0; m<rows; m++){
      for(n=0; n<cols; n++){

         sum_p = 0.0;
         for(i=0; i<2; i++){
            for(j=0; j<3; j++){

               xx = m-i+1;
               yy = n-j+1;
               if(xx < 0)     xx = 0;
               if(xx >= rows) xx = rows-1;
               if(yy < 0)     yy = 0;
               if(yy >= cols) yy = cols-1;

               sum_p = sum_p + c[i][j] * eg[xx][yy];
            }  /* ends loop over j */
         }     /* ends loop over i */

         ep[m][n] = sum_p;
         t = in_image[m][n] + ep[m][n];

               /**********************************
               *
               *    Here set the point [m][n]=one
               *
               ***********************************/

         if(t > threshold){
            eg[m][n]        = t - threshold*2;
            out_image[m][n] = one;
         }  /* ends if t > threshold  */


               /**********************************
               *
               *    Here set the point [m][n]=zero
               *
               ***********************************/

         else{  /* t <= threshold */
            eg[m][n]        = t;
            out_image[m][n] = zero;
         }  /* ends else t <= threshold  */

      }  /* ends loop over n columns */
   }         /* ends loop over m rows */


   for(i=0; i<rows; i++){
      free(eg[i]);
      free(ep[i]);
   }


}  /*  ends half_tone  */





#ifdef NEVER


   /*******************************
   *
   *   get_threshold_value(...
   *
   ********************************/

get_threshold_value(threshold, print)
   int *print, *threshold;
{
   int i;
   printf("\nHT> The threshold = %d", *threshold);
   printf("\nHT> Enter new theshold value ");
   printf("(0 for no change) \n___\b\b\b");
   get_integer(&i);
   if((i != 0) && (i!= *threshold))
      *threshold = i;

   printf(
      "\nHT> print = %d (1 for print  0 for display)", 
      *print);
   printf("\nHT> Enter print value  \n_\b");
   get_integer(&i);
   *print = i;
}




   /********************************************
   *
   *   print_halftone_array(...
   *
   *   This function takes the halftoned images
   *   and prints it to a line printer.  If the
   *   image array has a 1 then print a ' '.
   *   If the image array has a 0 then print
   *   a '*'.
   *
   *********************************************/


print_halftone_array(image)
   short image[ROWS][COLS];
{
   char printer_name[80], response[80], string[101];
   FILE *printer;
   int        i, j, l, line_counter;

   line_counter = 0;

   strcpy(printer_name, "prn");

   if( (printer = fopen(printer_name, "w")) == NULL)
      printf("\nHT> Could not open printer");
   else{
      printf("\nOpened printer and now printing");

    /*************************************************
    *
    *   Loop over the rows in the image.  For each row
    *   first clear out the string print buffer.
    *   Then go through the columns and set the string
    *   to either '*' or ' '.  Finally, write the
    *   string out to the printer.
    *
    *************************************************/

   for(i=0; i<ROWS; i++){

      for(l=0; l<COLS+1; l++) string[l] = '\0';

      for(j=0; j<COLS; j++){
         if(image[i][j] == 1)
            string[j] = '*';
         else
            string[j] = ' ';
      }  /* ends loop over j columns */

      printf("%3d", i);
      fputs(string, printer);
      fputc('\n', printer);
      line_counter = line_counter + 1;
      if(line_counter >= 53){
         line_counter = 0;
         putc(FORMFEED, printer);
      }  /* ends if line_counter >=53  */

   }  /* ends loop over i rows */


   }  /* ends opened printer */

   putc(FORMFEED, printer);
   fclose(printer);

}  /* ends print_halftone_array */



#endif

⌨️ 快捷键说明

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