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
26#include <mia/core/pixeltype.hh>
27#include <mia/core/filter.hh>
28#include <mia/core/msgstream.hh>
29#include <mia/core/tools.hh>
31#include <mia/2d/vectorfield.hh>
32
34
35#define ATTR_IMAGE_KMEANS_CLASSES "kmeans"
36
37
48{
49public:
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
91protected:
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
114private:
115 C2DBounds m_size;
116 EPixelType m_pixel_type;
117};
118
120typedef C2DImage::Pointer P2DImage;
121
123typedef std::vector<P2DImage> C2DImageSeries;
124
125typedef std::shared_ptr<C2DImageSeries> P2DImageSeries;
126
129
130
138template <typename T>
140{
141public:
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
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));
364private:
365 T2DDatafield<T> m_image;
366};
367
373{
374public:
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
392template <typename S>
393struct plugin_data_type<T2DImage<S>> {
394 typedef C2DImage type;
395};
397
407EXPORT_2D bool operator == (const C2DImage& a, const C2DImage& b);
408
413inline bool operator != (const C2DImage& a, const C2DImage& b)
414{
415 return ! (a == b );
416}
417
418
424
432{
433public:
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
482template <>
483struct Binder<C2DImage> {
485 typedef __bind_all<T2DImage> Derived;
486};
487
488//@endcond INTERNAL
489
501template <typename O>
502struct 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
T2DImage< uint16_t > C2DUSImage
2D image with unsigned 16 bit integer values
Definition: 2d/image.hh:454
T2DImage< uint8_t > C2DUBImage
2D image with unsigned 8 bit integer values
Definition: 2d/image.hh:448
T2DImage< int32_t > C2DSIImage
2D image with signed 32 bit integer values
Definition: 2d/image.hh:457
std::shared_ptr< C2DImageSeries > P2DImageSeries
Definition: 2d/image.hh:125
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition: 2d/image.hh:120
FConvert2DImageToPixeltypeO< float > FCopy2DImageToFloatRepn
short name for 2DImage to float pixel repn copy functor
Definition: 2d/image.hh:547
T2DImage< double > C2DDImage
2D image with double precsion floating point values
Definition: 2d/image.hh:472
T2DImage< bool > C2DBitImage
2D image with binary values
Definition: 2d/image.hh:442
T2DImage< float > C2DFImage
2D image with single precsion floating point values
Definition: 2d/image.hh:469
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
std::vector< C2DImageSeries > C2DImageSeriesGroup
Definition: 2d/image.hh:127
T2DImage< int8_t > C2DSBImage
2D image with signed 8 bit integer values
Definition: 2d/image.hh:445
std::vector< P2DImage > C2DImageSeries
helper type for image series
Definition: 2d/image.hh:123
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition: 2d/image.hh:413
EXPORT_2D bool operator==(const C2DImage &a, const C2DImage &b)
std::map< std::string, C2DImageSeriesGroup > C2DImageGroupedSeries
Definition: 2d/image.hh:128
T2DImage< uint32_t > C2DUIImage
2D image with unsigned 32 bit integer values
Definition: 2d/image.hh:460
T2DImage< int64_t > C2DSLImage
2D image with signed 64 bit integer values
Definition: 2d/image.hh:463
T2DImage< int16_t > C2DSSImage
2D image with signed 16 bit integer values
Definition: 2d/image.hh:451
T2DImage< uint64_t > C2DULImage
2D image with unsigned 64 bit integer values
Definition: 2d/image.hh:466
a 2D field of floating point single accuracy 2D vectors
This is the base class for 2D images that can hold generic pixel data.
Definition: 2d/image.hh:48
void set_pixel_size(const C2DFVector &pixel)
std::shared_ptr< C2DImage > Pointer
2D Image pointer type
Definition: 2d/image.hh:58
virtual C2DImage * clone() const __attribute__((warn_unused_result))=0
virtual ~C2DImage()
C2DBounds dimsize_type
a definition of the image dimension type for
Definition: 2d/image.hh:55
C2DFVector get_pixel_size() const
const C2DBounds & get_size() const
void set_origin(const C2DFVector &origin)
C2DFVector get_origin() const
EPixelType get_pixel_type() const
static const char * data_descr
Definition: 2d/image.hh:52
A collection of attributes.
Definition: attributes.hh:260
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:373
functor to copy an image into paointer representation
Definition: 2d/image.hh:432
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:90
::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
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:140
C2DImage Super
define the super class of this class for generic processing
Definition: 2d/image.hh:143
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:269
virtual C2DImage * clone() const __attribute__((warn_unused_result))
C2DFVector get_gradient(const C2DFVector &p) const
std::pair< double, double > get_minmax_intensity() const
const_reference operator[](size_t idx) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:245
T2DImage(const T2DDatafield< T > &orig)
const_iterator begin_at(size_t x, size_t y) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:293
T2DImage(const C2DBounds &size, const CAttributedData &attr)
T2DImage(const C2DBounds &size, const std::vector< T > &init_data)
void put_data_line_x(size_t y, const std::vector< T > &buffer)
forwarding function to access the underlying T2DDatafield
const T2DDatafield< T > & data() const
get direct access to the data field
reference operator[](size_t idx)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:251
void get_data_line_x(size_t y, std::vector< T > &buffer) const
forwarding function to access the underlying T2DDatafield
iterator begin()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:281
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
const_reference operator()(const C2DBounds &l) const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:257
T2DImage(const T2DDatafield< T > &orig, const CAttributedData &attr)
iterator end()
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:287
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
void get_data_line_y(size_t x, std::vector< T > &buffer) const
forwarding function to access the underlying T2DDatafield
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:275
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
size_t size() const
forwarding function to access the underlying T2DDatafield
void make_single_ref() __attribute__((deprecated))
void put_data_line_y(size_t x, const std::vector< T > &buffer)
forwarding function to access the underlying T2DDatafield
T2DImage(const T2DImage &orig)
reference operator()(const C2DBounds &l)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:263
T2DImage(const C2DBounds &size, const T *init_data)
T2DImage(const C2DBounds &size)
C2DFVector get_gradient(size_t idx) const
iterator begin_at(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:299
reference operator()(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:239
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
T2DImage(T2DImage &&orig)
T y
second element
Definition: 2d/vector.hh:57
T x
first element
Definition: 2d/vector.hh:54
#define EXPORT_2D
Definition: defines2d.hh:37
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
static F::result_type filter(const F &f, const B &b)
Definition: core/filter.hh:258
CDebugSink & cvdebug()
Definition: msgstream.hh:226
EPixelType
Definition: pixeltype.hh:32
functor to convert an image with an abitrary pixel type to single floating point pixels
Definition: 2d/image.hh:502
base class for all filer type functors.
Definition: core/filter.hh:70