Morph.tcc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <iostream>
  2. namespace NICE {
  3. template<class P>
  4. ImageT<P>* median(const ImageT<P>& src, int anchorx, int anchory, uint maskx, uint masky, ImageT<P>* dst)
  5. {
  6. if(anchorx==-1)
  7. anchorx=maskx/2;
  8. if(anchory==-1)
  9. anchory=masky/2;
  10. ImageT<P> *result = createResultBuffer(src, dst);
  11. if( src.width()!=result->width() || src.height()!=result->height() )
  12. fthrow(ImageException,"src and dst must have the same size.");
  13. #ifdef NICE_USELIB_IPP
  14. IppiPoint anchor={anchorx,anchory};
  15. IppiSize ippiSize = { src.width()-maskx+1, src.height()-masky+1 };
  16. IppiSize mask={maskx,masky};
  17. IppStatus ret = ippiFilterMedian_C1R(
  18. src.getPixelPointerXY(maskx-1-anchorx,masky-1-anchory),
  19. src.getStepsize(),
  20. result->getPixelPointerXY(anchorx,anchory),
  21. result->getStepsize(),
  22. ippiSize,
  23. mask,
  24. anchor);
  25. if(ret!=ippStsNoErr)
  26. fthrow(ImageException, ippGetStatusString(ret));
  27. #else // NICE_USELIB_IPP
  28. fthrow(ImageException,"Not yet supportet without IPP.");
  29. #endif // NICE_USELIB_IPP
  30. return result;
  31. }
  32. template<class P>
  33. ColorImageT<P>* median(const ColorImageT<P>& src,bool mask, ColorImageT<P>* dst)
  34. {
  35. ColorImageT<P> *result = createResultBuffer(src, dst);
  36. if( src.width()!=result->width() || src.height()!=result->height() )
  37. fthrow(ImageException,"src and dst must have the same size.");
  38. #ifdef NICE_USELIB_IPP
  39. IppiMaskSize masksize;
  40. if (mask)
  41. {
  42. masksize=ippMskSize5x5;
  43. }
  44. else
  45. {
  46. masksize=ippMskSize3x3;
  47. }
  48. IppiSize ippiSize = { src.width()-4, src.height()-4 };
  49. IppStatus ret = ippiFilterMedianColor_C3R(
  50. src.getPixelPointerXY(4,4),
  51. src.getStepsize(),
  52. result->getPixelPointerXY(0,0),
  53. result->getStepsize(),
  54. ippiSize,
  55. masksize);
  56. if(ret!=ippStsNoErr)
  57. fthrow(ImageException, ippGetStatusString(ret));
  58. #else // NICE_USELIB_IPP
  59. fthrow(ImageException,"Not yet supportet without IPP.");
  60. #endif // NICE_USELIB_IPP
  61. return result;
  62. }
  63. }