DeprecatedConverter.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image library
  4. * See file License for license information.
  5. */
  6. /**
  7. * @file DeprecatedConverter.h
  8. * DEPRECATED
  9. * - Do NOT use this class in new code
  10. * - use the new functions in Convert.h, FilterT.h, etc.
  11. * @deprecated Use new functions in Convert.h, FilterT.h, ...
  12. */
  13. #ifndef LIMUN_CONVERTER_H
  14. #define LIMUN_CONVERTER_H
  15. #include "core/basics/deprecated.h"
  16. #include "core/image/ippwrapper.h"
  17. #include "core/image/GrayColorImageCommonImplementation.h"
  18. #include "core/image/RectT.h"
  19. #include "core/vector/VectorT.h"
  20. #include "core/image/Convert.h"
  21. namespace NICE {
  22. class DeprecatedConverter;
  23. template<class P> class GrayColorImageCommonImplementationT;
  24. template<class P> class ColorImageT;
  25. template<class P> class ImageT;
  26. typedef ColorImageT<Ipp8u> ColorImage;
  27. typedef ColorImageT<Ipp8u> ThreeChannelImage;
  28. typedef ColorImageT<Ipp8u> HSVColorImage;
  29. typedef ImageT<Ipp8u> Image;
  30. typedef ImageT<Ipp16s> GrayImage16s;
  31. typedef ImageT<Ipp32f> FloatImage;
  32. /**
  33. * A DEPRECATED collection of image conversion functions, which has been
  34. * replaced by new functions in Convert.h, Filter.h, etc. Do NOT use this
  35. * class in new code!
  36. *
  37. * @deprecated Use new functions in Convert.h, Filter.h, ...
  38. *
  39. * @note Most functions are currently not supported without IPP
  40. * and will throw an exception if compiled without IPP.
  41. * Use new functions instead of this class if no IPP is available.
  42. *
  43. * @author Ferid Bajramovic (ferid [dot] bajramovic [at] informatik [dot] uni-jena [dot] de)
  44. */
  45. class LIMUN_DEPRECATED DeprecatedConverter {
  46. private:
  47. #ifndef NICE_USELIB_IPP
  48. // lookup tables for rgb -> gray color transform
  49. static bool pLut_initialized;
  50. static int pLutRg[256];
  51. static int pLutGg[256];
  52. static int pLutBg[256];
  53. #endif
  54. public:
  55. /**
  56. * Convert the HSV-ColorImage hsv into a RGB-ColorImage.
  57. * @param hsv Original HSV image
  58. * @param rgb optional buffer to be used as target.
  59. * Create a new ColorImage if hsv == NULL.
  60. * @return ColorImage
  61. * @throw An ImageException will be thrown if
  62. * rgb != NULL and the size of hsv and rgb are not equal.
  63. */
  64. static ColorImage* hsvToRGB(const HSVColorImage& hsv,
  65. ColorImage* rgb = NULL);
  66. /**
  67. * Convert the RGB-ColorImage rgb into a HSVColorImage.
  68. * @param rgb Original RGB image
  69. * @param hsv optional buffer to be used as target.
  70. * Create a new HSVColorImage if hsv == NULL.
  71. * @return HSVColorImage
  72. * @throw An ImageException will be thrown if
  73. * hsv != NULL and the size of rgb and hsv are not equal.
  74. */
  75. static HSVColorImage* rgbToHSV(const ColorImage& rgb,
  76. HSVColorImage* hsv = NULL);
  77. /**
  78. * Convert RGB to HSV inside a region of interest
  79. * (i.e. only a part of the image). The resulting image is
  80. * of the same (!) size as rgb.
  81. * @see rgbToHSV()
  82. * @param rgb input image
  83. * @param hsv optional buffer to be used as target.
  84. * Create a new HSVColorImage if hsv == NULL.
  85. * If hsv != NULL then size must be equal to rgb's size!
  86. * @param rect Region of interest
  87. */
  88. static HSVColorImage* rgbToHSVRegion(const ColorImage& rgb,
  89. HSVColorImage* hsv,
  90. const Rect rect);
  91. /**
  92. * Convert the RGB-ColorImage rgb into a Image.
  93. * @param rgb Original RGB image
  94. * @param gray optional buffer to be used as target.
  95. * Create a new Image if gray == NULL.
  96. * @return Image
  97. * @throw An ImageException will be thrown if
  98. * gray != NULL and the size of rgb and gray are not equal.
  99. */
  100. template<class P>
  101. static ImageT<P>* rgbToGray(const ColorImageT<P>& rgb,
  102. ImageT<P>* gray = NULL);
  103. /**
  104. * Convert the Image gray into a RGB-ColorImage.
  105. * @param gray Original gray image
  106. * @param rgb optional buffer to be used as target.
  107. * Create a new ColorImage if rgb == NULL.
  108. * @return ColorImage
  109. * @throw An ImageException will be thrown if
  110. * rgb != NULL and the size of rgb and gray are not equal.
  111. */
  112. template<class P>
  113. static ColorImageT<P>* grayToRGB(const ImageT<P>& gray,
  114. ColorImageT<P>* rgb = NULL);
  115. /**
  116. * Convert the graylevel image to a graylevel image with a different bitdepth.
  117. * @param image Original graylevel image
  118. * @param buffer optional buffer to be used as target.
  119. * Create a new Image if buffer == NULL.
  120. * @return graylevel image
  121. * @throw An ImageException will be thrown if
  122. * buffer != NULL and the size of buffer and image are not equal.
  123. */
  124. template<class P1, class P2>
  125. static ImageT<P2>* convertBitDepth(const ImageT<P1>& image,
  126. ImageT<P2>* buffer=NULL);
  127. /**
  128. * Convert the color image to a color image with a different bitdepth.
  129. * @param image Original color image
  130. * @param buffer optional buffer to be used as target.
  131. * Create a new ColorImage if buffer == NULL.
  132. * @return color image pointer
  133. * @throw An ImageException will be thrown if
  134. * buffer != NULL and the size of buffer and image are not equal.
  135. */
  136. template<class P1, class P2>
  137. static ColorImageT<P2>* convertBitDepth(const ColorImageT<P1>& image,
  138. ColorImageT<P2>* buffer=NULL);
  139. /**
  140. * Convert the graylevel image gray into a FloatImage.
  141. * @param gray Original graylevel image
  142. * @param fimage optional buffer to be used as target.
  143. * Create a new FloatImage if fimage == NULL.
  144. * @return FloatImage
  145. * @throw An ImageException will be thrown if
  146. * fimage != NULL and the size of fimage and gray are not equal.
  147. */
  148. template<class P>
  149. static FloatImage* grayToFloat(const ImageT<P>& gray,
  150. FloatImage* fimage = NULL);
  151. /**
  152. * Convert the FloatImage into a Image just rounded (not scaled)
  153. * @param fimage Original float image
  154. * @param gray optional buffer to be used as target.
  155. * Create a new Image if gray == NULL.
  156. * @return Image*
  157. * @throw An ImageException will be thrown if
  158. * gray != NULL and the size of fimage and gray are not equal.
  159. */
  160. template<class P>
  161. static ImageT<P>* floatToGray(const FloatImage& fimage,
  162. ImageT<P>* gray = NULL);
  163. /**
  164. * Convert the FloatImage into a Image by scaling with p' = 255/(max-min)*(p-min)
  165. * @param fimage Original float image
  166. * @param gray optional buffer to be used as target.
  167. * Create a new Image if gray == NULL.
  168. * @return Image*
  169. * @throw An ImageException will be thrown if
  170. * gray != NULL and the size of fimage and gray are not equal.
  171. */
  172. template<class P>
  173. static ImageT<P>* floatToGrayScaled(const FloatImage& fimage,
  174. ImageT<P>* gray = NULL);
  175. /**
  176. * Convert the FloatImage into a Image by scaling with p' = 255/(fmax-fmin)*(p-fmin)
  177. * @param fimage Original float image
  178. * @param fmin minimum float value
  179. * @param fmax maximum float value
  180. * @param gray optional buffer to be used as target.
  181. * Create a new Image if gray == NULL.
  182. * @return Image*
  183. * @throw An ImageException will be thrown if
  184. * gray != NULL and the size of fimage and gray are not equal.
  185. */
  186. template<class P>
  187. static ImageT<P>* floatToGrayScaled(const FloatImage& fimage, Ipp32f fmin, Ipp32f fmax,
  188. ImageT<P>* gray = NULL);
  189. /**
  190. * Convert the 16bit graylevel image gray into a FloatImage.
  191. * @param gray Original 16 bit graylevel image
  192. * @param fimage optional buffer to be used as target.
  193. * Create a new FloatImage if fimage == NULL.
  194. * @return FloatImage
  195. * @throw An ImageException will be thrown if
  196. * fimage != NULL and the size of rgb and gray are not equal.
  197. */
  198. static FloatImage* gray16sToFloat(const GrayImage16s& gray,
  199. FloatImage* fimage = NULL);
  200. /**
  201. * Convert the RGB-ColorImage rgb into a FloatImage containing all rgb values,
  202. * so that the resulting image is 3 times wider.
  203. * @param rgb Original RGB image
  204. * @param fimage optional buffer to be used as target.
  205. * Create a new FloatImage if fimage == NULL.
  206. * @return FloatImage
  207. * @throw An ImageException will be thrown if
  208. * fimage != NULL and the size of rgb and gray are not equal.
  209. */
  210. static FloatImage* rgbToFloat(const ColorImage& rgb,
  211. FloatImage* fimage = NULL);
  212. /**
  213. * Set Image dst to grayvalue value.
  214. * @param dst destination gray image
  215. * @param value destination grayvalue
  216. */
  217. static void set(const unsigned char& value, Image* dst);
  218. /**
  219. * Mirror Image on horizontal, vertical or both axis.
  220. * @param src source gray image
  221. * @param dst destination gray image
  222. * @param axis mirror type (horizontal:ippAxsHorizontal, vertical:ippAxsVertical, both:ippAxsBoth)
  223. * @return Image
  224. */
  225. template<class P>
  226. static ImageT<P>* mirror(const ImageT<P>& src, IppiAxis axis, ImageT<P>* dst = NULL);
  227. /**
  228. * Mirror Image on horizontal, vertical or both axis.
  229. * @param src source gray image
  230. * @param dst destination gray image
  231. * @param axis mirror type (horizontal:ippAxsHorizontal, vertical:ippAxsVertical, both:ippAxsBoth)
  232. * @return Image
  233. */
  234. template<class P>
  235. static ColorImageT<P>* mirror(const ColorImageT<P>& src, IppiAxis axis, ColorImageT<P>* dst = NULL);
  236. /**
  237. * Remap Image src into the Image dst using lookup tables.
  238. * @param src source gray image
  239. * @param dst destination gray image
  240. * @param px 2D float image containing new x coordinate
  241. * @param py 2D float image containing new y coordinate
  242. * @param interpolation interpolation type (IPPI_INTER_NN|IPPI_INTER_LINEAR|IPPI_INTER_CUBIC) nearest neighbor interpolation, linear interpolation or cubic interpolation
  243. * @return Image
  244. */
  245. static Image* remap(const Image& src, const FloatImage &px, const FloatImage &py, Image* dst = NULL, int interpolation=IPPI_INTER_LINEAR);
  246. /**
  247. * Remap ColorImage src into the ColorImage dst using lookup tables.
  248. * @param src source RGB image
  249. * @param dst destination RGB image
  250. * @param px 2D float image containing new x coordinate
  251. * @param py 2D float image containing new y coordinate
  252. * @param interpolation interpolation type (IPPI_INTER_NN|IPPI_INTER_LINEAR|IPPI_INTER_CUBIC) nearest neighbor interpolation, linear interpolation or cubic interpolation
  253. * @return ColorImage
  254. */
  255. static ColorImage* remap(const ColorImage& src, const FloatImage &px, const FloatImage &py, ColorImage* dst = NULL, int interpolation=IPPI_INTER_LINEAR);
  256. /**
  257. * Resizes ImageT src into the ImageT dst using scale factors xFactor and yFactor.
  258. * @param src source ImageT
  259. * @param dst destination ImageT
  260. * @param xFactor factor for scaling the x-axis if 0 it is caculated by src vs. dst
  261. * @param yFactor factor for scaling the y-axis if 0 it is caculated by src vs. dst
  262. * @param interpolation interpolation type (IPPI_INTER_NN|IPPI_INTER_LINEAR|IPPI_INTER_CUBIC) nearest neighbor interpolation, linear interpolation or cubic interpolation
  263. * @return ImageT<P>
  264. */
  265. template<class P>
  266. static ImageT<P>* resize(const ImageT<P>& src, ImageT<P>* dst, double xFactor=0.0, double yFactor=0.0, int interpolation=IPPI_INTER_LINEAR);
  267. /**
  268. * Resizes ColorImageT src into the ColorImageT dst using scale factors xFactor and yFactor.
  269. * @param src source ColorImageT
  270. * @param dst destination ColorImageT
  271. * @param xFactor factor for scaling the x-axis if 0 it is caculated by src width vs. dst width
  272. * @param yFactor factor for scaling the y-axis if 0 it is caculated by src height vs. dst height
  273. * @param interpolation interpolation type (IPPI_INTER_NN|IPPI_INTER_LINEAR|IPPI_INTER_CUBIC) nearest neighbor interpolation, linear interpolation or cubic interpolation
  274. * @return ColorImageT
  275. */
  276. template<class P>
  277. static ColorImageT<P>* resize(const ColorImageT<P>& src, ColorImageT<P>* dst, double xFactor=0.0, double yFactor=0.0, int interpolation=IPPI_INTER_LINEAR);
  278. /**
  279. * Blurs Image src into the Image dst.
  280. * @param src source gray image
  281. * @param dst destination gray image
  282. * @param size length and width of the square used for mean filter
  283. * @return Image
  284. */
  285. static Image* blur(const Image& src, const int& size, Image* dst);
  286. /**
  287. * Filters Image src into the Image dst using a median filter.
  288. * @param src source gray image
  289. * @param dst destination gray image
  290. * @param size length and width of the square used for median filter
  291. * @return Image
  292. */
  293. static Image* median(const Image& src, const int& size, Image* dst);
  294. /**
  295. * Generate a binarized image from Image img
  296. * @param img gray image
  297. * @param threshold threshold
  298. */
  299. static void thresholdIP(Image& img, int threshold);
  300. /**
  301. * Generate a threshold image from Image img
  302. * @param img gray image
  303. * @param threshold threshold
  304. * @param value set pixel less than threshold to this value
  305. */
  306. static void lowerThresholdIP(Image& img, int threshold, int value=0);
  307. /**
  308. * Generate a threshold image from Image img
  309. * @param img gray image
  310. * @param threshold threshold
  311. * @param value set pixel greater than threshold to this value
  312. */
  313. static void upperThresholdIP(Image& img, int threshold, int value=255);
  314. /**
  315. * Filters Image src into the Image dst using a 3x3 erosion.
  316. * @param src source gray image
  317. * @param dst destination gray image
  318. * @return Image
  319. */
  320. static Image* erode(const Image& src, Image* dst=NULL);
  321. /**
  322. * Filters Image img using a 3x3 erosion (in place).
  323. * @param img gray image
  324. */
  325. static void erodeIP(Image& img);
  326. /**
  327. * Filters Image src into the Image dst using a 3x3 dilation.
  328. * @param src source gray image
  329. * @param dst destination gray image
  330. * @return Image
  331. */
  332. static Image* dilate(const Image& src, Image* dst=NULL);
  333. /**
  334. * Filters Image img using a 3x3 dilation (in place).
  335. * @param img gray image
  336. */
  337. static void dilateIP(Image& img);
  338. /**
  339. * Calculate a histogram.
  340. * @param src source image
  341. * @param min lower boundary (included)
  342. * @param max upper boundary (not included)
  343. * @param nlevels number of histogram bins
  344. * @return gray value histogram
  345. */
  346. template<class P>
  347. static VectorT<int>* histogram(const ImageT<P>& src, int min=0, int max=256, int nlevels=256);
  348. /**
  349. * Calculate a histogram.
  350. * @param src source image
  351. * @param histo outputvector for the histogram (number of element is the number of histogram bins)
  352. * @param min lower boundary (included)
  353. * @param max upper boundary (not included)
  354. * @return gray value histogram
  355. */
  356. template<class P>
  357. static VectorT<int>* histogram(const ImageT<P>& src, VectorT<int> *histo, int min=0, int max=256);
  358. /**
  359. * Calculate a histogram.
  360. * @param src source image
  361. * @param min lower boundary (included)
  362. * @param max upper boundary (not included)
  363. * @param nlevels number of histogram bins
  364. * @return histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  365. */
  366. template<class P>
  367. static VectorT<int>* histogram(const ColorImageT<P>& src, int min=0, int max=256, int nlevels=256);
  368. /**
  369. * Calculate a histogram.
  370. * @param src source image
  371. * @param histo outputvector for the histogram (number of element / 3 is the number of histogram bins per color)
  372. * @param min lower boundary (included)
  373. * @param max upper boundary (not included)
  374. * @return histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  375. */
  376. template<class P>
  377. static VectorT<int>* histogram(const ColorImageT<P>& src, VectorT<int> *histo, int min=0, int max=256);
  378. /**
  379. * Calculate a normalized histogram.
  380. * @param src source image
  381. * @param min lower boundary (included)
  382. * @param max upper boundary (not included)
  383. * @param nlevels number of histogram bins
  384. * @return gray value normalized histogram
  385. */
  386. template<class P>
  387. static VectorT<float>* histogramNormalized(const ImageT<P>& src, int min=0, int max=256, int nlevels=256);
  388. /**
  389. * Calculate a normalized histogram.
  390. * @param src source image
  391. * @param histo outputvector for the histogram (number of element is the number of histogram bins)
  392. * @param min lower boundary (included)
  393. * @param max upper boundary (not included)
  394. * @return gray value normalized histogram
  395. */
  396. template<class P>
  397. static VectorT<float>* histogramNormalized(const ImageT<P>& src, VectorT<float> *histo, int min=0, int max=256);
  398. /**
  399. * Calculate a normalized histogram.
  400. * @param src source image
  401. * @param min lower boundary (included)
  402. * @param max upper boundary (not included)
  403. * @param nlevels number of histogram bins
  404. * @return normalized histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  405. */
  406. template<class P>
  407. static VectorT<float>* histogramNormalized(const ColorImageT<P>& src, int min=0, int max=256, int nlevels=256);
  408. /**
  409. * Calculate a normalized histogram.
  410. * @param src source image
  411. * @param histo outputvector for the histogram (number of element / 3 is the number of histogram bins per color)
  412. * @param min lower boundary (included)
  413. * @param max upper boundary (not included)
  414. * @return normalized histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  415. */
  416. template<class P>
  417. static VectorT<float>* histogramNormalized(const ColorImageT<P>& src, VectorT<float> *histo, int min=0, int max=256);
  418. /**
  419. * Calculate a cumulative histogram.
  420. * @param src source image
  421. * @param min lower boundary (included)
  422. * @param max upper boundary (not included)
  423. * @param nlevels number of histogram bins
  424. * @return gray value cumulative histogram
  425. */
  426. template<class P>
  427. static VectorT<int>* histogramCumulative(const ImageT<P>& src, int min=0, int max=256, int nlevels=256);
  428. /**
  429. * Calculate a cumulative histogram.
  430. * @param src source image
  431. * @param histo outputvector for the histogram (number of element is the number of histogram bins)
  432. * @param min lower boundary (included)
  433. * @param max upper boundary (not included)
  434. * @return gray value cumulative histogram
  435. */
  436. template<class P>
  437. static VectorT<int>* histogramCumulative(const ImageT<P>& src, VectorT<int> *histo, int min=0, int max=256);
  438. /**
  439. * Calculate a cumulative histogram.
  440. * @param src source image
  441. * @param min lower boundary (included)
  442. * @param max upper boundary (not included)
  443. * @param nlevels number of histogram bins
  444. * @return cumulative histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  445. */
  446. template<class P>
  447. static VectorT<int>* histogramCumulative(const ColorImageT<P>& src, int min=0, int max=256, int nlevels=256);
  448. /**
  449. * Calculate a cumulative histogram.
  450. * @param src source image
  451. * @param histo outputvector for the histogram (number of element / 3 is the number of histogram bins per color)
  452. * @param min lower boundary (included)
  453. * @param max upper boundary (not included)
  454. * @return cumulative histogram (histogram bins for red, histogram bins for green and histogram bins for blue)
  455. */
  456. template<class P>
  457. static VectorT<int>* histogramCumulative(const ColorImageT<P>& src, VectorT<int> *histo, int min=0, int max=256);
  458. /**
  459. * Compute gradient streng image for a given vertical and horizontal gradient image
  460. * @param dx vertical gradient of a Image
  461. * @param dy horizontal gradient of a Image
  462. * @param buffer target buffer
  463. * @return FloatImage
  464. * @throw An ImageException will be thrown if the size of dx and dy are not equal.
  465. */
  466. static FloatImage* gradientStrength(const GrayImage16s& dx, const GrayImage16s& dy, FloatImage *buffer=NULL);
  467. /**
  468. * nonMaximumSuppression
  469. * @return FloatImage
  470. */
  471. static Image* nonMaximumSuppression(const GrayImage16s& dx, const GrayImage16s& dy, const FloatImage &mag, Image *buffer=NULL);
  472. /**
  473. * Calculates bitwise AND between the corresponding pixels of the ColorImage src0 and ColorImage src1 into the ColorImage dst.
  474. * @param src0 source color image
  475. * @param src1 source color image
  476. * @param dst destination color image
  477. * @return ColorImage
  478. */
  479. template<class P>
  480. static ColorImageT<P>* And(const ColorImageT<P>& src0, const ColorImageT<P>& src1, ColorImageT<P>* dst=NULL);
  481. /**
  482. * Calculates bitwise AND between the corresponding pixels of the Image src0 and Image src1 into the Image dst.
  483. * @param src0 source gray image
  484. * @param src1 source gray image
  485. * @param dst destination gray image
  486. * @return Image
  487. */
  488. template<class P>
  489. static ImageT<P>* And(const ImageT<P>& src0, const ImageT<P>& src1, ImageT<P>* dst=NULL);
  490. /**
  491. * Calculates the MEAN of the corresponding pixels of the ColorImage src0 and ColorImage src1 into the ColorImage dst.
  492. * @param src0 source color image
  493. * @param src1 source color image
  494. * @param dst destination color image
  495. * @return ColorImage
  496. */
  497. template<class P>
  498. static ColorImageT<P>* mean(const ColorImageT<P>& src0, const ColorImageT<P>& src1, ColorImageT<P>* dst=NULL);
  499. /**
  500. * Calculates the MEAN of the corresponding pixels of the Image src0 and Image src1 into the Image dst.
  501. * @param src0 source gray image
  502. * @param src1 source gray image
  503. * @param dst destination gray image
  504. * @return Image
  505. */
  506. template<class P>
  507. static ImageT<P>* mean(const ImageT<P>& src0, const ImageT<P>& src1, ImageT<P>* dst=NULL);
  508. /**
  509. * Calculates the absolute difference between Image src0 and Image src1 into the Image dst.
  510. * @param src0 source gray image
  511. * @param src1 source gray image
  512. * @param dst destination gray image
  513. * @return Image
  514. */
  515. static Image* absDiff(const Image& src0, const Image& src1, Image* dst=NULL);
  516. /**
  517. * Calculates the absolute difference between ColorImage src0 and ColorImage src1 into the ColorImage dst.
  518. * @param src0 source color image
  519. * @param src1 source color image
  520. * @param dst destination color image
  521. * @return ColorImage
  522. */
  523. static ColorImage* absDiff(const ColorImage& src0, const ColorImage& src1, ColorImage* dst=NULL);
  524. /**
  525. * Copies pixels from inside a rectangle in src to dst top left.
  526. * @param src source gray image
  527. * @param x0 left border of the rectangle in src
  528. * @param y0 top border of the rectangle in src
  529. * @param x1 right border of the rectangle in src
  530. * @param y1 lower border of the rectangle in src
  531. * @param dst destination gray image
  532. * @return Image
  533. */
  534. static Image* copyRect(const Image& src, const int& x0, const int& y0, const int& x1, const int& y1, Image* dst);
  535. /**
  536. * Copies pixels from inside a rectangle in src to dst top left.
  537. * @param src source color image
  538. * @param x0 left border of the rectangle in src
  539. * @param y0 top border of the rectangle in src
  540. * @param x1 right border of the rectangle in src
  541. * @param y1 lower border of the rectangle in src
  542. * @param dst destination color image
  543. * @return ColorImage
  544. */
  545. static ColorImage* copyRect(const ColorImage& src, const int& x0, const int& y0, const int& x1, const int& y1, ColorImage* dst);
  546. /**
  547. * Convert RGB to HSV inside a region of interest
  548. * (i.e. only a part of the image). The resulting image is
  549. * of the same (!) size as rgb.
  550. * @see rgbToGray()
  551. * @param rgb input image
  552. * @param gray optional buffer to be used as target.
  553. * Create a new Image if hsv == NULL.
  554. * If gray != NULL then size must be equal to rgb's size!
  555. * @param rect Region of interest
  556. */
  557. static Image* rgbToGrayRegion(const ColorImage& rgb,
  558. Image* gray,
  559. const Rect rect);
  560. /**
  561. * Compute horizontal part of the gradient of a Image via Sobel
  562. * inside a region of interest (i.e. only a part of the image).
  563. * The resulting image is of the same (!) size as gray.
  564. * @param gray Original gray image
  565. * @param dx optional buffer to be used as target.
  566. * Create a new GrayImage16s if dx == NULL.
  567. * If dx != NULL then size must be equal to gray's size!
  568. * @param rect Region of interest
  569. * @return GrayImage16s
  570. * @throw An ImageException will be thrown if
  571. * dx != NULL and the size of gray and dx are not equal.
  572. */
  573. static GrayImage16s* grayToDxRegion(const Image& gray,
  574. GrayImage16s* dx,
  575. Rect rect);
  576. /**
  577. * Canny algorithm for edge detection.
  578. * @param srcdx x-derivate of Image
  579. * @param srcdy y-derivate of Image
  580. * @param low lower edge threshold
  581. * @param high upper edge threshold
  582. * @param dst destination Image
  583. * @return ImageT<Ipp16s>
  584. */
  585. static Image* canny(GrayImage16s& srcdx, GrayImage16s &srcdy,
  586. float low, float high, Image* dst=NULL);
  587. /**
  588. * Filters Image \c src by columns into the Image \c dst using Sobel 3x3.
  589. * @param src source gray image
  590. * @param dst destination gray image
  591. * @return ImageT<Ipp16s>
  592. */
  593. template<class P>
  594. static ImageT<P>* grayToDx(const ImageT<P>& src, ImageT<P>* dst=NULL);
  595. static GrayImage16s* grayToDx(const Image& src, GrayImage16s* dst=NULL);
  596. /**
  597. * Filters Image \c src by rows into the Image \c dst using Sobel 3x3.
  598. * @param src source gray image
  599. * @param dst destination gray image
  600. * @return ImageT<Ipp16s>
  601. */
  602. template<class P>
  603. static ImageT<P>* grayToDy(const ImageT<P>& src, ImageT<P>* dst=NULL);
  604. static GrayImage16s* grayToDy(const Image& src, GrayImage16s* dst=NULL);
  605. /**
  606. * Filters Image \c src by columns into the Image \c dst using filter kernel \c kernel.
  607. * @param src source gray image
  608. * @param kernel filter kernel
  609. * @param anchor vertical offset to the kernelposition if negativ use center position
  610. * @param dst destination gray image
  611. * @return Image
  612. */
  613. template<class P>
  614. static ImageT<P>* filterX(const ImageT<P>& src, const VectorT<float> &kernel, int anchor=-1, ImageT<P>* dst=NULL);
  615. static Image* filterX(const Image& src, const VectorT<int> &kernel, int anchor=-1, int divisor=1, Image* dst=NULL);
  616. /**
  617. * Filters Image \c src by rows into the Image \c dst using filter kernel \c kernel.
  618. * @param src source gray image
  619. * @param kernel filter kernel
  620. * @param anchor horizontal offset to the kernelposition if negativ use center position
  621. * @param dst destination gray image
  622. * @return Image
  623. */
  624. template<class P>
  625. static ImageT<P>* filterY(const ImageT<P>& src, const VectorT<float> &kernel, int anchor=-1, ImageT<P>* dst=NULL);
  626. static Image* filterY(const Image& src, const VectorT<int> &kernel, int anchor=-1, int divisor=1, Image* dst=NULL);
  627. /**
  628. * Filters Image \c src by rows into the Image \c dst using filter kernel \c kernel.
  629. * @param src source gray image
  630. * @param kernel filter kernel (kernel cooefficient in inverse order!, use noAlignment for kernel image!)
  631. * @param anchorx horizontal offset to the kernelposition if negativ use center position
  632. * @param anchory vertical offset to the kernelposition if negativ use center position
  633. * @param dst destination gray image
  634. * @return Image
  635. */
  636. template<class P>
  637. static ImageT<P>* filter(const ImageT<P>& src, const FloatImage &kernel, int anchorx=-1, int anchory=-1, ImageT<P>* dst=NULL);
  638. static Image* filter(const Image& src, const ImageT<int> &kernel, int anchorx=-1, int anchory=-1, int divisor=1, Image* dst=NULL);
  639. /**
  640. * Performs a 2d valid convolution between src and kernel.
  641. * @param src source floatimage
  642. * @param kernel convolution floatimage (kernel cooefficient in inverse order!)
  643. * @param dst destination floatimage
  644. * @return Image
  645. */
  646. static FloatImage* convolution(const FloatImage& src, const FloatImage &kernel, FloatImage* dst=NULL);
  647. /**
  648. * Apply a 3x3 averaging filter to image
  649. * @param image Original image
  650. * @param buffer optional buffer to be used as target.
  651. * Create a new ColorImage if buffer == NULL.
  652. * If buffer != NULL then size must be equal to image's size!
  653. * @param rect Region of interest
  654. * @return ColorImage
  655. * @throw An ImageException will be thrown if
  656. * buffer != NULL and the size of image and buffer are not equal.
  657. */
  658. static ColorImage* filterLowpassRegion(const ColorImage& image,
  659. ColorImage* buffer,
  660. Rect rect);
  661. /**
  662. * Apply a 3x3 gauss filter to image
  663. * @param image Original image
  664. * @param buffer optional buffer to be used as target.
  665. * Create a new ColorImage if buffer == NULL.
  666. * If buffer != NULL then size must be equal to image's size!
  667. * @param rect Region of interest
  668. * @return ColorImage
  669. * @throw An ImageException will be thrown if
  670. * buffer != NULL and the size of image and buffer are not equal.
  671. */
  672. static ColorImage* filterGaussRegion(const ColorImage& image,
  673. ColorImage* buffer,
  674. Rect rect);
  675. /**
  676. * Apply a 3x3 gauss filter to image
  677. * @param image Original image
  678. * @param buffer optional buffer to be used as target.
  679. * Create a new Image if buffer == NULL.
  680. * @return Image
  681. */
  682. template<class P>
  683. static ImageT<P>* filterGauss3x3(const ImageT<P>& image, ImageT<P>* buffer=NULL);
  684. /**
  685. * Apply a 3x3 gauss filter to image
  686. * @param image Original image
  687. * @param buffer optional buffer to be used as target.
  688. * Create a new Image if buffer == NULL.
  689. * @return Image
  690. */
  691. template<class P>
  692. static ImageT<P>* filterGauss5x5(const ImageT<P>& image, ImageT<P>* buffer=NULL);
  693. /**
  694. * Apply a gauss filter with standard derivation sigma to image
  695. * @param image Original image
  696. * @param buffer optional buffer to be used as target.
  697. * Create a new ColorImage if buffer == NULL.
  698. * If buffer != NULL then size must be equal to image's size!
  699. * @param sigma standard derivation of the gauss distribution
  700. * @return ColorImage
  701. * @throw An ImageException will be thrown if
  702. * buffer != NULL and the size of image and buffer are not equal.
  703. */
  704. static Image* filterGauss(const Image& image,
  705. float sigma,
  706. Image* buffer=NULL);
  707. /* static ColorImage* filterGauss(const ColorImage& image,
  708. float sigma,
  709. ColorImage* buffer=NULL);
  710. */
  711. /**
  712. * Compute vertical part of the gradient of a Image via Sobel
  713. * inside a region of interest (i.e. only a part of the image).
  714. * The resulting image is of the same (!) size as gray.
  715. * @param gray Original gray image
  716. * @param dy optional buffer to be used as target.
  717. * Create a new GrayImage16s if dy == NULL.
  718. * If dy != NULL then size must be equal to gray's size!
  719. * @param rect Region of interest
  720. * @return GrayImage16s
  721. * @throw An ImageException will be thrown if
  722. * dy != NULL and the size of gray and dy are not equal.
  723. */
  724. static GrayImage16s* grayToDyRegion(const Image& gray,
  725. GrayImage16s* dy,
  726. const Rect rect);
  727. /**
  728. * Convert a floating point image into a gray image (in RGB format)
  729. */
  730. static ColorImage* floatImageToGrayRGB(const FloatImage& floatImage,
  731. ColorImage* image);
  732. /**
  733. * Convert a signed image into a colored image
  734. * (white positiv values, red negativ values).
  735. * @note usefull to display float or signed images
  736. */
  737. template<class P>
  738. static ColorImage* signedImageToRGB(const ImageT<P>& image,
  739. ColorImage* colored);
  740. /**
  741. * Clip a \c rect within \c image.
  742. * @param image The image
  743. * @param rect The rectangle
  744. * @return \c Rect
  745. */
  746. static inline Rect clipRect(const MultiChannelImageAccess& image, const Rect rect) {
  747. return NICE::clipRect(image, rect);
  748. }
  749. /**
  750. * Make an \c IppiRect for the full image.
  751. * @param image The image
  752. * @return \c IppiRect
  753. */
  754. static inline IppiRect makeRectFullImage(const MultiChannelImageAccess& image) {
  755. return NICE::makeRectFullImage(image);
  756. }
  757. /**
  758. * Make an \c IppiSize for the full image.
  759. * @param image The image
  760. * @return \c IppiSize
  761. */
  762. static inline IppiSize makeROIFullImage(const MultiChannelImageAccess& image) {
  763. return NICE::makeROIFullImage(image);
  764. }
  765. /**
  766. * Get an \c IppiSize for \c rect clipped within \c image.
  767. * @param image The image
  768. * @param rect The rectangle
  769. * @return \c IppiSize
  770. */
  771. static inline IppiSize makeROIRect(const MultiChannelImageAccess& image, const Rect rect) {
  772. return NICE::makeROIRect(image, rect);
  773. }
  774. #ifdef NICE_USELIB_IPP
  775. /**
  776. * Work around a certain IPP bug (?).
  777. * @param ippiSize input and output
  778. * @param clippedROI input and output
  779. */
  780. static void preventIppBug(IppiSize& ippiSize, Rect& clippedROI) {
  781. return NICE::preventIppBug(ippiSize, clippedROI);
  782. }
  783. #endif // NICE_USELIB_IPP
  784. private:
  785. /**
  786. * Create result buffer.
  787. * @param image input
  788. * @param buffer image buffer for result
  789. * @return image buffer
  790. */
  791. template<class IMG, class BUFFER>
  792. static BUFFER* createResultBuffer(const IMG& image,
  793. BUFFER* buffer);
  794. /**
  795. * Create result buffer.
  796. * @param width width of the input image
  797. * @param height height of the input image
  798. * @param buffer image buffer for result
  799. * @return image buffer
  800. */
  801. template<class BUFFER>
  802. static BUFFER* createResultBuffer(const int width,
  803. const int height,
  804. BUFFER* buffer);
  805. };
  806. } // namespace
  807. #include "core/image/ImageT.h"
  808. #include "core/image/ImageT.h"
  809. #include "core/image/ColorImageT.h"
  810. //#ifdef __GNUC__
  811. #include <core/image/DeprecatedConverter.tcc>
  812. //#endif
  813. #endif