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

📄 delas.c

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




       /*****************************************************
       *
       *       file d:\cips\delas.c
       *
       *       Functions: This file contains
       *          main
       *          display_image_portion
       *          read_string
       *          read_image
       *          my_read
       *          get_image_name
       *          get_parameters
       *          show_parameters
       *          read_header
       *          color_transform
       *          display_menu
       *
       *       Purpose: This program displays images on the EGA 
       *          monitor.
       *          It can display either a 300x500 section of a 
       *          single
       *          channel of an image, or three channels of a 
       *          100x500
       *	  section of an image. This can use either a straight
       *	  mapping of 256 gray levels to 16 colors or a modified
       *	  mapping that brings out selected objects in the image.
       *
       *       Modifications:
       *          17 June 1987 - created
       *          8 August 1987 - added the ability to draw a
       *              grid over the image and label areas with
       *              a C or an L.
       *	  30 August 1987 - major changes made so that this is
       *              the only display routine needed.
       *           9 April 1988 - moved to Borland's Turbo C 1.5.
       *              This has a library of graphics routines that
       *	      are more reliable and execute faster.
       *	  13 September 1990 - put in function
       *	      blank_out_display to help reduce
       *	      the contrast when taking photos.
       *	  15 September 1990 - put the x_offset and
       *	      y_offset parameters in to center the
       *	      image display.
       *
       ********************************************************/


#include "d:\lsu\vision3.h"

   short image[ROWS][COLS];

