2d/image.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2014 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #ifndef mia_2d_2dimage_hh
23 #define mia_2d_2dimage_hh
24 
25 #include <mia/core/attributes.hh>
26 #include <mia/core/pixeltype.hh>
27 #include <mia/core/filter.hh>
28 #include <mia/core/msgstream.hh>
29 #include <mia/core/tools.hh>
30 #include <mia/core/type_traits.hh>
31 #include <mia/2d/vectorfield.hh>
32 
34 
35 #define ATTR_IMAGE_KMEANS_CLASSES "kmeans"
36 
37 
48 public:
51  static const char *data_descr;
52 
55 
57  typedef std::shared_ptr<C2DImage > Pointer;
58 
59  virtual ~C2DImage();
60 
62  EPixelType get_pixel_type() const;
63 
65  const C2DBounds& get_size() const;
66 
68  C2DFVector get_pixel_size() const;
69 
71  void set_pixel_size(const C2DFVector& pixel);
72 
77  virtual C2DImage* clone() const __attribute__((warn_unused_result)) = 0;
78 
79  protected:
82  C2DImage(const C2DBounds& size, EPixelType type);
83 
86  C2DImage(const CAttributedData& attributes, const C2DBounds& size, EPixelType type);
87 
91  C2DImage();
92 
93  private:
94  C2DBounds m_size;
95  EPixelType m_pixel_type;
96 };
97 
99 typedef C2DImage::Pointer P2DImage;
100 
102 typedef std::vector<P2DImage> C2DImageSeries;
103 
104 typedef std::shared_ptr<C2DImageSeries> P2DImageSeries;
105 
106 typedef std::vector<C2DImageSeries> C2DImageSeriesGroup;
107 typedef std::map<std::string, C2DImageSeriesGroup> C2DImageGroupedSeries;
108 
109 
117 template <typename T>
118 class EXPORT_2D T2DImage : public C2DImage {
119 public:
121  typedef C2DImage Super;
122 
124  typedef typename T2DDatafield<T>::iterator iterator;
125  typedef typename T2DDatafield<T>::const_iterator const_iterator;
126  typedef typename T2DDatafield<T>::const_reference const_reference;
127  typedef typename T2DDatafield<T>::reference reference;
128  typedef typename T2DDatafield<T>::const_pointer const_pointer;
129  typedef typename T2DDatafield<T>::pointer pointer;
130  typedef typename T2DDatafield<T>::value_type value_type;
131  typedef typename T2DDatafield<T>::difference_type difference_type;
132  typedef typename T2DDatafield<T>::size_type size_type;
133  typedef typename T2DDatafield<T>::range_iterator range_iterator;
134  typedef typename T2DDatafield<T>::const_range_iterator const_range_iterator;
135  typedef typename T2DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
136  typedef typename T2DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
137 
138  typedef typename T2DDatafield<T>::data_array data_array;
139 
141 
147  T2DImage(const C2DBounds& size, const T* init_data);
148 
154  T2DImage(const C2DBounds& size, const data_array& init_data);
160  T2DImage(const C2DBounds& size, const CAttributedData& attr);
161 
166  T2DImage(const C2DBounds& size);
167 
171  T2DImage(const T2DImage& orig);
172 
177  T2DImage(const T2DDatafield<T>& orig);
178 
184  T2DImage(const T2DDatafield<T>& orig, const CAttributedData& attr);
185 
186  T2DImage();
187 
191  virtual C2DImage* clone() const __attribute__((warn_unused_result));
192 
194  const_reference operator()(size_t x, size_t y) const {
195  return m_image(x,y);
196  }
197 
199  reference operator()(size_t x, size_t y){
200  return m_image(x,y);
201  }
202 
204  const_reference operator[](size_t idx) const {
205  return m_image[idx];
206  }
207 
209  reference operator[](size_t idx){
210  return m_image[idx];
211  }
212 
214  const_reference operator()(const C2DBounds& l) const{
215  return m_image(l.x,l.y);
216  }
217 
219  reference operator()(const C2DBounds& l){
220  return m_image(l.x,l.y);
221  }
222 
224  const_iterator begin()const {
225  return m_image.begin();
226  }
227 
229  const_iterator end()const {
230  return m_image.end();
231  }
232 
234  iterator begin() {
235  return m_image.begin();
236  }
237 
239  iterator end() {
240  return m_image.end();
241  }
242 
244  const_iterator begin_at(size_t x, size_t y)const {
245  return m_image.begin_at(x, y);
246  }
247 
249  iterator begin_at(size_t x, size_t y) {
250  return m_image.begin_at(x, y);
251  }
252 
254  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end) {
255  return m_image.begin_range(begin, end);
256  }
257 
259  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end){
260  return m_image.end_range(begin, end);
261  }
262 
264  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const {
265  return m_image.begin_range(begin, end);
266  }
267 
269  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end) const{
270  return m_image.end_range(begin, end);
271  }
272 
274  size_t size() const;
275 
277  const T2DDatafield<T>& data() const;
278 
280  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
281 
283  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
284 
286  void put_data_line_x(size_t y, const std::vector<T>& buffer);
287 
289  void put_data_line_y(size_t x, const std::vector<T>& buffer);
290 
296  C2DFVector get_gradient(size_t idx) const;
297 
303  C2DFVector get_gradient(const C2DFVector& p) const;
304 private:
305  T2DDatafield<T> m_image;
306 };
307 
312 class CImageComparePrinter: public TFilter<int> {
313 public:
314  template <typename T, typename S>
315  int operator () (const T2DImage<T>& src, const T2DImage<S>& ref) const {
316  typename T2DImage<T>::const_iterator si = src.begin();
317  typename T2DImage<T>::const_iterator se = src.end();
318  typename T2DImage<S>::const_iterator ri = ref.begin();
319 
320  while (si != se)
321  cvdebug() << *si++ << " expect " << *ri++ << "\n";
322  return 0;
323  }
324 };
325 
329 template <typename S>
330 struct plugin_data_type<T2DImage<S> > {
331  typedef C2DImage type;
332 };
334 
344 EXPORT_2D bool operator == (const C2DImage& a, const C2DImage& b);
345 
350 inline bool operator != (const C2DImage& a, const C2DImage& b)
351 {
352  return ! (a == b );
353 }
354 
355 
361 
369 public:
370  template <typename T>
371  P2DImage operator () (const T2DImage<T>& image) const {
372  return P2DImage(new T2DImage<T>(image));
373  }
374 };
375 
378 
381 
384 
387 
390 
393 
396 
397 #ifdef LONG_64BIT
400 
403 #endif
404 
407 
410 
419 template <>
420 struct Binder<C2DImage> {
422  typedef __bind_all<T2DImage> Derived;
423 };
424 
428 template <>
429 struct dispatch_attr_string<C2DFVector> {
435  static std::string val2string(const C2DFVector& value) {
436  std::stringstream sval;
437  sval << value.x << " " << value.y;
438  return sval.str();
439  }
445  static C2DFVector string2val(const std::string& str) {
446  std::istringstream sval(str);
447  C2DFVector value;
448  sval >> value.x >> value.y;
449  return value;
450  }
451 };
453 
465 template <typename O>
466 struct FConvert2DImageToPixeltypeO: public TFilter<T2DImage<O> > {
467 
473  template <typename T>
474  T2DImage<O> operator () (const T2DImage<T> &image) const {
475  T2DImage<O> result(image.get_size(), image);
476  copy(image.begin(), image.end(), result.begin());
477  return result;
478  }
479 
486  T2DImage<O> operator () (const C2DImage &image) const {
487  return filter(*this, image);
488  }
489 
496  T2DImage<O> operator () (P2DImage image) const {
497  return filter(*this, *image);
498  }
499 };
500 
501 
509 
512 
513 
515 
516 #endif
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:99
CDebugSink & cvdebug()
Definition: msgstream.hh:216
TTranslator< C2DFVector > C2DFVectorTranslator
typedef for the C2DFVector to std::string translator
Definition: 2d/image.hh:511
std::map< std::string, C2DImageSeriesGroup > C2DImageGroupedSeries
Definition: 2d/image.hh:107
T2DImage< signed int > C2DSIImage
2D image with signed 32 bit integer values
Definition: 2d/image.hh:392
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 2d/image.hh:466
Generic string vs. attribute translator singleton.
Definition: attributes.hh:506
iterator end()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:239
std::vector< C2DImageSeries > C2DImageSeriesGroup
Definition: 2d/image.hh:106
EPixelType
Definition: pixeltype.hh:32
functor to copy an image into paointer representation
Definition: 2d/image.hh:368
T2DImage< double > C2DDImage
2D image with double precsion floating point values
Definition: 2d/image.hh:409
base class for all filer type functors.
Definition: core/filter.hh:68
T y
second element
Definition: 2d/vector.hh:56
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:118
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
A collection of attributes.
Definition: attributes.hh:252
T2DImage< unsigned short > C2DUSImage
2D image with unsigned 16 bit integer values
Definition: 2d/image.hh:389
T2DImage< float > C2DFImage
2D image with single precsion floating point values
Definition: 2d/image.hh:406
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:230
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:229
EXPORT_2D bool operator==(const C2DImage &a, const C2DImage &b)
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition: 2d/image.hh:350
range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end)
forwarding function to access the specified range of the underlying T2DDatafield
Definition: 2d/image.hh:254
reference operator[](size_t idx)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:209
T2DImage< signed short > C2DSSImage
2D image with signed 16 bit integer values
Definition: 2d/image.hh:386
#define EXPORT_2D
Definition: defines2d.hh:37
iterator begin_at(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:249
iterator begin()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:234
const_range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end) const
forwarding function to access the specified range of the underlying T2DDatafield
Definition: 2d/image.hh:264
T2DImage< unsigned int > C2DUIImage
2D image with unsigned 32 bit integer values
Definition: 2d/image.hh:395
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:224
std::shared_ptr< C2DImage > Pointer
2D Image pointer type
Definition: 2d/image.hh:57
static const char * data_descr
Definition: 2d/image.hh:51
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:52
C2DImage Super
define the super class of this class for generic processing
Definition: 2d/image.hh:121
const_reference operator[](size_t idx) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:204
T2DImage< unsigned char > C2DUBImage
2D image with unsigned 8 bit integer values
Definition: 2d/image.hh:383
reference operator()(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:199
const_iterator begin_at(size_t x, size_t y) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:244
std::shared_ptr< C2DImageSeries > P2DImageSeries
Definition: 2d/image.hh:104
range_iterator end_range(const C2DBounds &begin, const C2DBounds &end)
forwarding function to access the specified range of the underlying T2DDatafield
Definition: 2d/image.hh:259
FConvert2DImageToPixeltypeO< float > FCopy2DImageToFloatRepn
short name for 2DImage to float pixel repn copy functor
Definition: 2d/image.hh:508
const_range_iterator end_range(const C2DBounds &begin, const C2DBounds &end) const
forwarding function to access the specified range of the underlying T2DDatafield
Definition: 2d/image.hh:269
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:47
C2DBounds dimsize_type
a definition of the image dimension type for
Definition: 2d/image.hh:54
T2DImage< bool > C2DBitImage
2D image with binary values
Definition: 2d/image.hh:377
T2DImage< signed char > C2DSBImage
2D image with signed 8 bit integer values
Definition: 2d/image.hh:380
a class to print out the intensity values of two images to compare them
Definition: 2d/image.hh:312
const C2DBounds & get_size() const
::std::vector< T > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:57
std::vector< P2DImage > C2DImageSeries
helper type for image series
Definition: 2d/image.hh:102
T2DImage< signed long > C2DSLImage
2D image with signed 64 bit integer values
Definition: 2d/image.hh:399
T2DImage< unsigned long > C2DULImage
2D image with unsigned 64 bit integer values
Definition: 2d/image.hh:402
const_reference operator()(const C2DBounds &l) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:214
reference operator()(const C2DBounds &l)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:219
T x
first element
Definition: 2d/vector.hh:53
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46