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-2017 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 
73 
75  C2DFVector get_origin() const;
76 
78  void set_origin(const C2DFVector& origin);
79 
84  virtual C2DImage* clone() const __attribute__((warn_unused_result)) = 0;
85 
86  virtual std::pair<double, double> get_minmax_intensity() const = 0;
87 
88  virtual void make_single_ref() __attribute__((deprecated)) = 0;
89 
90  protected:
91  C2DImage(C2DImage&& other);
92  C2DImage& operator = (C2DImage&& other);
93 
94  C2DImage(const C2DImage& other) = default;
95 
96 
97  C2DImage& operator = (const C2DImage& other) = default;
98 
99 
102  C2DImage(const C2DBounds& size, EPixelType type);
103 
106  C2DImage(const CAttributedData& attributes, const C2DBounds& size, EPixelType type);
107 
111  C2DImage();
112 
113 private:
114  C2DBounds m_size;
115  EPixelType m_pixel_type;
116 };
117 
119 typedef C2DImage::Pointer P2DImage;
120 
122 typedef std::vector<P2DImage> C2DImageSeries;
123 
124 typedef std::shared_ptr<C2DImageSeries> P2DImageSeries;
125 
126 typedef std::vector<C2DImageSeries> C2DImageSeriesGroup;
127 typedef std::map<std::string, C2DImageSeriesGroup> C2DImageGroupedSeries;
128 
129 
137 template <typename T>
138 class EXPORT_2D T2DImage : public C2DImage {
139 public:
141  typedef C2DImage Super;
142 
144  typedef typename T2DDatafield<T>::iterator iterator;
145  typedef typename T2DDatafield<T>::const_iterator const_iterator;
146  typedef typename T2DDatafield<T>::const_reference const_reference;
147  typedef typename T2DDatafield<T>::reference reference;
148  typedef typename T2DDatafield<T>::const_pointer const_pointer;
149  typedef typename T2DDatafield<T>::pointer pointer;
150  typedef typename T2DDatafield<T>::value_type value_type;
151  typedef typename T2DDatafield<T>::difference_type difference_type;
152  typedef typename T2DDatafield<T>::size_type size_type;
153  typedef typename T2DDatafield<T>::range_iterator range_iterator;
154  typedef typename T2DDatafield<T>::const_range_iterator const_range_iterator;
155  typedef typename T2DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
156  typedef typename T2DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
157 
158  typedef typename T2DDatafield<T>::data_array data_array;
159 
161 
167  T2DImage(const C2DBounds& size, const T* init_data);
168 
174  T2DImage(const C2DBounds& size, const std::vector<T>& init_data);
180  T2DImage(const C2DBounds& size, const CAttributedData& attr);
181 
186  T2DImage(const C2DBounds& size);
187 
191  T2DImage(const T2DImage& orig);
192 
196  T2DImage(T2DImage&& orig);
197 
202 
203 
207  T2DImage<T>& operator = (const T2DImage<T>& orig);
208 
209 
214  T2DImage(const T2DDatafield<T>& orig);
215 
221  T2DImage(const T2DDatafield<T>& orig, const CAttributedData& attr);
222 
223  T2DImage();
224 
228  virtual C2DImage* clone() const __attribute__((warn_unused_result));
229 
231  const_reference operator()(size_t x, size_t y) const {
232  return m_image(x,y);
233  }
234 
236  reference operator()(size_t x, size_t y){
237  return m_image(x,y);
238  }
239 
241  const_reference operator[](size_t idx) const {
242  return m_image[idx];
243  }
244 
246  reference operator[](size_t idx){
247  return m_image[idx];
248  }
249 
251  const_reference operator()(const C2DBounds& l) const{
252  return m_image(l.x,l.y);
253  }
254 
256  reference operator()(const C2DBounds& l){
257  return m_image(l.x,l.y);
258  }
259 
261  const_iterator begin()const {
262  return m_image.begin();
263  }
264 
266  const_iterator end()const {
267  return m_image.end();
268  }
269 
271  iterator begin() {
272  return m_image.begin();
273  }
274 
276  iterator end() {
277  return m_image.end();
278  }
279 
281  const_iterator begin_at(size_t x, size_t y)const {
282  return m_image.begin_at(x, y);
283  }
284 
286  iterator begin_at(size_t x, size_t y) {
287  return m_image.begin_at(x, y);
288  }
289 
291  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end) {
292  return m_image.begin_range(begin, end);
293  }
294 
296  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end){
297  return m_image.end_range(begin, end);
298  }
299 
301  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const {
302  return m_image.begin_range(begin, end);
303  }
304 
306  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end) const{
307  return m_image.end_range(begin, end);
308  }
309 
311  size_t size() const;
312 
314  const T2DDatafield<T>& data() const;
315 
317  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
318 
320  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
321 
323  void put_data_line_x(size_t y, const std::vector<T>& buffer);
324 
326  void put_data_line_y(size_t x, const std::vector<T>& buffer);
327 
333  C2DFVector get_gradient(size_t idx) const;
334 
340  C2DFVector get_gradient(const C2DFVector& p) const;
341 
343  std::pair<double, double> get_minmax_intensity() const;
344 
345  void make_single_ref() __attribute__((deprecated));
346 private:
347  T2DDatafield<T> m_image;
348 };
349 
354 class CImageComparePrinter: public TFilter<int> {
355 public:
356  template <typename T, typename S>
357  int operator () (const T2DImage<T>& src, const T2DImage<S>& ref) const {
358  typename T2DImage<T>::const_iterator si = src.begin();
359  typename T2DImage<T>::const_iterator se = src.end();
360  typename T2DImage<S>::const_iterator ri = ref.begin();
361 
362  while (si != se)
363  cvdebug() << *si++ << " expect " << *ri++ << "\n";
364  return 0;
365  }
366 };
367 
371 template <typename S>
372 struct plugin_data_type<T2DImage<S> > {
373  typedef C2DImage type;
374 };
376 
386 EXPORT_2D bool operator == (const C2DImage& a, const C2DImage& b);
387 
392 inline bool operator != (const C2DImage& a, const C2DImage& b)
393 {
394  return ! (a == b );
395 }
396 
397 
403 
411 public:
412  template <typename T>
413  P2DImage operator () (const T2DImage<T>& image) const {
414  return P2DImage(new T2DImage<T>(image));
415  }
416 };
417 
420 
423 
426 
429 
432 
435 
438 
441 
444 
447 
450 
459 template <>
460 struct Binder<C2DImage> {
462  typedef __bind_all<T2DImage> Derived;
463 };
464 
465 //@endcond INTERNAL
466 
478 template <typename O>
479 struct FConvert2DImageToPixeltypeO: public TFilter<T2DImage<O> > {
480 
486  template <typename T>
487  T2DImage<O> operator () (const T2DImage<T> &image) const {
488  T2DImage<O> result(image.get_size(), image);
489  copy(image.begin(), image.end(), result.begin());
490  return result;
491  }
492 
499  T2DImage<O> operator () (const C2DImage &image) const {
500  return filter(*this, image);
501  }
502 
509  T2DImage<O> operator () (P2DImage image) const {
510  return filter(*this, *image);
511  }
512 };
513 
514 
522 
523 
525 
526 #endif
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:119
CDebugSink & cvdebug()
Definition: msgstream.hh:216
T2DImage< int8_t > C2DSBImage
2D image with signed 8 bit integer values
Definition: 2d/image.hh:422
std::map< std::string, C2DImageSeriesGroup > C2DImageGroupedSeries
Definition: 2d/image.hh:127
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:301
functor to convert an image with an abitrary pixel type to single floating point pixels ...
Definition: 2d/image.hh:479
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:266
iterator end()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:276
std::vector< C2DImageSeries > C2DImageSeriesGroup
Definition: 2d/image.hh:126
EPixelType
Definition: pixeltype.hh:32
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:261
T2DImage< int32_t > C2DSIImage
2D image with signed 32 bit integer values
Definition: 2d/image.hh:434
functor to copy an image into paointer representation
Definition: 2d/image.hh:410
T2DImage< double > C2DDImage
2D image with double precsion floating point values
Definition: 2d/image.hh:449
base class for all filer type functors.
Definition: core/filter.hh:70
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:138
class EXPORT_CORE CMeans private
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
A collection of attributes.
Definition: attributes.hh:255
T2DImage< float > C2DFImage
2D image with single precsion floating point values
Definition: 2d/image.hh:446
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:250
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:306
EXPORT_2D bool operator==(const C2DImage &a, const C2DImage &b)
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition: 2d/image.hh:392
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:291
reference operator[](size_t idx)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:246
#define EXPORT_2D
Definition: defines2d.hh:37
a 2D field of floating point single accuracy 2D vectors
iterator begin_at(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:286
iterator begin()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:271
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
T2DImage< uint32_t > C2DUIImage
2D image with unsigned 32 bit integer values
Definition: 2d/image.hh:437
std::shared_ptr< C2DImage > Pointer
2D Image pointer type
Definition: 2d/image.hh:57
static const char * data_descr
Definition: 2d/image.hh:51
const_reference operator[](size_t idx) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:241
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:89
const_reference operator()(const C2DBounds &l) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:251
C2DImage Super
define the super class of this class for generic processing
Definition: 2d/image.hh:141
reference operator()(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:236
T2DImage< uint8_t > C2DUBImage
2D image with unsigned 8 bit integer values
Definition: 2d/image.hh:425
T2DImage< int16_t > C2DSSImage
2D image with signed 16 bit integer values
Definition: 2d/image.hh:428
std::shared_ptr< C2DImageSeries > P2DImageSeries
Definition: 2d/image.hh:124
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:296
FConvert2DImageToPixeltypeO< float > FCopy2DImageToFloatRepn
short name for 2DImage to float pixel repn copy functor
Definition: 2d/image.hh:521
const_iterator begin_at(size_t x, size_t y) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:281
const C2DBounds & get_size() const
T2DImage< int64_t > C2DSLImage
2D image with signed 64 bit integer values
Definition: 2d/image.hh:440
T2DImage< uint64_t > C2DULImage
2D image with unsigned 64 bit integer values
Definition: 2d/image.hh:443
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:47
T2DImage< uint16_t > C2DUSImage
2D image with unsigned 16 bit integer values
Definition: 2d/image.hh:431
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:419
CAttributedData & operator=(const CAttributedData &org)
Assignemt operator.
a class to print out the intensity values of two images to compare them
Definition: 2d/image.hh:354
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:94
std::vector< P2DImage > C2DImageSeries
helper type for image series
Definition: 2d/image.hh:122
reference operator()(const C2DBounds &l)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:256
T x
first element
Definition: 2d/vector.hh:53
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36