TUnaryTransformProcessorComp.h
Go to the documentation of this file.
1 #ifndef iipr_TUnaryTransformProcessorComp_included
2 #define iipr_TUnaryTransformProcessorComp_included
3 
4 
5 // STL includes
6 #include <functional>
7 
8 // ACF includes
10 
11 #ifdef max
12  #undef max
13 #endif
14 
15 
16 namespace iipr
17 {
18 
19 
20 template <typename ArgumentType>
21 class InvertFunction: public std::unary_function<ArgumentType, ArgumentType>
22 {
23 public:
25  {
26  m_maxValue = std::numeric_limits<ArgumentType>::max();
27  }
28 
29  inline ArgumentType operator()(const ArgumentType& value)
30  {
31  return (m_maxValue - value);
32  }
33 
34 private:
35  ArgumentType m_maxValue;
36 };
37 
38 
42 template <typename PixelType, class Predicate>
44 {
45 public:
47 
48  I_BEGIN_COMPONENT(TUnaryTransformProcessorComp);
49  I_END_COMPONENT;
50 
51 protected:
52  // reimplemented (iipr::CImageProcessorCompBase)
53  virtual bool ProcessImage(
54  const iprm::IParamsSet* paramsPtr,
55  const iimg::IBitmap& inputImage,
56  iimg::IBitmap& outputImage);
57 
58 private:
59  Predicate m_predicate;
60 };
61 
62 
63 // reimplemented (iipr::CImageProcessorCompBase)
64 
65 template <typename PixelType, class Predicate>
67  const iprm::IParamsSet* /*paramsPtr*/,
68  const iimg::IBitmap& inputImage,
69  iimg::IBitmap& outputImage)
70 {
71  if (!outputImage.CreateBitmap(inputImage.GetPixelFormat(), inputImage.GetImageSize())){
72  SendErrorMessage(0, "Output bitmap could not be created");
73 
74  return false; // cannot create output image
75  }
76 
77  int imageWidth = inputImage.GetImageSize().GetX();
78  int imageHeight = inputImage.GetImageSize().GetY();
79  int componentsCount = inputImage.GetComponentsCount();
80 
81  for (int y = 0; y < imageHeight; y++){
82  PixelType* inputImageLinePtr = (PixelType*)inputImage.GetLinePtr(y);
83  PixelType* outputImageLinePtr = (PixelType*)outputImage.GetLinePtr(y);
84 
85  for (int x = 0; x < imageWidth; x++){
86  for (int colorComponentIndex = 0; colorComponentIndex < componentsCount; colorComponentIndex++){
87  int pixelOffset = x * componentsCount + colorComponentIndex;
88 
89  outputImageLinePtr[pixelOffset] = m_predicate(inputImageLinePtr[pixelOffset]);
90  }
91  }
92  }
93 
94  return true;
95 }
96 
97 
99 
100 
101 } // namespace iipr
102 
103 
104 #endif // !iipr_TUnaryTransformProcessorComp_included
105 
106 
TUnaryTransformProcessorComp< quint8, InvertFunction< quint8 > > CInvertOperatorComp
Implementation of general morphological operator.
ArgumentType operator()(const ArgumentType &value)
Basic implementation for a simple bitmap processor.
virtual bool ProcessImage(const iprm::IParamsSet *paramsPtr, const iimg::IBitmap &inputImage, iimg::IBitmap &outputImage)

© 2007-2011 Witold Gantzke and Kirill Lepskiy