Advertisement
sam2708

binary

Nov 15th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. /*******************************************************************/
  2. /*binary      Convert Image to Binary */
  3. /*******************************************************************/
  4.  
  5. #include "VisXV4.h"           /* VisionX structure include file    */
  6. #include "Vutil.h"            /* VisionX utility header files      */
  7. #include "stdlib.h"
  8.  
  9. VXparam_t par[] =             /* command line structure            */
  10. { /* prefix, value,   description                         */  
  11. {    "if=",    0,   " input file  vtemp: local max filter "},
  12. {    "of=",    0,   " output file "},
  13. {     0,       0,   0}  /* list termination */
  14. };
  15. #define  IVAL   par[0].val
  16. #define  OVAL   par[1].val
  17.  
  18. main(argc, argv)
  19. int argc;
  20. char *argv[];
  21. {
  22. Vfstruct (im);                      /* i/o image structure          */
  23. Vfstruct (tm);                      /* temp image structure         */
  24.  
  25. int        y,x;                     /* index counters               */
  26.   VXparse(&argc, &argv, par);       /* parse the command line       */
  27.  
  28.   Vfread(&im, IVAL);                /* read image file              */
  29.   Vfembed(&tm, &im, 1,1,1,1);       /* image structure with border  */
  30.  
  31.   if ( im.type != VX_PBYTE ) {      /* check image format           */
  32.      fprintf(stderr, "vtemp: no byte image data in input file\n");
  33.      exit(-1);
  34.   }
  35.   for (y = im.ylo ; y <= im.yhi ; y++) {  /* compute the function */
  36.      for (x = im.xlo; x <= im.xhi; x++)  {    
  37.         if (tm.u[y][x] < 128){
  38.        
  39.             im.u[y][x] = 255;      
  40.         }
  41.         else  {
  42.             im.u[y][x] = 0;      
  43.         }    
  44.      }
  45.    }
  46.  
  47.    Vfwrite(&im, OVAL);             /* write image file                */
  48.    exit(0);
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement