home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / ASCENDER / ascendMar8.tar / UMass / BoldtNew / LLVS / convolve.c < prev    next >
C/C++ Source or Header  |  1996-01-31  |  2KB  |  85 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "signal2D.h"
  4. #include "llvs_per_plane.h"
  5.  
  6. /* CONVOLVE LLVS PLANE WITH A TEMPLATE */
  7.  
  8. void main(int argc, char *argv[])
  9. {
  10.   char *imagefilename, *templatefilename, *resultfilename;
  11.   PLANE *inplane, *outplane;
  12.   PLANE_INFO *inplane_info, *outplane_info;
  13.   static char *inassoc;
  14.   Signal_2D template;
  15.   float backval = 0.0;
  16.   Bool suc;
  17.  
  18.   if (!(argc == 4)) {
  19.     fprintf(stderr,
  20.         "Usage: convolve inimage.plane template.txt outimage.plane\n");
  21.     return;
  22.   }
  23.  
  24.   imagefilename = argv[1];
  25.   templatefilename = argv[2];
  26.   resultfilename = argv[3];
  27.  
  28.   /* READ IN 2D CONVOLUTION TEMPLATE */
  29.   suc = read_signal_2D(templatefilename, &template);
  30.   if(! suc) return;
  31.  
  32.   /* READ INPUT IMAGE PLANE */
  33.   if (read_plane(&inplane,&inplane_info,&inassoc,imagefilename) < 0) {
  34.     perror("convolve: read_plane");
  35.     fprintf(stderr,"convolve: read_plane could not read in plane %s\n",
  36.         imagefilename);
  37.     return;
  38.   }
  39.   if (!((inplane_info->datatype == LLVS_BYTE) ||
  40.     (inplane_info->datatype == LLVS_SHORT))) {
  41.     fprintf(stderr,"convolve: input plane type must be byte or short int\n");
  42.     fprintf(stderr,"convolve: input file name was %s\n", imagefilename);
  43.     return;
  44.   }
  45.     
  46.  
  47.   /* CREATE (FLOATING POINT) OUTPUT IMAGE PLANE */
  48.   if (new_plane(&outplane,&outplane_info,LLVS_FLOAT,inplane_info->level,
  49.         inplane_info->row_dimension, inplane_info->column_dimension,
  50.         inplane_info->row_location, inplane_info->column_location,
  51.         &backval) < 0) {
  52.     perror("convolve: new_plane");
  53.     fprintf(stderr,"convolve: new_plane could not allocate plane\n");
  54.     return;
  55.   }
  56.  
  57.   /* PERFORM THE CONVOLUTION */
  58.   if (inplane_info->datatype == LLVS_BYTE)
  59.     suc = byteIn_floatOut_signal_2D_convolve_edgecut(
  60.          (unsigned char*)inplane->plane_base,
  61.          inplane_info->column_dimension,
  62.          inplane_info->row_dimension,
  63.              &template,
  64.          (float*)outplane->plane_base);
  65.   else
  66.     suc = shortIn_floatOut_signal_2D_convolve_edgecut(
  67.          (short int*)inplane->plane_base,
  68.          inplane_info->column_dimension,
  69.          inplane_info->row_dimension,
  70.              &template,
  71.          (float*)outplane->plane_base);
  72.  
  73.   if(!suc) return;
  74.  
  75.   /* WRITE RESULT PLANE */
  76.   suc = write_plane(outplane,outplane_info,"NIL",resultfilename);
  77.   if(! suc) return;
  78.  
  79.   free_signal_2D(&template);
  80.   free(inplane); free(inplane_info);
  81.   free(outplane); free(outplane_info);
  82.  
  83.   return;
  84. }
  85.