Advertisement
Guest User

pgmUtility.h

a guest
Mar 11th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 4.90 KB | None | 0 0
  1. //
  2. //  pgmUtility.h
  3. //  cscd240pgm
  4. //
  5. //  Created by Tony Tian on 11/2/13.
  6. //  Copyright (c) 2013 Tony Tian. All rights reserved.
  7. //
  8.  
  9. #ifndef cscd240pgm_pgmUtility_h
  10. #define cscd240pgm_pgmUtility_h
  11.  
  12. #include <math.h>
  13.  
  14. #define rowsInHeader 4      // number of rows in image header
  15. #define maxSizeHeadRow 200  // maximal number characters in one row in the header
  16.  
  17.  
  18.  
  19. /**
  20.  *  Function Name:
  21.  *      pgmRead()
  22.  *      pgmRead() reads in a pgm image using file I/O, you have to follow the file format.
  23.  *      
  24.  *  @param[in,out]  header  holds the header of the pgm file in a 2D character array
  25.  *                          After we process the pixels in the input image, we write the origianl
  26.  *                          header (or potentially modified) back to a new image file.
  27.  *  @param[in,out]  numRows describes how many rows of pixels in the image.
  28.  *  @param[in,out]  numCols describe how many pixels in one row in the image.
  29.  *  @param[in]      in      FILE pointer, points to an opened image file that we like to read in.
  30.  *  @return         If successful, return all pixels in the pgm image, which is an int **, equivalent to
  31.  *                  a 2D array. Otherwise null.
  32.  *
  33.  */
  34. int ** pgmRead( char **header, int *numRows, int *numCols, FILE *in  );
  35.  
  36.  
  37. /**
  38.  *  Function Name:
  39.  *      pgmDrawCircle()
  40.  *      pgmDrawCircle() draw a circle on the image by setting relavant pixels to Zero.
  41.  *
  42.  *  @param[in,out]  pixels  holds all pixels in the pgm image, which a 2D integer array. The array
  43.  *                          are modified after the drawing.
  44.  *  @param[in]      numRows describes how many rows of pixels in the image.
  45.  *  @param[in]      numCols describes how many columns of pixels in one row in the image.
  46.  *  @param[in]      centerCol specifies at which column you like to center your circle.
  47.  *  @param[in]      centerRow specifies at which row you like to center your circle.
  48.  *                        centerCol and centerRow defines the center of the circle.
  49.  *  @param[in]      radius    specifies what the radius of the circle would be, in number of pixels.
  50.  *  @param[in,out]  header returns the new header after draw.
  51.  *                  the circle draw might change the maximum intensity value in the image, so we
  52.  *                  have to change maximum intensity value in the header accordingly.
  53.  *  @return         return 1 if max intensity is changed, otherwise return 0;
  54.  */
  55. int pgmDrawCircle( int **pixels, int numRows, int numCols, int centerRow,
  56.                   int centerCol, int radius, char **header );
  57.  
  58.  
  59. /**
  60.  *  Function Name:
  61.  *      pgmDrawEdge()
  62.  *      pgmDrawEdge() draws a black edge frame around the image by setting relavant pixels to Zero.
  63.  *
  64.  *  @param[in,out]  pixels  holds all pixels in the pgm image, which a 2D integer array. The array
  65.  *                          are modified after the drawing.
  66.  *  @param[in]      numRows describes how many rows of pixels in the image.
  67.  *  @param[in]      numCols describes how many columns of pixels in one row in the image.
  68.  *  @param[in]      edgeWidth specifies how wide the edge frame would be, in number of pixels.
  69.  *  @param[in,out]  header returns the new header after draw.
  70.  *                  the function might change the maximum intensity value in the image, so we
  71.  *                  have to change the maximum intensity value in the header accordingly.
  72.  *
  73.  *  @return         return 1 if max intensity is changed by the drawing, otherwise return 0;
  74.  */
  75. int pgmDrawEdge( int **pixels, int numRows, int numCols, int edgeWidth, char **header );
  76.  
  77.  
  78.  
  79. /**
  80.  *  Function Name:
  81.  *      pgmWrite()
  82.  *      pgmWrite() writes headers and pixels into a pgm image using file I/O.
  83.  *                  writing back image has to strictly follow the image format.
  84.  *
  85.  *  @param[in]  header  holds the header of the pgm file in a 2D character array
  86.  *                          we write the header back to a new image file on disk.
  87.  *  @param[in]  pixels  holds all pixels in the pgm image, which a 2D integer array.
  88.  *  @param[in]  numRows describes how many rows of pixels in the image.
  89.  *  @param[in]  numCols describe how many columns of pixels in one row in the image.
  90.  *  @param[in]  out     FILE pointer, points to an opened text file that we like to write into.
  91.  *  @return     return 0 if the function successfully writes the header and pixels into file.
  92.  *                          else return -1;
  93.  */
  94. int pgmWrite( const char **header, const int **pixels, int numRows, int numCols, FILE *out );
  95.  
  96.  
  97. /**
  98.  *  Function Name:
  99.  *      distance()
  100.  *      distance() returns the Euclidean distance between two pixels.
  101.  *
  102.  *  @param[in]  p1  coordinates of pixel one, p1[0] is for row number, p1[1] is for column number
  103.  *  @param[in]  p2  coordinates of pixel two, p2[0] is for row number, p2[1] is for column number
  104.  *  @return         return distance between p1 and p2
  105.  */
  106. double distance( int p1[], int p2[] );
  107.  
  108.  
  109. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement