My Project
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 {
49 public:
52  static const char *data_descr;
53 
56 
58  typedef std::shared_ptr<C2DImage > Pointer;
59 
60  virtual ~C2DImage();
61 
64 
66  const C2DBounds& get_size() const;
67 
70 
72  void set_pixel_size(const C2DFVector& pixel);
73 
74 
77 
79  void set_origin(const C2DFVector& origin);
80 
85  virtual C2DImage *clone() const __attribute__((warn_unused_result)) = 0;
86 
87  virtual std::pair<double, double> get_minmax_intensity() const = 0;
88 
89  virtual void make_single_ref() __attribute__((deprecated)) = 0;
90 
91 protected:
92  C2DImage(C2DImage&& other);
93  C2DImage& operator = (C2DImage&& other);
94 
95  C2DImage(const C2DImage& other) = default;
96 
97 
98  C2DImage& operator = (const C2DImage& other) = default;
99 
100 
103  C2DImage(const C2DBounds& size, EPixelType type);
104 
107  C2DImage(const CAttributedData& attributes, const C2DBounds& size, EPixelType type);
108 
113 
114 private:
115  C2DBounds m_size;
116  EPixelType m_pixel_type;
117 };
118 
120 typedef C2DImage::Pointer P2DImage;
121 
123 typedef std::vector<P2DImage> C2DImageSeries;
124 
125 typedef std::shared_ptr<C2DImageSeries> P2DImageSeries;
126 
129 
130 
138 template <typename T>
140 {
141 public:
143  typedef C2DImage Super;
144 
146  typedef typename T2DDatafield<T>::iterator iterator;
147  typedef typename T2DDatafield<T>::const_iterator const_iterator;
148  typedef typename T2DDatafield<T>::const_reference const_reference;
149  typedef typename T2DDatafield<T>::reference reference;
150  typedef typename T2DDatafield<T>::const_pointer const_pointer;
151  typedef typename T2DDatafield<T>::pointer pointer;
152  typedef typename T2DDatafield<T>::value_type value_type;
153  typedef typename T2DDatafield<T>::difference_type difference_type;
154  typedef typename T2DDatafield<T>::size_type size_type;
155  typedef typename T2DDatafield<T>::range_iterator range_iterator;
156  typedef typename T2DDatafield<T>::const_range_iterator const_range_iterator;
157  typedef typename T2DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
158  typedef typename T2DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
159 
160  typedef typename T2DDatafield<T>::data_array data_array;
161 
163 
169  T2DImage(const C2DBounds& size, const T *init_data);
170 
176  T2DImage(const C2DBounds& size, const std::vector<T>& init_data);
182  T2DImage(const C2DBounds& size, const CAttributedData& attr);
183 
188  T2DImage(const C2DBounds& size);
189 
193  T2DImage(const T2DImage& orig);
194 
199 
204 
205 
210 
211 
216  T2DImage(const T2DDatafield<T>& orig);
217 
223  T2DImage(const T2DDatafield<T>& orig, const CAttributedData& attr);
224 
226 
230  virtual C2DImage *clone() const __attribute__((warn_unused_result));
231 
233  const_reference operator()(size_t x, size_t y) const
234  {
235  return m_image(x, y);
236  }
237 
239  reference operator()(size_t x, size_t y)
240  {
241  return m_image(x, y);
242  }
243 
245  const_reference operator[](size_t idx) const
246  {
247  return m_image[idx];
248  }
249 
251  reference operator[](size_t idx)
252  {
253  return m_image[idx];
254  }
255 
257  const_reference operator()(const C2DBounds& l) const
258  {
259  return m_image(l.x, l.y);
260  }
261 
263  reference operator()(const C2DBounds& l)
264  {
265  return m_image(l.x, l.y);
266  }
267 
269  const_iterator begin()const
270  {
271  return m_image.begin();
272  }
273 
275  const_iterator end()const
276  {
277  return m_image.end();
278  }
279 
281  iterator begin()
282  {
283  return m_image.begin();
284  }
285 
287  iterator end()
288  {
289  return m_image.end();
290  }
291 
293  const_iterator begin_at(size_t x, size_t y)const
294  {
295  return m_image.begin_at(x, y);
296  }
297 
299  iterator begin_at(size_t x, size_t y)
300  {
301  return m_image.begin_at(x, y);
302  }
303 
305  range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)
306  {
307  return m_image.begin_range(begin, end);
308  }
309 
311  range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)
312  {
313  return m_image.end_range(begin, end);
314  }
315 
317  const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const
318  {
319  return m_image.begin_range(begin, end);
320  }
321 
323  const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end) const
324  {
325  return m_image.end_range(begin, end);
326  }
327 
329  size_t size() const;
330 
332  const T2DDatafield<T>& data() const;
333 
335  void get_data_line_x(size_t y, std::vector<T>& buffer) const;
336 
338  void get_data_line_y(size_t x, std::vector<T>& buffer) const;
339 
341  void put_data_line_x(size_t y, const std::vector<T>& buffer);
342 
344  void put_data_line_y(size_t x, const std::vector<T>& buffer);
345 
351  C2DFVector get_gradient(size_t idx) const;
352 
359 
361  std::pair<double, double> get_minmax_intensity() const;
362 
363  void make_single_ref() __attribute__((deprecated));
364 private:
365  T2DDatafield<T> m_image;
366 };
367 
372 class CImageComparePrinter: public TFilter<int>
373 {
374 public:
375  template <typename T, typename S>
376  int operator () (const T2DImage<T>& src, const T2DImage<S>& ref) const
377  {
378  typename T2DImage<T>::const_iterator si = src.begin();
379  typename T2DImage<T>::const_iterator se = src.end();
380  typename T2DImage<S>::const_iterator ri = ref.begin();
381 
382  while (si != se)
383  cvdebug() << *si++ << " expect " << *ri++ << "\n";
384 
385  return 0;
386  }
387 };
388 
392 template <typename S>
393 struct plugin_data_type<T2DImage<S>> {
394  typedef C2DImage type;
395 };
397 
407 EXPORT_2D bool operator == (const C2DImage& a, const C2DImage& b);
408 
413 inline bool operator != (const C2DImage& a, const C2DImage& b)
414 {
415  return ! (a == b );
416 }
417 
418 
424 
432 {
433 public:
434  template <typename T>
435  P2DImage operator () (const T2DImage<T>& image) const
436  {
437  return P2DImage(new T2DImage<T>(image));
438  }
439 };
440 
443 
446 
449 
452 
455 
458 
461 
464 
467 
470 
473 
482 template <>
483 struct Binder<C2DImage> {
485  typedef __bind_all<T2DImage> Derived;
486 };
487 
488 //@endcond INTERNAL
489 
501 template <typename O>
502 struct FConvert2DImageToPixeltypeO: public TFilter<T2DImage<O>> {
503 
509  template <typename T>
510  T2DImage<O> operator () (const T2DImage<T>& image) const
511  {
512  T2DImage<O> result(image.get_size(), image);
513  copy(image.begin(), image.end(), result.begin());
514  return result;
515  }
516 
523  T2DImage<O> operator () (const C2DImage& image) const
524  {
525  return filter(*this, image);
526  }
527 
534  T2DImage<O> operator () (P2DImage image) const
535  {
536  return filter(*this, *image);
537  }
538 };
539 
540 
548 
549 
551 
552 #endif
C2DULImage
T2DImage< uint64_t > C2DULImage
2D image with unsigned 64 bit integer values
Definition: 2d/image.hh:466
T2DVector::y
T y
second element
Definition: 2d/vector.hh:57
C2DUSImage
T2DImage< uint16_t > C2DUSImage
2D image with unsigned 16 bit integer values
Definition: 2d/image.hh:454
T2DImage::T2DImage
T2DImage(const T2DDatafield< T > &orig, const CAttributedData &attr)
P2DImageSeries
std::shared_ptr< C2DImageSeries > P2DImageSeries
Definition: 2d/image.hh:125
T2DImage::size
size_t size() const
forwarding function to access the underlying T2DDatafield
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
C2DImage::get_origin
C2DFVector get_origin() const
T2DVector::x
T x
first element
Definition: 2d/vector.hh:54
tools.hh
get_gradient
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
T2DImage::get_data_line_y
void get_data_line_y(size_t x, std::vector< T > &buffer) const
forwarding function to access the underlying T2DDatafield
T2DImage::T2DImage
T2DImage(const C2DBounds &size, const T *init_data)
T2DImage::T2DImage
T2DImage(const T2DDatafield< T > &orig)
T2DDatafield::data_array
::std::vector< typename __holder_type_dispatch< T >::type > data_array
type for the flat reprentation of the 2D data field
Definition: 2d/datafield.hh:95
FCopy2DImageToFloatRepn
FConvert2DImageToPixeltypeO< float > FCopy2DImageToFloatRepn
short name for 2DImage to float pixel repn copy functor
Definition: 2d/image.hh:547
T2DImage::operator[]
reference operator[](size_t idx)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:251
CImageComparePrinter
a class to print out the intensity values of two images to compare them
Definition: 2d/image.hh:373
FConvert2DImageToPixeltypeO
functor to convert an image with an abitrary pixel type to single floating point pixels
Definition: 2d/image.hh:502
T2DImage::end_range
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:323
operator!=
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition: 2d/image.hh:413
C2DImage
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:48
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
TFilter
base class for all filer type functors.
Definition: core/filter.hh:70
T2DImage::T2DImage
T2DImage(T2DImage &&orig)
C2DImage::clone
virtual C2DImage * clone() const __attribute__((warn_unused_result))=0
T2DImage::get_data_line_x
void get_data_line_x(size_t y, std::vector< T > &buffer) const
forwarding function to access the underlying T2DDatafield
T2DImage::begin
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:269
C2DFImage
T2DImage< float > C2DFImage
2D image with single precsion floating point values
Definition: 2d/image.hh:469
P2DImage
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:120
T2DVector< unsigned int >
filter
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:258
T2DImage::end
iterator end()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:287
C2DImage::set_pixel_size
void set_pixel_size(const C2DFVector &pixel)
msgstream.hh
C2DImageSeriesGroup
std::vector< C2DImageSeries > C2DImageSeriesGroup
Definition: 2d/image.hh:127
operator==
EXPORT_2D bool operator==(const C2DImage &a, const C2DImage &b)
T2DImage::get_gradient
C2DFVector get_gradient(const C2DFVector &p) const
cvdebug
CDebugSink & cvdebug()
Definition: msgstream.hh:226
T2DImage::begin_range
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:317
T2DImage::get_gradient
C2DFVector get_gradient(size_t idx) const
C2DImage::set_origin
void set_origin(const C2DFVector &origin)
CAttributedData::operator=
CAttributedData & operator=(const CAttributedData &org)
Assignemt operator.
T2DImage::operator()
const_reference operator()(const C2DBounds &l) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:257
C2DDImage
T2DImage< double > C2DDImage
2D image with double precsion floating point values
Definition: 2d/image.hh:472
C2DBitImage
T2DImage< bool > C2DBitImage
2D image with binary values
Definition: 2d/image.hh:442
C2DSLImage
T2DImage< int64_t > C2DSLImage
2D image with signed 64 bit integer values
Definition: 2d/image.hh:463
CAttributedData
A collection of attributes.
Definition: attributes.hh:260
T2DImage::operator[]
const_reference operator[](size_t idx) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:245
T2DImage::operator()
reference operator()(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:239
T2DImage::put_data_line_x
void put_data_line_x(size_t y, const std::vector< T > &buffer)
forwarding function to access the underlying T2DDatafield
T2DImage::get_minmax_intensity
std::pair< double, double > get_minmax_intensity() const
C2DImage::get_pixel_size
C2DFVector get_pixel_size() const
T2DImage::begin
iterator begin()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:281
T2DImage::clone
virtual C2DImage * clone() const __attribute__((warn_unused_result))
C2DImage::~C2DImage
virtual ~C2DImage()
T2DImage::begin_range
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:305
C2DSBImage
T2DImage< int8_t > C2DSBImage
2D image with signed 8 bit integer values
Definition: 2d/image.hh:445
C2DSIImage
T2DImage< int32_t > C2DSIImage
2D image with signed 32 bit integer values
Definition: 2d/image.hh:457
T2DImage::T2DImage
T2DImage(const C2DBounds &size)
attributes.hh
C2DImage::Pointer
std::shared_ptr< C2DImage > Pointer
2D Image pointer type
Definition: 2d/image.hh:58
C2DImage::data_descr
static const char * data_descr
Definition: 2d/image.hh:52
C2DUBImage
T2DImage< uint8_t > C2DUBImage
2D image with unsigned 8 bit integer values
Definition: 2d/image.hh:448
C2DImageGroupedSeries
std::map< std::string, C2DImageSeriesGroup > C2DImageGroupedSeries
Definition: 2d/image.hh:128
C2DFVectorfield
a 2D field of floating point single accuracy 2D vectors
Definition: 2d/vectorfield.hh:80
C2DImage::get_pixel_type
EPixelType get_pixel_type() const
C2DSSImage
T2DImage< int16_t > C2DSSImage
2D image with signed 16 bit integer values
Definition: 2d/image.hh:451
T2DDatafield
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:90
std
Definition: gsl_iterator.hh:324
T2DImage::T2DImage
T2DImage(const C2DBounds &size, const std::vector< T > &init_data)
T2DImage::make_single_ref
void make_single_ref() __attribute__((deprecated))
T2DImage::begin_at
iterator begin_at(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:299
T2DImage::T2DImage
T2DImage(const T2DImage &orig)
T2DImage::operator()
reference operator()(const C2DBounds &l)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:263
T2DImage::put_data_line_y
void put_data_line_y(size_t x, const std::vector< T > &buffer)
forwarding function to access the underlying T2DDatafield
T2DImage::Super
C2DImage Super
define the super class of this class for generic processing
Definition: 2d/image.hh:143
C2DImageSeries
std::vector< P2DImage > C2DImageSeries
helper type for image series
Definition: 2d/image.hh:123
EPixelType
EPixelType
Definition: pixeltype.hh:32
T2DImage
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:140
T2DImage::T2DImage
T2DImage(const C2DBounds &size, const CAttributedData &attr)
private
class EXPORT_CORE CMeans private
C2DImage::dimsize_type
C2DBounds dimsize_type
a definition of the image dimension type for
Definition: 2d/image.hh:55
CopyC2DImageToP2DImage
functor to copy an image into paointer representation
Definition: 2d/image.hh:432
T2DImage::T2DImage
T2DImage()
type_traits.hh
C2DImage::get_size
const C2DBounds & get_size() const
vectorfield.hh
filter.hh
T2DImage::end_range
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:311
EXPORT_2D
#define EXPORT_2D
Definition: defines2d.hh:37
C2DUIImage
T2DImage< uint32_t > C2DUIImage
2D image with unsigned 32 bit integer values
Definition: 2d/image.hh:460
T2DImage::begin_at
const_iterator begin_at(size_t x, size_t y) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:293
T2DImage::end
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:275
T2DImage::data
const T2DDatafield< T > & data() const
get direct access to the data field
pixeltype.hh