aimstil  5.0.5
BasicPixelTests.h
Go to the documentation of this file.
1 #ifndef TIL_BASIC_PIXEL_TESTS_H
2 #define TIL_BASIC_PIXEL_TESTS_H
3 
4 
5 // Local includes
6 #include "til/til_common.h"
7 #include "til/numeric_array.h"
8 
10 //
11 // Classes that make simple tests on pixels, used in loops of some functions
12 // that enable to template over such classes (e.g. region growing).
13 //
14 // For consistency between iterator approaches and position approaches, the
15 // image has always to be passed as an argument, i.e. the pixel class
16 // discovers every time the image it has to process. It comes to the price that
17 // no preprocessing can be done inside a test class. On the other hand,
18 // iterators can be used without fear that the image being processed is
19 // actually different from the image that the iterator is refering to.
20 //
22 
23 
24 namespace til
25 {
26 
27 
28 // This class is not a test, it merely collects common code over a range of
29 // pixel test class.
30 
31 /*
32 template < class TImage >
33 class PT_NoValue
34 {
35 
36 public: // typedefs
37 
38  typedef typename TImage::ConstVolumetricIterator ConstVolumetricIterator;
39  typedef typename TImage::value_type value_type;
40 
41 public: // constructors & destructor
42 
43  PT_NoValue() {}
44 
45 public: // set & get
46 
47  void setImage(ConstPtr<TImage> &im) { m_im = im; }
48  const ConstPtr<TImage> & image() const { return m_im; }
49 
50 public: // functions
51 
52  static void next() {}
53 
54 private: // data
55 
56  ConstPtr<TImage> m_im;
57 };
58 
59 
60 
61 template < class TImage >
62 class PT_IsOnImageBorder : public PT_NoValue<TImage>
63 {
64 
65 public: // function
66 
67  bool compute(const ConstVolumetricIterator &iIm) const
68  {
69  return this->_compute(iIm.pos(), iIm.image()->getDim());
70  }
71 
72  bool compute(const Vector<int,3> &pos) const
73  {
74  return this->_compute(this->image()->getValue(pos), m_im.size());
75  }
76 
77 private: // function
78 
79  bool _compute(const Vector<int,3> &pos, const Vector<int,3> &imDim) const
80  {
81  return (
82  (pos.getX() == 0) ||
83  (pos.getY() == 0) ||
84  (pos.getZ() == 0) ||
85  (pos.getX() == imDim.getX()-1) ||
86  (pos.getY() == imDim.getY()-1) ||
87  (pos.getZ() == imDim.getZ()-1));
88  }
89 };
90 */
91 
92 // This class is not a test, it merely collects common code over a range of
93 // pixel test class.
94 
95 template < class _TImage >
97 {
98 
99 public: // typedefs
100 
101  typedef _TImage TImage;
102  typedef typename TImage::value_type value_type;
104 
105 public: // constructors & destructor
106 
107  PT_SingleValue() { this->setValue(0); }
108  PT_SingleValue(value_type value) { this->setValue(value); }
109 
110 public: // set & get
111 
112  void setValue(value_type value) { m_value = value; }
113  value_type getValue() const { return m_value; }
114 
115 public: // functions
116 
117  static void next() {}
118 
119 private: // data
120 
121  value_type m_value;
122 };
123 
124 
125 
126 // Test is intensity is below some fixed threshold
127 
128 template < class TImage >
129 class PT_IsBelow : public PT_SingleValue<TImage>
130 {
131 public: // typedefs
132 
133  typedef typename TImage::value_type value_type;
135 
136 public: // constructors & destructor
137 
139  PT_IsBelow(value_type value) : PT_SingleValue<TImage>(value) {}
140 
141 public: // function
142 
143  bool compute(const ConstVolumetricIterator &iIm) const
144  {
145  return this->_compute(*iIm);
146  }
147 
148  bool compute(const TImage &im, const numeric_array<int,3> &pos) const
149  {
150  return this->_compute(im.getValue(pos));
151  }
152 
153 private: // function
154 
155  bool _compute(value_type value) const
156  {
157  return value <= this->getValue();
158  }
159 };
160 
161 
162 // Test if intensity is above some fixed threshold
163 
164 template < class TImage >
165 class PT_IsAbove : public PT_SingleValue<TImage>
166 {
167 public: // typedefs
168 
169  typedef typename TImage::value_type value_type;
171 
172 public: // constructors & destructor
173 
175  PT_IsAbove(value_type value) : PT_SingleValue<TImage>(value) {}
176 
177 public: // function
178 
179  bool compute(const ConstVolumetricIterator & iIm) const
180  {
181  return this->_compute(*iIm);
182  }
183 
184  bool compute(const TImage & im, const numeric_array<int,3> & pos) const
185  {
186  return this->_compute(im(pos));
187  }
188 
189 private: // function
190 
191  bool _compute(value_type value) const
192  {
193  return value >= this->getValue();
194  }
195 };
196 
197 
198 // Test if intensity is equal to some fixed value
199 
200 template < class TImage >
201 class PT_IsEqual : public PT_SingleValue<TImage>
202 {
203 public: // typedefs
204 
205  typedef typename TImage::value_type value_type;
207 
208 public: // constructors & destructor
209 
211  PT_IsEqual(value_type value) : PT_SingleValue<TImage>(value) {}
212 
213 public: // function
214 
215  bool compute(const ConstVolumetricIterator & iIm) const
216  {
217  return this->_compute(*iIm);
218  }
219 
220  bool compute(const TImage &im, const numeric_array<int,3> & pos) const
221  {
222  return this->_compute(im(pos));
223  }
224 
225 private: // function
226 
227  bool _compute(value_type value) const
228  {
229  return value == this->getValue();
230  }
231 };
232 
233 
234 // Test if intensity is different from a given fixed value
235 /*
236 template < class TImage >
237 class PT_IsNotEqual : public PT_SingleValue<TImage>
238 {
239 
240 public: // constructors & destructor
241 
242  PT_IsNotEqual() : PT_SingleValue<TImage>() {}
243  PT_IsNotEqual(value_type value) : PT_SingleValue<TImage>(value) {}
244 
245 public: // function
246 
247  bool compute(const ConstVolumetricIterator &iIm) const
248  {
249  return this->_compute(*iIm);
250  }
251 
252  bool compute(const ConstPtr<TImage> &im, const Vector<int,3> &pos) const
253  {
254  return this->_compute(im.getValue(pos));
255  }
256 
257 private: // function
258 
259  bool _compute(value_type value) const
260  {
261  return value != this->getValue();
262  }
263 };
264 */
265 } // namespace
266 
267 #endif
268 
269 
A trait class to assign iterators to image types.
void setValue(value_type value)
TImage::value_type value_type
bool compute(const TImage &im, const numeric_array< int, 3 > &pos) const
bool compute(const ConstVolumetricIterator &iIm) const
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
bool compute(const TImage &im, const numeric_array< int, 3 > &pos) const
General macros, definitions and functions.
PT_IsAbove(value_type value)
TImage::value_type value_type
bool compute(const ConstVolumetricIterator &iIm) const
bool compute(const TImage &im, const numeric_array< int, 3 > &pos) const
PT_IsEqual(value_type value)
PT_IsBelow(value_type value)
bool compute(const ConstVolumetricIterator &iIm) const
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
value_type getValue() const
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
PT_SingleValue(value_type value)
Iterator< TImage >::ConstVolumetric ConstVolumetricIterator
TImage::value_type value_type
TImage::value_type value_type