main()
{
   char  channels[80],
         color_transform[80],
         file_name[80],
         response[80];

   int   a,
         b,
         c,
	 channel,
	 double_display,
	 horizontal,
         ie,
         il,
         key,
         le,
         ll,
         not_finished,
	 r,
	 vertical,
	 x_offset,
	 y_offset;


   unsigned int block,
                color,
                i,
                j,
                x,
                y;

   unsigned long histogram[256];


   _setvideomode(_TEXTC80);         /* MSC 6.0 statements */
   _setbkcolor(1);
   _settextcolor(7);
   _clearscreen(_GCLEARSCREEN);

   strcpy(file_name, "d:/images/nbrite.dat");
   strcpy(channels, "Single channel");
   strcpy(color_transform, "Modified transform");
   channel = 1;
   il      = 1;
   ll      = 100;
   ie      = 1;
   le	   = 100;
   horizontal = 5;
   vertical   = 4;
   double_display = 0;

   printf("\nThis is the display program.");
   printf("\nThis program can either display a 300x500 section of");
   printf("\nan image or three channels of a 100x500 section of an");
   printf("\nimage. The parameters entered describe the upper left");
   printf("\n100x100 corner of the display.");

   not_finished = 1;
   while(not_finished){

      display_menu(channels, color_transform);
      get_image_name(file_name);
      get_parameters(&channel, &il, &ie, &ll, &le,
		     &horizontal, &vertical, &double_display);


	/*******************************************
	*
	*   we want to set an offset so the image is
	*   centered on the CRT
	*
	********************************************/

	   x_offset = 0;
	   y_offset = 0;
	   x_offset = (6-horizontal)*100;
	   x_offset = 20 + x_offset/2;
	   y_offset = (4-vertical)*100;
	   y_offset = 40 + y_offset/2;



           /*********************************************
           *
           *   If the color_transform requires histogram
           *   equalization, then calculate the histogram
           *   from the four corners of the image.  You
           *   will use this in the display loop below
           *   to equalize the image.
           *
           **********************************************/

      if(color_transform[0] == 'H'){
         printf("\nCalculating histograms");
         zero_long_histogram(histogram);
         printf("\n\t1");
         read_image(image, file_name, channel, il, ie, ll, le);
         calculate_long_histogram(image, histogram);
         printf("\n\t2");
	 read_image(image, file_name, channel, il+400, ie,
		    ll+400, le);
         calculate_long_histogram(image, histogram);
         printf("\n\t3");
	 read_image(image, file_name, channel, il,
		    ie+400, ll, le+400);
         calculate_long_histogram(image, histogram);
         printf("\n\t4");
         read_image(image, file_name, channel, il+400, ie+400,
		    ll+400, le+400);
         calculate_long_histogram(image, histogram);
for(a=0; a<256; a++)
printf("\nh[%4d] = %8d", a, histogram[a]);
      }  /* ends if color_transform == H */


           /*********************************************
           *
           *   Find out what the key should be. This
           *   requires looking at the name of the image
           *   that is being displayed. Use a different
           *   key for the three different channels of
           *   the image.
           *
           **********************************************/

      key = 0;
      if(file_name[16] == '1')
         key = 1;
      if(file_name[16] == '2')
         key = 2;
      if(file_name[16] == '3')
         key = 3;
      if( (file_name[16] == '.') &&
          (channel == 1))
         key = 1;
      if( (file_name[16] == '.') &&
          (channel == 2))
         key = 2;
      if( (file_name[16] == '.') &&
          (channel == 3))
         key = 3;

  /* set graphics mode */
/*******
     map_16_shades_of_gray(_VRES16COLOR);
     blank_out_display();
********/

my_set_colors();




	  /***************************************************
          *
          *   If a single channel is desired then display a 300x500
	  *   section of one channel. If multiple channels
	  *   are desired then display one 100x500 section
	  *   of the image three times.
          *
	  *****************************************************/

      if( (channels[0] == 'S')  ||
	  (channels[0] == 's')){

	 for(a=0; a<horizontal; a++){
	    for(b=0; b<vertical; b++){
               x = a*100;
               y = b*100;
               read_image(image, file_name, channel, il+y, ie+x,
			   ll+y, le+x);

               if(color_transform[0] == 'H')
                  perform_histogram_equalization(image, histogram,
					      16, 40000);

	       if(double_display == 1){

		  if( (a==0) && (b==0)){
		    x_offset = 120;
		    y_offset = 40;
		  }

		  if( (a==0) && (b==1)){
		    x_offset = 120;
		    y_offset = 140;
		  }

		  if( (a==1) && (b==0)){
		    x_offset = 220;
		    y_offset = 40;
		  }

		  if( (a==1) && (b==1)){
		    x_offset = 220;
		    y_offset = 140;
		  }
	       }

               display_image_portion(image, key, color_transform,
				x, y, x_offset, y_offset,
				double_display);
            }  /* ends loop over b                   */
	 }     /* ends loop over a		     */

      }        /* ends if channels == Single channel */



      else{    /* else display three channels        */
         for(a=0; a<5; a++){    /*  Channel 1  */
            x = a*100;
            y =     0;
            read_image(image, file_name, 1, il+y, ie+x, ll+y,
			le+x);
            display_image_portion(image, key, color_transform, x,
				  y, x_offset, y_offset,
				  double_display);
         }  /* ends loop over a  */

         for(a=0; a<5; a++){    /*  Channel 2  */
            x = a*100;
            y =     0;
            color_transform[0] = 'S';
            read_image(image, file_name, 2, il+y, ie+x, ll+y,
		       le+x);
            display_image_portion(image, key, color_transform, x,
				  y+100, x_offset, y_offset,
				  double_display);
         }  /* ends loop over a  */

         for(a=0; a<5; a++){    /*  Channel 3  */
            x = a*100;
            y =     0;
            color_transform[0] = 'S';
            read_image(image, file_name, 3, il+y, ie+x, ll+y,
			le+x);
            display_image_portion(image, key, color_transform, x,
				  y+200, x_offset, y_offset,
				  double_display);
         }  /* ends loop over a  */
      }     /* ends else display multiple channels  */


/******************
      setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
      for(i=0; i<5; i++){
         line(0, i*100, 500, i*100);
      }

      for(i=0; i<6; i++){
         line(i*100, 0, i*100, 300);
      }


      setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
      for(i=0; i<13; i++){
         line(0, i*25, 500, i*25);
      }

      for(i=0; i<21; i++){
         line(i*25, 0, i*25, 300);
      }
******************/


/***********
setusercharsize(1, 2, 1, 2);
settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 0);
outtextxy(10, 320, "done");
***********/


/******************
    The following label the objects in the lower portion of the
image
outtextxy(400, 200, "041 house");
outtextxy(100, 25, "041 house");
outtextxy(100, 200, "040 apartments/hotel");
outtextxy(350, 50, "040 apartments/hotel");
outtextxy(10, 100, "200 decidous");
outtextxy(175, 150, "200 decidous");
*******************/


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

          /* set display back to text mode */
   _setvideomode(_TEXTC80);         /* MSC 6.0 statements */
   _setbkcolor(1);
   _settextcolor(7);
   _clearscreen(_GCLEARSCREEN);


   }  /* ends while not_finished  */

}  /* ends main  */



