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

📄 delas.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 3 页
字号:
       *              from the file rwimage.c to this file.
       *
      
*************************************************************/


        /****************************************************
        *
        *       read_image(image, file_name, channel, il, ie, ll,
le)
        *
        *       This function will read in an elas image.
        *       The il and ie are given with the idea that
        *       the il and ie of the image are 1,1.
        *
        *       The image is packed into the array starting at
        *       location [0][0].
        *
        ****************************************************/


read_image(image, file_name, channel, il, ie, ll, le)

        int   ie, il, channel, ll, le;
        char  file_name[];
        short image[ROWS][COLS];

{
        int     file_closed,
                file_descriptor,
                i,
                j,
                last_i,
                last_j,
                nc,
                origin,
                position,
                read_file;

        char    in_buffer[512];

        long    current_position,
                line_length,
                offset;

        struct header_parameters par;

        union short_char_union scu;


        read_header(file_name, &par);

        line_length = par.le - par.ie + 1;
        if((line_length % 256) != 0)
           line_length = ((line_length/256) + 1) * 256;

        nc     = par.nc;

        last_i = ll;
        if(ll > ROWS)
           last_i = ROWS;
        last_j = le;
        if(le > COLS)
           last_j = COLS;

        file_descriptor = my_open(file_name);

        origin = 0;     /* seek from beginning of file */
        offset = (long)(header_size) + ((il-1)*nc +
(channel-1))*line_length;

        position = lseek(file_descriptor, offset, origin);

        for(i=0; i<last_i; i++){
           read_file = my_read(file_descriptor, in_buffer,
line_length);
           for(j=0; j<last_j; j++){
              scu.s_num      =            0;
              scu.s_alpha[0] = in_buffer[j+ie-1]; /********/
              image[i][j]    =    scu.s_num;
           }    /* ends loop over j COLS */

                        /*****************************************
                        *
                        *       If more than one channel in the
                        *       image then skip over the other
                        *       channels.
                        *
                        ******************************************/
           if(nc != 1){
              origin =                    1; /* seek from current
position */
              offset = (nc - 1)*line_length;
              lseek(file_descriptor, offset, origin);
           }

        }       /* ends loop over i ROWS */

        file_closed = close(file_descriptor);

}       /* ends read_image */

       /*****************************************************
       *
       *       file c:\lsu\mrw.c
       *
       *       Functions: This file contains
       *           my_read
       *           my_write
       *
       *       Purpose: These two functions call the Turbo C
       *           functions _read and _write. All software
       *           will use my_read and my_write so that if
       *           the software is ported to another system
       *           that uses read and write changing the
       *           two functions in this file will take care
       *           of the move.
       *
       *       External Call:
       *           _read
       *           _write
       *
       *       Modifications:
       *           10 June 1987 - created
       *
       *
      
************************************************************/


my_read(file_descriptor, buffer, number_of_bytes)
   int  file_descriptor, number_of_bytes;
   char *buffer;
{
   int read();
   read(file_descriptor, buffer, number_of_bytes);
}


my_write(file_descriptor, buffer, number_of_bytes)
   int  file_descriptor, number_of_bytes;
   char *buffer;
{
   int write();
   write(file_descriptor, buffer, number_of_bytes);
}
       
/***************************************************************
        *
        *       file c:\lsu\gin.c
        *
        *       Functions: This file contains
        *           get_image_name
        *
        *       Purpose - This function prompts the user to enter
the
        *            name of an image.
        *
        *       External Calls:
        *           rstring.c - read_string
        *                       clear_buffer
        *
        *       Modifications:
        *           26 September 86 - now uses vision3.h instead of
        *               vision2.h and the read_string and
get_integer
        *               instead of  scanf.
        *           11 March 1987 - this function was removed from
the
        *               file ip.c and put in file gin.c.
        *
       
***************************************************************/




