Guest User

Untitled

a guest
Jul 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1. #include "Image.h"
  2. #include <iostream>
  3. #include <complex>
  4.  
  5. using namespace std;
  6.  
  7. #define Usage "makeSwirl inImg outImg coeffn"
  8.  
  9. /*
  10. * arg1 is the image to transform.
  11. * arg2 is the swirl coefficient
  12. * Returns image with enhanced edges.
  13. */
  14. Image swirl(const Image&, const float&);
  15. /*
  16. * arg1 is the image within which the pixel to be transformed is located.
  17. * arg2&3&4 are the row, colum, and channel of the pixel to transform.
  18. * arg5 is the swirl coefficient
  19. * arg6&7 are the rows and cols of arg1.
  20. * returns transformed pixel.
  21. */
  22. float onePixelSwirl(const Image&, const int&, const int&, const int&, const double&, const int&, const int&);
  23.  
  24. int main(int argc, char **argv)
  25. {
  26. // Check for proper number of arguments.
  27. if(argc != 4)
  28. {
  29. cout << Usage;
  30. exit(3);
  31. }
  32.  
  33. // Read in image specified by user.
  34. const Image IN_IMG = readImage(argv[1]);
  35.  
  36. // Create output image with oil effect.
  37. Image outImg = swirl(IN_IMG, atof(argv[3]));
  38.  
  39. // Output the image
  40. writeImage(outImg, argv[2]);
  41.  
  42. // Success!
  43. return(0);
  44. }
  45.  
  46. Image swirl(const Image& IN_IMG, const float& COEFF)
  47. {
  48. Image outImg;
  49.  
  50. // Allocate memory
  51. const int ROWS = IN_IMG.getRow();
  52. const int COLS = IN_IMG.getCol();
  53. const int CHANNELS = IN_IMG.getChannel();
  54. outImg.createImage(ROWS, COLS, IN_IMG.getType());
  55.  
  56. // Perform edge effect
  57. for (int k = 0; k < CHANNELS; ++k)
  58. for (int i = 0; i < ROWS; ++i)
  59. for (int j = 0; j < COLS; ++j)
  60. outImg(i,j,k) = onePixelSwirl(IN_IMG, i, j, k, COEFF, ROWS, COLS);
  61.  
  62. return outImg;
  63. }
  64.  
  65. float onePixelSwirl(const Image& IN_IMG, const int& ROW, const int& COL,
  66. const int& CHANNEL, const double& COEFF, const int& ROWS, const int& COLS)
  67. {
  68. // define shift of origin
  69. //const double X_SHIFT = ROWS/2.0;
  70. //const double Y_SHIFT = COLS/2.0;
  71. //const complex<double> NEW_SHIFTED(ROW - X_SHIFT, COL - Y_SHIFT);
  72.  
  73.  
  74. //const double r = abs(NEW_SHIFTED);
  75. //const complex<double> OLD_SHIFTED = polar(r, arg(NEW_SHIFTED) + r/COEFF);
  76. //const int OLD_ROW = OLD_SHIFTED.real() <= ROWS ? OLD_SHIFTED.real() : ROWS;
  77. //const int OLD_COL = OLD_SHIFTED.imag() <= COLS ? OLD_SHIFTED.imag() : COLS;
  78.  
  79. //return IN_IMG(OLD_ROW, OLD_COL, CHANNEL);
  80. return 0;
  81. }
  82.  
  83. /********************************************************************
  84. * Image.h - header file of the Image library which defines
  85. * a new class "Image" and the associated member functions
  86. *
  87. * Author: Hairong Qi, hqi@utk.edu, ECE, University of Tennessee
  88. *
  89. * Created: 02/05/02
  90. *
  91. * Note:
  92. * This is a simple C++ library for image processing.
  93. * The purpose is not high performance, but to show how
  94. * the algorithm works through programming.
  95. * This library can only read in PGM/PPM format images.
  96. *
  97. * Modification:
  98. * 07/31/09 - moving header files for colorProcessing, imageIO, and
  99. * matrixProcessing to this file
  100. * 01/22/06 - reorganize the Image library such that the Image class
  101. * only contains member functions related to the most
  102. * fundamental image operation
  103. * 11/12/05 - add wavelet transform function
  104. * 09/26/05 - add Fourier transform related functions
  105. * 09/07/05 - add overloading function for "/"
  106. * 09/07/05 - modify createImage() function
  107. * 09/07/05 - fix problems with copy constructor
  108. * 08/07/05 - regrouping functions
  109. ********************************************************************/
  110.  
  111. #ifndef IMAGE_H
  112. #define IMAGE_H
  113.  
  114. #include <iostream>
  115. #include <cmath>
  116.  
  117. using namespace std;
  118.  
  119. #define PGMRAW 1 // magic number is 'P5'
  120. #define PPMRAW 2 // magic number is 'P6'
  121. #define PGMASCII 3 // magic number is 'P2'
  122. #define PPMASCII 4 // magic number is 'P3'
  123. #define GRAY 10 // gray-level image
  124. #define BINARY 11 // binary image
  125.  
  126. #define NBIT 8
  127. #define L ( pow(2.0,NBIT)-1 ) // the largest intensity represented by NBIT
  128.  
  129. class Image {
  130. friend ostream & operator<<(ostream &, Image &);
  131. friend Image operator/(Image &, double); // image divided by a scalar
  132. friend Image operator*(Image &, double); // image multiplied by a scalar
  133. friend Image operator+(Image &, double); // image add a scalar
  134. friend Image operator-(Image &, double); // image subtract a scalar
  135.  
  136. public:
  137. // constructors and destructor
  138. Image(); // default constructor
  139. Image(int, // constructor with row
  140. int, // column
  141. int t=PGMRAW); // type (use PGMRAW, PPMRAW,
  142. // PGMASCII, PPMASCII)
  143. Image(const Image &); // copy constructor
  144. ~Image(); // destructor
  145.  
  146. // create an image
  147. void createImage(); // create an image, parameters all set
  148. void createImage(int, // create an image with row
  149. int c=1, // column (default 1, a column vector)
  150. int t=PGMRAW); // and type, default is PGMRAW
  151. void initImage(float init=0.0); // initiate the pixel value of an img
  152. // the default is 0.0
  153.  
  154. // get and set functions
  155. int getRow() const; // get row # / the height of the img
  156. int getCol() const; // get col # / the width of the image
  157. int getChannel() const; // get channel number of the image
  158. int getType() const; // get the image type
  159. float getMaximum() const; // get the maximum pixel value
  160. void getMaximum(float &, // return the maximum pixel value
  161. int &, int &); // and its indices
  162. float getMinimum() const; // get the mininum pixel value
  163. void getMinimum(float &, // return the minimum pixel value
  164. int &, int &); // and its indices
  165. Image getRed() const; // get the red channel
  166. Image getGreen() const; // get the green channel
  167. Image getBlue() const; // get the blue channel
  168. Image getImage(int) const; // get the kth channel image,
  169. // k starts at 0
  170.  
  171. void setRow(int); // set row number
  172. void setCol(int); // set column number
  173. void setChannel(int); // set the number of channel
  174. void setType(int t=PGMRAW); // set the image type
  175. void setRed(Image &); // set the red channel
  176. void setGreen(Image &); // set the green channel
  177. void setBlue(Image &); // set the blue channel
  178. void setImage(Image &, int); // set the kth channel image,
  179. // k starts at 0
  180.  
  181. // operator overloading functions
  182. float & operator()(int, // operator overloading (i,j,k)
  183. int c = 0, // when c=k=0, a column vector
  184. int k = 0) const;
  185. const Image operator=(const Image &); // = operator overloading
  186. Image operator+(const Image &) const; // overloading + operator
  187. Image operator-(const Image &) const; // overloading - operator
  188. Image operator*(const Image &) const; // overloading pixelwise *
  189. Image operator/(const Image &) const; // overloading pixelwise division
  190. Image operator->*(const Image &) const; // overloading ->* operator
  191. // (matrix multiplication)
  192.  
  193. bool IsEmpty() const { return (image==NULL); }
  194.  
  195. private:
  196. int row; // number of rows / height
  197. int col; // number of columns / width
  198. int channel; // nr of channels (1 for gray, 3 for color)
  199. int type; // image type (PGM, PPM, etc.)
  200. int maximum; // the maximum pixel value
  201. float *image; // image buffer
  202. };
  203.  
  204.  
  205. ////////////////////////////////////
  206. // image I/O
  207. Image readImage(char *); // read image
  208. void writeImage(Image &, // write an image
  209. char *,
  210. int flag=0); // flag for rescale, rescale when == 1
  211. Image rescale(Image &, // rescale an image
  212. float a=0.0, // lower bound
  213. float b=L); // upper bound
  214.  
  215.  
  216. ////////////////////////////////////
  217. // color processing routines
  218. Image RGB2HSI(Image &); // convert from RGB to HSI model
  219. Image HSI2RGB(Image &); // convert from HSI to RGB model
  220.  
  221.  
  222. ////////////////////////////////////
  223. // matrix manipulation
  224. Image transpose(Image &); // image transpose
  225. Image inverse(Image &); // image inverse
  226. Image pinv(Image &); // image pseudo-inverse
  227. Image subImage(Image &, // crop an image
  228. int, // starting row index
  229. int, // starting column index
  230. int, // ending row index
  231. int); // ending column index
  232.  
  233.  
  234. #endif
Add Comment
Please, Sign In to add comment