display_menu(channels, color_transform)
   char channels[], color_transform[];
{
   char response[80];
   int  not_finished, r;

   not_finished = 1;
   while(not_finished){
      printf("\n\nDISPLAY> Enter choice (0 for no change) ");
      printf("\nDISPLAY> 1. Channels-- %s", channels);
      printf("\nDISPLAY> 2. Color Transform-- %s",
	  color_transform);
      printf("\nDISPLAY> _\b");
      get_integer(&r);

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

      if(r == 1){
         printf("\nDISPLAY> Enter the new channel mode ");
	 printf("\nDISPLAY> (S) Single channel   (M) Multiple channel");
         printf("\nDISPLAY> _\b");
         read_string(response);
         if((response[0] == 'S') ||
            (response[0] == 's'))
               strcpy(channels, "Single channel");
         else
               strcpy(channels, "Multiple channels");
      }  /* ends if r == 1 */

      if(r == 2){
         printf("\nDISPLAY> Enter the new color transform mode ");
	 printf("\nDISPLAY> (S) Straight mode");
	 printf(" (M) Modified mode");
	 printf(" (R) Results mode");
	 printf(" (H) Histogram Equalization");
         printf("\nDISPLAY> _\b");
         read_string(response);
         if((response[0] == 'S') ||
            (response[0] == 's'))
               strcpy(color_transform, "Straight mode");
         if((response[0] == 'M') ||
            (response[0] == 'm'))
               strcpy(color_transform, "Modified mode");
         if((response[0] == 'H') ||
            (response[0] == 'h'))
	       strcpy(color_transform,
		   "Histogram Equalization Mode");
	 if((response[0] == 'R') ||
	    (response[0] == 'r'))
	       strcpy(color_transform,
		   "Results Mode");
      }  /* ends if r == 2  */

   }  /* ends while not_finished  */

}  /* ends display_menu  */






display_image_portion(image, key, desired_color_transform,
		      x, y, x_offset, y_offset,
		      double_display)
   char     desired_color_transform[];
   int	    key, x_offset, y_offset, double_display;
   short    image[ROWS][COLS];
   unsigned int x, y;
{
   unsigned int color, i, j;

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


            if(desired_color_transform[0] == 'H')
               color = image[i][j];
            else
               color = color_transform(image[i][j], key,
				    desired_color_transform);

	    /*putpixel(j+x, i+y, color);*/

	    _setcolor(color);

	    if(double_display == 1){
	       _setpixel( (j*2)+1 + x + x_offset, (i*2)+1 + y + y_offset);
	       _setpixel( (j*2)+1 + x + x_offset + 1, (i*2)+1 + y + y_offset);
	       _setpixel( (j*2)+1 + x + x_offset, (i*2)+1 + y + y_offset + 1);
	       _setpixel( (j*2)+1 + x + x_offset + 1, (i*2)+1 + y + y_offset + 1);
	    }
	    else
	       /***_setpixel(j+x+x_offset, i+y+y_offset);***/
my_set_pixel(j+x+x_offset, i+y+y_offset, lookup(color));

         }  /* ends loop over j  */
      }     /* ends loop over i  */

}  /* ends display_image_portion  */




read_string(string)
        char *string;
{
        int     eof,
                letter,
                no_error;

        eof = -1;
        no_error = 0;

        while((letter = getchar()) != '\n' &&
               letter !=  eof)
           *string++ = letter;

        *string = '\0';

        return((letter == eof) ? eof : no_error);

}       /* ends read_string */



clear_buffer(string)
   char string[];
{
   int i;
   for(i=0; i<MAX_NAME_LENGTH; i++)
      string[i] = ' ';
}



long_clear_buffer(string)
   char string[];
{
   int i;
   for(i=0; i<300; i++)
      string[i] = ' ';
}


       /***********************************************************
       *
       *       file c:\lsu\rdimage.c
       *
       *       Functions: This file contains
       *           read_image
       *
       *       Purpose: These functions read images from and write
       *          images to disk files using the ELAS image format.
       *
       *       External Calls:
       *          rhead.c - read_header
       *          whead.c - write_header
       *          mrw.c - my_read,
       *                  my_write
       *
       *       Modifications:
       *          July 86 - ported to IBM-PC
       *          29 September 86 - uses vision3.h instead of
       *              vision2.h
       *	   10 February 1987 - changed the images from int to
       *              short and the int_char_union was changed to
a
       *              short_char_union.
       *          12 June 1987 - ported to Borland Turbo C. The
       *              call to read and write were changed to
       *              my_read and my_write.
       *           12 June 1987 - one function, read_image, moved

⌨️ 快捷键说明

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