get_image_name(name)

        char name[];
{
        char response[80];
        printf("\n\nImage name is--%s", name);
        printf("\nDo you want to change this name (Y/N)? _\b");
        clear_buffer(response);
        read_string(response);
        if((response[0] == 'Y') ||
           (response[0] == 'y')){
             printf("\n\nEnter image name\n--");
             read_string(name);
        }
}       /* ends get_image_name  */

       
/***************************************************************
        *
        *       file c:\lsu\gp.c
        *
        *       Functions: This file contains
        *           get_parameters
        *           show_parameters
        *
        *       Purpose - These functions get image parameters.
        *
        *       External Calls:
        *           rstring.c - read_string
        *           intcvrt.c - get_integer
        *
        *       Modifications:
        *           19 February 1987 - These functions were taken
out
        *               of the file ip.c.
        *
       
***************************************************************/



get_parameters(channel, il, ie, ll, le, h, v, dd)
	int *channel, *il, *ie, *le, *ll, *h, *v, *dd;
{
        int choice, not_finished;

        not_finished = 1;
        while(not_finished){
	   show_parameters(channel, il, ie, ll, le, h, v, dd);
	   printf("\n\nEnter choice to change");
	   printf(" (enter 0 for no changes) __\b\b");
           get_integer(&choice);

           switch (choice){
              case 0:
                 not_finished = 0;
                 break;

              case 1:
                 printf("\nEnter channel number\n_\b");
                 get_integer(channel);
                 break;

              case 2:
                 printf("\nEnter initial line\n___\b\b\b");
                 get_integer(il);
                 break;

              case 3:
                 printf("\nEnter initial element\n___\b\b\b");
                 get_integer(ie);
                 break;

              case 4:
                 printf("\nEnter last line\n___\b\b\b");
                 get_integer(ll);
                 break;

              case 5:
                 printf("\nEnter last element\n___\b\b\b");
                 get_integer(le);
		 break;

	      case 6:
		 printf("\nEnter horizontal \n___\b\b\b");
		 get_integer(h);
		 break;

	      case 7:
		 printf("\nEnter vertical \n___\b\b\b");
		 get_integer(v);
		 break;

	      case 8:
		 printf("\nEnter double display (1=on 0=off)");
		 printf("\n___\b\b\b");
		 get_integer(dd);
		 break;

           }  /* ends switch choice       */
        }     /* ends while not_finished  */
}             /* ends get_parameters      */


show_parameters(channel, il, ie, ll, le, h, v, dd)
	int *channel, *il, *ie, *le, *ll, *h, *v, *dd;
{

   printf("\n\nThe image parameters are:");
   printf("\n\t1. channel = %4d", *channel);
   printf("\n\t2.      il = %4d", *il);
   printf("\n\t3.      ie = %4d", *ie);
   printf("\n\t4.      ll = %4d", *ll);
   printf("\n\t5.      le = %4d", *le);
   printf("\n\t6.      horizontal = %d", *h);
   printf("\n\t7.      vertical   = %d", *v);
   printf("\n\t8.      double display = %d", *dd);

}  /* ends show_parameters  */

       
/***********************************************************
        *
        *        file c:\lsu\rhead.c
        *
        *        Functions: This file contains
        *            read_header
        *            show_header
        *
        *        Purpose: These functions read an ELAS image header
        *           and display its contents to the screen.
        *
        *        External Calls:
        *           unions.c - long_equate
        *                      float_equate
        *           mrw.c - my_read
        *
        *        Modifications:
        *            June 1986 - created
        *            26 September 1986 - uses vision3.h instead of
        *                vision2.h
        *            12 June 1987 - ported to Borland Turbo C. The
        *                call to read was changed to my_read.
        *
       
***********************************************************/


        /*********************************************
        *
        *       This function will read the header of
        *       an elas image and report the 
        *       parameters.
        *
        *********************************************/

read_header(file_name, params)

        char file_name[];
        struct header_parameters *params;

{

        int     closed_file,
                file_descriptor,
                i,
                read_file,
                value,
                written;

        char    in_buffer[header_size],
                line1[64],
                line2[64],
                line3[64],
                line4[64];

        union long_char_union  lcu;
        union float_char_union fcu;

                /*****************************************
                *
                *       Open the file, read in 1024 bytes
                *       and then proceed to pull out the
                *       bytes from the in_buffer.
                *
                ******************************************/

        file_descriptor = my_open(file_name);

        read_file = my_read(file_descriptor, in_buffer,
header_size);


