ImageT.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. * NICE - New Image C++ extension
  3. * - libimage - An ImageT library
  4. * See file License for license information.
  5. */
  6. #include <core/image/Convert.h>
  7. #ifndef _LIMUN_GRAYIMAGET_H
  8. #define _LIMUN_GRAYIMAGET_H
  9. #include <core/image/ippwrapper.h>
  10. #include <core/image/CoordT.h>
  11. #include <core/image/ColorT.h>
  12. #include <core/image/Drawable.h>
  13. #include <core/image/GrayColorImageCommonImplementation.h>
  14. #include <core/image/BlockImageAccessT.h>
  15. namespace NICE {
  16. template<class P> class GrayColorImageCommonImplementationT;
  17. class ImageFile;
  18. /**
  19. * @class ImageT
  20. * The standard template class for gray images (single channel).
  21. * Use typdef Image for a normal 8 bit gray image.
  22. *
  23. * This class offers the same high performance pointer arithmetic pixel access
  24. * interface as BlockImageAccessT with the additional property that
  25. * rows are consecutive memory blocks, i.e. columnStepsize() == bytedepth().
  26. *
  27. * @author Ferid Bajramovic
  28. * @example image_overview.cpp
  29. */
  30. template<class P>
  31. class ImageT: public BlockImageAccessT<P> {
  32. public:
  33. /**
  34. * @name Constructors, factory methods and destructor
  35. * \{
  36. */
  37. /**
  38. * Default constructor
  39. */
  40. ImageT();
  41. /**
  42. * Create an ImageT of size (\c width, \c height)
  43. * @param width width
  44. * @param height height
  45. * @param _memoryLayout see \c MemoryLayout
  46. */
  47. ImageT ( const int width, const int height, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  48. GrayColorImageCommonImplementation::ippAlignment );
  49. /**
  50. * Create a copy of \c orig.
  51. * @param orig Original ImageT
  52. * @param copyMode \c MemoryLayout of the new \c ImageT
  53. * See also \c MemoryLayout.
  54. */
  55. ImageT ( const ImageT<P>& orig, const GrayColorImageCommonImplementation::MemoryLayout copyMode =
  56. GrayColorImageCommonImplementation::originalAlignment );
  57. /**
  58. * Create a shallow copy of \c orig directly using orig's pixel memory.
  59. * Pixels are not copied, onwership of pixel memory is not taken.
  60. * @param orig Original ImageT
  61. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  62. */
  63. ImageT ( ImageT<P>& orig, const GrayColorImageCommonImplementation::ShallowCopyMode shallow );
  64. /**
  65. * Create an ImageT from raw ImageT data
  66. * @param raw Raw ImageT data
  67. * @param width Width of the ImageT
  68. * @param height Height of the ImageT
  69. * @param m_rowStepsize Number of bytes between the beginning of
  70. * two consecutive lines (usually width)
  71. * @param copyMode \c MemoryLayout of the new \c ImageT
  72. * See also \c MemoryLayout.
  73. * @example image_creation.cpp
  74. */
  75. ImageT ( const P* raw, const int width, const int height, const int m_rowStepsize,
  76. const GrayColorImageCommonImplementation::MemoryLayout copyMode =
  77. GrayColorImageCommonImplementation::originalAlignment );
  78. /**
  79. * Create a ImageT from raw data directly using the pixel memory raw.
  80. * Pixels are not copied, onwership of pixel memory is not taken.
  81. * @param raw Raw ImageT data
  82. * @param width Width of the ImageT
  83. * @param height Height of the ImageT
  84. * @param m_rowStepsize Number of bytes between the beginning of
  85. * two consecutive lines (usually width)
  86. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  87. */
  88. ImageT ( P* raw, const int width, const int height, const int m_rowStepsize,
  89. const GrayColorImageCommonImplementation::ShallowCopyMode shallow );
  90. /**
  91. * Create a ImageT from raw ImageT data
  92. * Assume stepwidth = width
  93. * @see ImageT(P*,int,int,int,bool)
  94. * @param raw Raw ImageT data
  95. * @param width Width of the ImageT
  96. * @param height Height of the ImageT
  97. * @param copyMode \c MemoryLayout of the new \c ImageT
  98. * See also \c MemoryLayout.
  99. */
  100. ImageT ( const P* raw, const int width, const int height,
  101. const GrayColorImageCommonImplementation::MemoryLayout copyMode =
  102. GrayColorImageCommonImplementation::originalAlignment );
  103. /**
  104. * Create an ImageT from raw data directly using the pixel memory raw.
  105. * Pixels are not copied, onwership of pixel memory is not taken.
  106. * Assume stepwidth = width
  107. * @see ImageT(P*,int,int,int,bool)
  108. * @param raw Raw ImageT data
  109. * @param width Width of the ImageT
  110. * @param height Height of the ImageT
  111. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  112. */
  113. ImageT ( P* raw, const int width, const int height, const GrayColorImageCommonImplementation::ShallowCopyMode shallow );
  114. /**
  115. * Create an ImageT from the file named pgmFilename.
  116. * @note If no file named \c Filename exists, an ImageException is thrown.
  117. * @param Filename Name of the input file
  118. * @param _memoryLayout see \c MemoryLayout
  119. */
  120. ImageT ( const std::string& Filename, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  121. GrayColorImageCommonImplementation::ippAlignment );
  122. /**
  123. * Create a const shallow copy of \c orig directly using orig's pixel memory.
  124. * Pixels are not copied, onwership of pixel memory is not taken.
  125. * @param orig Original ImageT
  126. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  127. */
  128. static inline const ImageT<P>* createConst ( const ImageT<P>& orig,
  129. const GrayColorImageCommonImplementation::ShallowCopyMode shallow ) {
  130. return new ImageT<P> ( orig, shallow );
  131. }
  132. /**
  133. * Create a const ImageT from raw data directly using the pixel memory
  134. * raw. Pixels are not copied, onwership of pixel memory is not taken.
  135. * @param raw Raw ImageT data
  136. * @param width Width of the ImageT
  137. * @param height Height of the ImageT
  138. * @param m_rowStepsize Number of bytes between the beginning of
  139. * two consecutive lines (usually width)
  140. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this "constuctor"
  141. */
  142. static inline const ImageT<P>* createConst ( const P* raw, const int width, const int height, const int m_rowStepsize,
  143. const GrayColorImageCommonImplementation::ShallowCopyMode shallow ) {
  144. return new ImageT<P> ( raw, width, height, m_rowStepsize, shallow );
  145. }
  146. /**
  147. * Create a const ImageT from raw data directly using the pixel memory
  148. * raw. Pixels are not copied, onwership of pixel memory is not taken.
  149. * Assume stepwidth = width
  150. * @see ImageT(P*,int,int,int,bool)
  151. * @param raw Raw ImageT data
  152. * @param width Width of the ImageT
  153. * @param height Height of the ImageT
  154. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this "constuctor"
  155. */
  156. static inline const ImageT<P>* createConst ( const P* raw, const int width, const int height,
  157. const GrayColorImageCommonImplementation::ShallowCopyMode shallow ) {
  158. return new ImageT<P> ( raw, width, height, width, shallow );
  159. }
  160. /**
  161. * Destructor.
  162. */
  163. virtual ~ImageT();
  164. /**
  165. * \}
  166. * @name Access pixels and pixel memory
  167. * \{
  168. */
  169. /**
  170. * Get a const pointer to the pixel data at point (x,y).
  171. * Supposed for high performance pixel access. Use with care.
  172. * @param x Position (x-coordinate)
  173. * @param y Position (y-coordinate)
  174. * @return pointer to the pixel at position (x,y)
  175. */
  176. inline P const* getPixelPointerXY ( const int x, const int y ) const {
  177. return pointerToPixel1 ( this->getPixelPointer(), x, y, this->rowStepsize() );
  178. }
  179. /**
  180. * Get a non-const pointer to the pixel data at point (x,y).
  181. * @param x Position (x-coordinate)
  182. * @param y Position (y-coordinate)
  183. */
  184. inline P* getPixelPointerXY ( const int x, const int y ) {
  185. return pointerToPixel1 ( this->getPixelPointer(), x, y, this->rowStepsize() );
  186. }
  187. /**
  188. * Get a const reference to the pixel data at point (x,y).
  189. * @param x Position (x-coordinate)
  190. * @param y Position (y-coordinate)
  191. * @example image_access_operator1.cpp
  192. */
  193. inline const P& operator() ( const int x, const int y ) const {
  194. return *pointerToPixel1 ( this->m_pixel, x, y, this->m_rowStepsize );
  195. // see getPixelQuick for changes
  196. // return *pointerToPixel1(this->getPixelPointer(), x, y, this->m_rowStepsize);
  197. }
  198. /**
  199. * Get a non-const reference to the pixel data at point (x,y).
  200. * @param x Position (x-coordinate)
  201. * @param y Position (y-coordinate)
  202. */
  203. inline P& operator() ( const int x, const int y ) {
  204. return *pointerToPixel1 ( this->m_pixel, x, y, this->m_rowStepsize );
  205. // see getPixelQuick for changes
  206. // return *pointerToPixel1(this->getPixelPointer(), x, y, this->m_rowStepsize);
  207. }
  208. /**
  209. * Get a pixel value WITHOUT boundary checking.
  210. * @param x Position (x-coordinate)
  211. * @param y Position (y-coordinate)
  212. * @return pixel at position (x,y)
  213. * @example image_access_function.cpp
  214. */
  215. inline P getPixelQuick ( const int x, const int y ) const {
  216. return * ( ( P* ) ( ( ( Ipp8u* ) this->m_pixel ) + y * this->m_rowStepsize + x * sizeof ( P ) ) );
  217. // version 3 was:
  218. // return *pointerToPixel1(this->m_pixel, x, y, this->m_rowStepsize);
  219. //
  220. // version 2 was:
  221. // return *pointerToPixel1(this->getPixelPointer(), x, y, this->m_rowStepsize);
  222. // getPixelPointer() requires some additional operations :(
  223. //
  224. // version 1 was:
  225. //return *getPixelPointerXY(x, y);
  226. // which used to many inline functions that were not optimized
  227. // by the compiler, tested with the program imageAccessTime (erik, Feb/2012)
  228. }
  229. /**
  230. * Get a pixel value WITH boundary checking.
  231. * @param x Position (x-coordinate)
  232. * @param y Position (y-coordinate)
  233. * @return pixel at position (x,y)
  234. * @throws ImageException if (x,y) is out of range
  235. */
  236. P getPixel ( const int x, const int y ) const;
  237. /**
  238. * Set a pixel value WITHOUT boundary checking.
  239. * @param x Position (x-coordinate)
  240. * @param y Position (y-coordinate)
  241. * @param value New pixel value
  242. */
  243. inline void setPixelQuick ( const int x, const int y, const P value ) {
  244. *getPixelPointerXY ( x, y ) = value;
  245. }
  246. /**
  247. * Set a pixel value WITH boundary checking.
  248. * @param x Position (x-coordinate)
  249. * @param y Position (y-coordinate)
  250. * @param value New pixel value
  251. * @throws ImageException if (x,y) is out of range
  252. */
  253. void setPixel ( const int x, const int y, const P value );
  254. /**
  255. * Set a pixel value WITH boundary checking.
  256. * Do nothing if (x,y) is out of range.
  257. * @param x Position (x-coordinate)
  258. * @param y Position (y-coordinate)
  259. * @param value New pixel value
  260. */
  261. void setPixelSave ( const int x, const int y, const P value );
  262. /**
  263. * Sets all pixel to the specified value
  264. * @param value pixel value
  265. */
  266. void set ( const P& value );
  267. /**
  268. * \}
  269. * @name Basic image operations
  270. * \{
  271. */
  272. /**
  273. * Assign constant to image values.
  274. */
  275. inline ImageT<P>& operator= ( const P c );
  276. /**
  277. * Get a const pointer to the pixel data at point (x,y).
  278. * Supposed for high performance pixel access. Use with care.
  279. * @param coord coordinates of the pixel
  280. * @return pointer to the pixel at position (x,y)
  281. * @example image_access_pointer.cpp
  282. */
  283. inline P const* getPixelPointerXY ( const Coord &coord ) const {
  284. return pointerToPixel1 ( this->getPixelPointer(), coord, this->m_rowStepsize );
  285. }
  286. /**
  287. * Get a non-const pointer to the pixel data at point (x,y).
  288. * @param coord coordinates of the pixel
  289. */
  290. inline P* getPixelPointerXY ( const Coord &coord ) {
  291. return pointerToPixel1 ( this->getPixelPointer(), coord, this->m_rowStepsize );
  292. }
  293. /**
  294. * Get a const reference to the pixel data at point (x,y).
  295. * @param coord coordinates of the pixel
  296. */
  297. inline const P& operator() ( const Coord &coord ) const {
  298. return *pointerToPixel1 ( this->getPixelPointer(), coord, this->m_rowStepsize );
  299. }
  300. /**
  301. * Get a non-const reference to the pixel data at point (x,y).
  302. * @param coord coordinates of the pixel
  303. */
  304. inline P& operator() ( const Coord &coord ) {
  305. return *pointerToPixel1 ( this->getPixelPointer(), coord, this->m_rowStepsize );
  306. }
  307. /**
  308. * Get a pixel value WITHOUT boundary checking.
  309. * @param coord coordinates of the pixel
  310. * @return pixel at position (x,y)
  311. */
  312. inline P getPixelQuick ( const Coord &coord ) const {
  313. return *getPixelPointerXY ( coord );
  314. }
  315. /**
  316. * Get a pixel value WITH boundary checking.
  317. * @param coord coordinates
  318. * @return pixel at position (x,y)
  319. * @throws ImageException if (x,y) is out of range
  320. */
  321. P getPixel ( const Coord &coord ) const;
  322. /**
  323. * Get a pixel value at arbitrary position using bilinear interpolation.
  324. * @param x coordinate
  325. * @param y coordinate
  326. * @return pixel at position (x,y)
  327. */
  328. float getPixelBilinear ( const float x, const float y ) const;
  329. /**
  330. * Set a pixel value WITHOUT boundary checking.
  331. * @param coord coordinates
  332. * @param value New pixel value
  333. */
  334. inline void setPixelQuick ( const Coord &coord, const P value ) {
  335. *getPixelPointerXY ( coord ) = value;
  336. }
  337. /**
  338. * Set a pixel value WITH boundary checking.
  339. * @param coord coordinates
  340. * @param value New pixel value
  341. * @throws ImageException if (x,y) is out of range
  342. */
  343. void setPixel ( const Coord &coord, const P value );
  344. /**
  345. * Set a pixel value WITH boundary checking.
  346. * Do nothing if (x,y) is out of range.
  347. * @param coord coordinates
  348. * @param value New pixel value
  349. */
  350. void setPixelSave ( const Coord &coord, const P value );
  351. /**
  352. * \}
  353. * @name Drawing Functions
  354. * \{
  355. */
  356. /**
  357. * Draw drawable object using the default gray value of the object.
  358. * @param drawable object to draw
  359. * @example image_draw.cpp
  360. */
  361. void draw ( Drawable<P> &drawable );
  362. /**
  363. * Draw drawable objects using the default gray value of the objects.
  364. * @param begin Iterator to first object to draw
  365. * @param end Iterator to last object to draw
  366. */
  367. template<typename DrawableIterator>
  368. void drawIter ( const DrawableIterator begin, const DrawableIterator end );
  369. /**
  370. * Draw drawable objects using the default gray value of the objects.
  371. * @param begin iterator to the first object to draw
  372. * @param number number of objects to draw
  373. */
  374. template<typename DrawableIterator>
  375. void drawIter ( const DrawableIterator begin, size_t number );
  376. /**
  377. * Draw drawable object
  378. * @param drawable object to draw
  379. * @param gray the gray value used for drawing
  380. */
  381. void draw ( Drawable<P> &drawable, const P& gray );
  382. /**
  383. * Draw drawable object
  384. * @param begin Iterator to first object to draw
  385. * @param end Iterator to last object to draw
  386. * @param gray the gray value used for drawing
  387. */
  388. template<typename DrawableIterator>
  389. void drawIter ( const DrawableIterator begin, const DrawableIterator end, const P& gray );
  390. /**
  391. * Draw drawable objects
  392. * @param begin iterator to the first object to draw
  393. * @param number number of objects to draw
  394. * @param gray the gray value used for drawing
  395. */
  396. template<typename DrawableIterator>
  397. void drawIter ( const DrawableIterator begin, size_t number, const P& gray );
  398. /**
  399. * \}
  400. * @name Compare Functions
  401. * \{
  402. */
  403. /**
  404. * @brief Compare \c g with \c this.
  405. * @pre Size of \c g and \c this must be equal
  406. * @param g image to compare with
  407. * @return true if \c g and \c this are equal
  408. */
  409. inline bool operator== ( const ImageT<P> &g ) const;
  410. /**
  411. * @brief Compare \c g with \c this.
  412. * @pre Size of \c g and \c this must be equal
  413. * @param g image to compare with
  414. * @return true if \c g and \c this are not equal
  415. */
  416. inline bool operator!= ( const ImageT<P> &g ) const;
  417. /**
  418. * @brief Compare \c this with color.
  419. * @param color color to compare with
  420. * @return true if each pixel of \c this has the value color
  421. */
  422. inline bool operator== ( const ColorT<P> &color ) const;
  423. /**
  424. * @brief Compare \c this with color.
  425. * @param color color to compare with
  426. * @return true if each pixel of \c this has not the value color
  427. */
  428. inline bool operator!= ( const ColorT<P> &color ) const;
  429. /**
  430. * @brief Compare \c this with color.
  431. * @param color color to compare with
  432. * @return true if each pixel of \c this has the value color
  433. */
  434. inline bool operator== ( P color ) const;
  435. /**
  436. * @brief Compare \c this with color.
  437. * @param color color to compare with
  438. * @return true if each pixel of \c this has not the value color
  439. */
  440. inline bool operator!= ( P color ) const;
  441. /**
  442. * \}
  443. * @name Image Tools
  444. * \{
  445. */
  446. /**
  447. * Mirror on horizontal, vertical or both axis.
  448. * @param axis mirror type
  449. * - ippAxsHorizontal = horizontal
  450. * - ippAxsVertical = vertical
  451. * - ippAxsBoth = both
  452. */
  453. void mirror ( IppiAxis axis );
  454. /**
  455. * transpose image (must be quadratic)
  456. */
  457. void transpose();
  458. /**
  459. * invert image (works only with an 8 bit image)
  460. */
  461. void invert();
  462. /**
  463. * Replace each value by the absolute value
  464. */
  465. void abs();
  466. /**
  467. * Get minimum value of the image.
  468. * @return minimun value of the image
  469. */
  470. P min() const;
  471. /**
  472. * Get maximum value of the image.
  473. * @return maximum value of the image
  474. */
  475. P max() const;
  476. /**
  477. * Get minimum and maximum value of the image.
  478. * @param min minimun value of the image
  479. * @param max maximum value of the image
  480. */
  481. void minmax ( P &min, P &max ) const;
  482. /**
  483. * Get x and y coordinate of the minimum value of the image.
  484. * @return x and y coordinate of the minimun value of the image
  485. */
  486. Coord minIndex() const;
  487. /**
  488. * Get the x and y coordinates of the maximum value of the image.
  489. * @return x and y coordinate of the maximum value of the image
  490. */
  491. Coord maxIndex() const;
  492. /**
  493. * Get the x and y coordinates of the minimum and maximum value of the image.
  494. * @param min x and y coordinate of the minimun value of the image
  495. * @param max x and y coordinate of the maximum value of the image
  496. */
  497. void minmaxIndex ( Coord& min, Coord& max ) const;
  498. /**
  499. * Get the sum of all pixel values of the image.
  500. * @return sum of all pixel values
  501. */
  502. double sum() const;
  503. /**
  504. * Get the mean of all pixel values of the image.
  505. * @return mean of all pixel values
  506. */
  507. double mean() const;
  508. /**
  509. * Get the mean and standard derivation of all pixel values of the image.
  510. * @param mean mean value of all pixel values
  511. * @param stddev standard derivation of all pixel values
  512. */
  513. void meanStdDev ( double &mean, double &stddev ) const;
  514. /**
  515. * \}
  516. * @name File operations
  517. * \{
  518. */
  519. /**
  520. * Write a colored image (white positiv values, red negativ values).
  521. * @note usefull to display float or signed images
  522. * @param file should contain a colorimage ImageFile
  523. */
  524. void writeColored ( const ImageFile &file ) const;
  525. /**
  526. * Write this ImageT as a PGM file.
  527. * @note If an file named \c pgmFilename exists, it will be overwritten.
  528. * @param pgmFilename Name of the file to be written
  529. */
  530. void writePGM ( const char* pgmFilename ) const;
  531. /**
  532. * Write this ImageT as a PGM file.
  533. * @note If an file named \c pgmFilename exists, it will be overwritten.
  534. * @param pgmFilename Name of the file to be written
  535. */
  536. void writePGM ( const std::string& pgmFilename ) const;
  537. /**
  538. * Write this ImageT as a rawfile.
  539. * @note If an file named \c rawFilename exists, it will be overwritten.
  540. * @param rawFilename Name of the file to be written
  541. */
  542. void writeRaw ( const char* rawFilename ) const;
  543. /**
  544. * Write this ImageT as a rawfile.
  545. * @note If an file named \c rawFilename exists, it will be overwritten.
  546. * @param rawFilename Name of the file to be written
  547. */
  548. void writeRaw ( const std::string& rawFilename ) const;
  549. /**
  550. * Read this ImageT from a PGM file.
  551. * @note If no file named \c pgmFilename exists, an ImageException is thrown.
  552. * @param pgmFilename Name of the input file
  553. * @param _memoryLayout see \c MemoryLayout
  554. */
  555. void readPGM ( const char* pgmFilename, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  556. GrayColorImageCommonImplementation::ippAlignment );
  557. /**
  558. * Read this ImageT from a PPM file.
  559. * @note If no file named \c pgmFilename exists, an ImageException is thrown.
  560. * @param pgmFilename Name of the input file
  561. * @param _memoryLayout see \c MemoryLayout
  562. */
  563. void readPGM ( const std::string& pgmFilename, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  564. GrayColorImageCommonImplementation::ippAlignment );
  565. /**
  566. * Read this ImageT from a raw file.
  567. * @note If no file named \c rawFilename exists, an ImageException is thrown.
  568. * @param rawFilename Name of the input file
  569. * @param _memoryLayout see \c MemoryLayout
  570. */
  571. void readRaw ( const char* rawFilename, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  572. GrayColorImageCommonImplementation::ippAlignment );
  573. /**
  574. * Read this ImageT from a raw file.
  575. * @note If no file named \c rawFilename exists, an ImageException is thrown.
  576. * @param rawFilename Name of the input file
  577. * @param _memoryLayout see \c MemoryLayout
  578. */
  579. void readRaw ( const std::string& rawFilename, const GrayColorImageCommonImplementation::MemoryLayout _memoryLayout =
  580. GrayColorImageCommonImplementation::ippAlignment );
  581. /**
  582. * \}
  583. * @name Copying
  584. * \{
  585. */
  586. /**
  587. * Copy \c orig to this (external pointers to image become invalid)
  588. * @param orig Original ColorImageT
  589. * @note
  590. * This will (in many cases) invalidate all pointers to the pixel memory
  591. * of this image as well as all subimages of this image!
  592. * MemoryLayout is set to GrayColorImageCommonImplementation::originalAlignment
  593. * if memory has to be reallocated.
  594. */
  595. ImageT<P>& operator= ( const ImageT<P>& orig );
  596. /**
  597. * Copy \c image to this (external pointers to image become invalid)
  598. * @param image Original ColorImageT
  599. * @param copyMode New \c MemoryLayout of this \c ColorImageT
  600. * if memory has to be reallocated.
  601. * See also \c MemoryLayout.
  602. * @note
  603. * This will (in many cases) invalidate all pointers to the pixel memory
  604. * of this image as well as all subimages of this image!
  605. */
  606. inline void copyFrom ( const GrayColorImageCommonImplementationT<P>& image, const GrayColorImageCommonImplementation::MemoryLayout copyMode =
  607. GrayColorImageCommonImplementation::ippAlignment ) {
  608. fromRaw ( image.getPixelPointer(), image.width(), image.height(), image.rowStepsize(), copyMode );
  609. }
  610. /**
  611. * \}
  612. * @name Subimages
  613. * \{
  614. */
  615. /**
  616. * Create a subimage using the same pixel memory.
  617. * @param area The area of the new subimage (must be within the image!)
  618. * @return A new ImageT<P> using the same pixel memory,
  619. * but representing a only a part of the image.
  620. */
  621. inline ImageT<P>* createSubImage ( const Rect& area ) {
  622. return new ImageT<P> ( getPixelPointerXY ( area.left, area.top ), area.width, area.height, this->getStepsize(),
  623. GrayColorImageCommonImplementation::shallowCopy );
  624. }
  625. /**
  626. * Create a const subimage using the same pixel memory.
  627. * @param area The area of the new subimage (must be within the image!)
  628. * @return A new ImageT<P> using the same pixel memory,
  629. * but representing a only a part of the image.
  630. */
  631. inline const ImageT<P>* createSubImage ( const Rect& area ) const {
  632. return new ImageT<P> ( getPixelPointerXY ( area.left, area.top ), area.width, area.height, this->getStepsize(),
  633. GrayColorImageCommonImplementation::shallowCopy );
  634. }
  635. /**
  636. * A subimage using the same pixel memory.
  637. * @param area The area of the new subimage (must be within the image!)
  638. * @return A ImageT<P> using the same pixel memory,
  639. * but representing a only a part of the image.
  640. */
  641. inline ImageT<P> subImage ( const Rect& area ) {
  642. return ImageT<P> ( getPixelPointerXY ( area.left, area.top ), area.width, area.height, this->getStepsize(),
  643. GrayColorImageCommonImplementation::shallowCopy );
  644. }
  645. /**
  646. * A const subimage using the same pixel memory.
  647. * @param area The area of the new subimage (must be within the image!)
  648. * @return A ImageT<P> using the same pixel memory,
  649. * but representing a only a part of the image.
  650. */
  651. inline const ImageT<P> subImage ( const Rect& area ) const {
  652. return ImageT<P> ( getPixelPointerXY ( area.left, area.top ), area.width, area.height, this->getStepsize(),
  653. GrayColorImageCommonImplementation::shallowCopy );
  654. }
  655. /**
  656. * Copies pixels from inside a rectangle to dst top left.
  657. * @param rect rectangle where to copy pixel from
  658. * @param dst optional buffer to be used as target.
  659. * Create a new Image if dst == NULL.
  660. * If dst != NULL then size must be equal to rect's size!
  661. * @return Image
  662. * @example image_copyrectsubimage.cpp
  663. */
  664. ImageT<P>* copyRect ( const Rect& rect, ImageT<P>* dst = NULL );
  665. /**
  666. * \}
  667. */
  668. private:
  669. /**
  670. * Create a const shallow copy of \c orig directly using orig's pixel memory.
  671. * Pixels are not copied, onwership of pixel memory is not taken.
  672. * @param orig Original ImageT
  673. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  674. * @note This constructor is private, use createConst() instead.
  675. */
  676. ImageT ( const ImageT<P>& orig, const GrayColorImageCommonImplementation::ShallowCopyMode shallow );
  677. /**
  678. * Create a const ImageT from raw data directly using the pixel memory
  679. * raw. Pixels are not copied, onwership of pixel memory is not taken.
  680. * @param raw Raw ImageT data
  681. * @param width Width of the ImageT
  682. * @param height Height of the ImageT
  683. * @param m_rowStepsize Number of bytes between the beginning of
  684. * two consecutive lines (usually width)
  685. * @param shallow Set to GrayColorImageCommonImplementation::shallowCopy to use this constuctor
  686. * @note This constructor is private, use createConst() instead.
  687. */
  688. ImageT ( const P* raw, const int width, const int height, const int m_rowStepsize,
  689. const GrayColorImageCommonImplementation::ShallowCopyMode shallow );
  690. //! helper function for \c allocPixel(), separated for template specialization
  691. virtual void doAllocPixelNoAlignment();
  692. //! helper function for \c allocPixel(), separated for template specialization
  693. virtual void doAllocPixelIPP();
  694. /**
  695. * Initialize from raw pixel data.
  696. * @param raw Raw ImageT data
  697. * @param width Width of the ImageT
  698. * @param height Height of the ImageT
  699. * @param m_rowStepsize Stepsize
  700. * @param copyMode \c MemoryLayout of the new \c ImageT
  701. * See also \c MemoryLayout.
  702. */
  703. void fromRaw ( const P* raw, const int width, const int height, const int m_rowStepsize,
  704. const GrayColorImageCommonImplementation::MemoryLayout copyMode =
  705. GrayColorImageCommonImplementation::originalAlignment );
  706. //! helper function for \c allocPixel(), separated for template specialization
  707. void doFromRaw ( const P* raw, const int m_rowStepsize );
  708. };
  709. typedef ImageT<Ipp8u> Image;
  710. typedef ImageT<Ipp16s> GrayImage16s;
  711. typedef ImageT<Ipp32f> FloatImage;
  712. } // namespace
  713. #include "core/image/GrayColorImageCommonImplementationT.h"
  714. //#ifdef __GNUC__
  715. #include "core/image/ImageT.tcc"
  716. //#endif
  717. #endif