        value = 0;
        long_equate(in_buffer, &lcu, value);
        params->nbih = lcu.l_num;

        
        value = 4;
        long_equate(in_buffer, &lcu, value);
        params->nbpr = lcu.l_num;

        value = 8;
        long_equate(in_buffer, &lcu, value);
        params->il = lcu.l_num;

        value = 12;
        long_equate(in_buffer, &lcu, value);
        params->ll = lcu.l_num;

        value = 16;
        long_equate(in_buffer, &lcu, value);
        params->ie = lcu.l_num;

        value = 20;
        long_equate(in_buffer, &lcu, value);
        params->le = lcu.l_num;

        value = 24;
        long_equate(in_buffer, &lcu, value);
        params->nc = lcu.l_num;

        value = 28;
        long_equate(in_buffer, &lcu, value);
        params->f321 = lcu.l_num;

        value = 36;
        long_equate(in_buffer, &lcu, value);
        params->y_offset = lcu.l_num;

        value = 40;
        for(i=0; i<4; i++)
           params->desc2[i] = in_buffer[value + i];

        value = 44;
        long_equate(in_buffer, &lcu, value);
        params->x_offset = lcu.l_num;

        value = 48;
        float_equate(in_buffer, &fcu, value);
        params->y_spot_size = fcu.f_num;

        value = 52;
        float_equate(in_buffer, &fcu, value);
        params->x_spot_size = fcu.f_num;

        value = 56;
        for(i=0; i<4; i++){
           float_equate(in_buffer, &fcu, (value+i*4));
           params->transform[i] = fcu.f_num;
        }

        value = 96;
        for(i=0; i<=256; i++)
           params->comments[i] = in_buffer[i + value];
        value = 32;
        for(i=0; i<4; i++)
           params->desc1[i] = in_buffer[value + i];


        closed_file = close(file_descriptor);

}       /* end of read_header */



        /*****************************************************
        *
        *       show_header(name, params)
        *
        *       This function shows the header input to the
        *       function.
        *
        *****************************************************/




show_header(name, params)

        char   name[];
        struct header_parameters *params;

{

        int     i;

        char    c,
                line1[64],
                line2[64],
                line3[64],
                line4[64],
                response[80];

        for(i=0; i<64; i++){
           line1[i] = params->comments[i];
           line2[i] = params->comments[i + 64];
           line3[i] = params->comments[i + 128];
           line4[i] = params->comments[i + 192];
        }
        line1[63] = '\0';
        line2[63] = '\0';
        line3[63] = '\0';
        line4[63] = '\0';


        printf("\nFile name is %s", name);
        printf("\nnbih=%d",params->nbih);
        printf("\nnbpr=%d",params->nbpr);
        printf("\nil=%d",params->il);
        printf("\nll=%d",params->ll);
        printf("\nie=%d",params->ie);
        printf("\nle=%d",params->le);
        printf("\nnc=%d",params->nc);
        printf("\n4321=%d",params->f321);
        printf("\nDescriptor1=%c%c%c%c",
           params->desc1[0],
           params->desc1[1],
           params->desc1[2],
           params->desc1[3]);
        printf("\ny offset=%d",params->y_offset);
        printf("\nDescriptor2=%c%c%c%c",
           params->desc2[0],
           params->desc2[1],
           params->desc2[2],
           params->desc2[3]);
        printf("\nx offset=%d",params->x_offset);
        printf("\ny spot size=%f",params->y_spot_size);
        printf("\nx spot size=%f",params->x_spot_size);
        printf("\nThe transform matrix is %f %f %f %f",
           params->transform[0],
           params->transform[1],
           params->transform[2],
           params->transform[3]);
        printf("\ncomments");
        printf("\n>%s",line1);
        printf("\n>%s",line2);
        printf("\n>%s",line3);
        printf("\n>%s",line4);

        printf("\nHit RETURN to continue");
        read_string(response);

}       /* end show_header */

        /*********************************************************
        *
        *       file c:\lsu\unions.c
        *
        *       Functions: This file contains
        *           long_equate
        *           float_equate
        *           store_long_into_buffer
        *           store_float_into_buffer
        *
        *       Purpose: These functions are used when reading and

⌨️ 快捷键说明

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