2d/image.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_2d_2dimage_hh
#define mia_2d_2dimage_hh
#include <mia/core/attributes.hh>
#include <mia/core/pixeltype.hh>
#include <mia/core/filter.hh>
#include <mia/core/msgstream.hh>
#include <mia/core/tools.hh>
#include <mia/core/type_traits.hh>
#include <mia/2d/vectorfield.hh>
NS_MIA_BEGIN
#define ATTR_IMAGE_KMEANS_CLASSES "kmeans"
class EXPORT_2D C2DImage: public CAttributedData
{
public:
static const char *data_descr;
typedef C2DBounds dimsize_type;
typedef std::shared_ptr<C2DImage > Pointer;
virtual ~C2DImage();
EPixelType get_pixel_type() const;
const C2DBounds& get_size() const;
C2DFVector get_pixel_size() const;
void set_pixel_size(const C2DFVector& pixel);
C2DFVector get_origin() const;
void set_origin(const C2DFVector& origin);
virtual C2DImage *clone() const __attribute__((warn_unused_result)) = 0;
virtual std::pair<double, double> get_minmax_intensity() const = 0;
virtual void make_single_ref() __attribute__((deprecated)) = 0;
protected:
C2DImage(C2DImage&& other);
C2DImage& operator = (C2DImage&& other);
C2DImage(const C2DImage& other) = default;
C2DImage& operator = (const C2DImage& other) = default;
C2DImage(const C2DBounds& size, EPixelType type);
C2DImage(const CAttributedData& attributes, const C2DBounds& size, EPixelType type);
C2DImage();
private:
C2DBounds m_size;
EPixelType m_pixel_type;
};
typedef C2DImage::Pointer P2DImage;
typedef std::vector<P2DImage> C2DImageSeries;
typedef std::shared_ptr<C2DImageSeries> P2DImageSeries;
typedef std::vector<C2DImageSeries> C2DImageSeriesGroup;
typedef std::map<std::string, C2DImageSeriesGroup> C2DImageGroupedSeries;
template <typename T>
class EXPORT_2D T2DImage : public C2DImage
{
public:
typedef C2DImage Super;
typedef typename T2DDatafield<T>::iterator iterator;
typedef typename T2DDatafield<T>::const_iterator const_iterator;
typedef typename T2DDatafield<T>::const_reference const_reference;
typedef typename T2DDatafield<T>::reference reference;
typedef typename T2DDatafield<T>::const_pointer const_pointer;
typedef typename T2DDatafield<T>::pointer pointer;
typedef typename T2DDatafield<T>::value_type value_type;
typedef typename T2DDatafield<T>::difference_type difference_type;
typedef typename T2DDatafield<T>::size_type size_type;
typedef typename T2DDatafield<T>::range_iterator range_iterator;
typedef typename T2DDatafield<T>::const_range_iterator const_range_iterator;
typedef typename T2DDatafield<T>::range_iterator_with_boundary_flag range_iterator_with_boundary_flag;
typedef typename T2DDatafield<T>::const_range_iterator_with_boundary_flag const_range_iterator_with_boundary_flag;
typedef typename T2DDatafield<T>::data_array data_array;
T2DImage(const C2DBounds& size, const T *init_data);
T2DImage(const C2DBounds& size, const std::vector<T>& init_data);
T2DImage(const C2DBounds& size, const CAttributedData& attr);
T2DImage(const C2DBounds& size);
T2DImage(const T2DImage& orig);
T2DImage(T2DImage&& orig);
T2DImage<T>& operator = (T2DImage<T>&& orig);
T2DImage<T>& operator = (const T2DImage<T>& orig);
T2DImage(const T2DDatafield<T>& orig);
T2DImage(const T2DDatafield<T>& orig, const CAttributedData& attr);
T2DImage();
virtual C2DImage *clone() const __attribute__((warn_unused_result));
const_reference operator()(size_t x, size_t y) const
{
return m_image(x, y);
}
reference operator()(size_t x, size_t y)
{
return m_image(x, y);
}
const_reference operator[](size_t idx) const
{
return m_image[idx];
}
reference operator[](size_t idx)
{
return m_image[idx];
}
const_reference operator()(const C2DBounds& l) const
{
return m_image(l.x, l.y);
}
reference operator()(const C2DBounds& l)
{
return m_image(l.x, l.y);
}
const_iterator begin()const
{
return m_image.begin();
}
const_iterator end()const
{
return m_image.end();
}
iterator begin()
{
return m_image.begin();
}
iterator end()
{
return m_image.end();
}
const_iterator begin_at(size_t x, size_t y)const
{
return m_image.begin_at(x, y);
}
iterator begin_at(size_t x, size_t y)
{
return m_image.begin_at(x, y);
}
range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)
{
return m_image.begin_range(begin, end);
}
range_iterator end_range(const C2DBounds& begin, const C2DBounds& end)
{
return m_image.end_range(begin, end);
}
const_range_iterator begin_range(const C2DBounds& begin, const C2DBounds& end)const
{
return m_image.begin_range(begin, end);
}
const_range_iterator end_range(const C2DBounds& begin, const C2DBounds& end) const
{
return m_image.end_range(begin, end);
}
size_t size() const;
const T2DDatafield<T>& data() const;
void get_data_line_x(size_t y, std::vector<T>& buffer) const;
void get_data_line_y(size_t x, std::vector<T>& buffer) const;
void put_data_line_x(size_t y, const std::vector<T>& buffer);
void put_data_line_y(size_t x, const std::vector<T>& buffer);
C2DFVector get_gradient(size_t idx) const;
C2DFVector get_gradient(const C2DFVector& p) const;
std::pair<double, double> get_minmax_intensity() const;
void make_single_ref() __attribute__((deprecated));
private:
T2DDatafield<T> m_image;
};
class CImageComparePrinter: public TFilter<int>
{
public:
template <typename T, typename S>
int operator () (const T2DImage<T>& src, const T2DImage<S>& ref) const
{
typename T2DImage<T>::const_iterator si = src.begin();
typename T2DImage<T>::const_iterator se = src.end();
typename T2DImage<S>::const_iterator ri = ref.begin();
while (si != se)
cvdebug() << *si++ << " expect " << *ri++ << "\n";
return 0;
}
};
template <typename S>
struct plugin_data_type<T2DImage<S>> {
typedef C2DImage type;
};
EXPORT_2D bool operator == (const C2DImage& a, const C2DImage& b);
inline bool operator != (const C2DImage& a, const C2DImage& b)
{
return ! (a == b );
}
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage& image);
class CopyC2DImageToP2DImage
{
public:
template <typename T>
P2DImage operator () (const T2DImage<T>& image) const
{
return P2DImage(new T2DImage<T>(image));
}
};
typedef T2DImage<bool> C2DBitImage;
typedef T2DImage<int8_t> C2DSBImage;
typedef T2DImage<uint8_t> C2DUBImage;
typedef T2DImage<int16_t> C2DSSImage;
typedef T2DImage<uint16_t> C2DUSImage;
typedef T2DImage<int32_t> C2DSIImage;
typedef T2DImage<uint32_t> C2DUIImage;
typedef T2DImage<int64_t> C2DSLImage;
typedef T2DImage<uint64_t> C2DULImage;
typedef T2DImage<float> C2DFImage;
typedef T2DImage<double> C2DDImage;
template <>
struct Binder<C2DImage> {
typedef __bind_all<T2DImage> Derived;
};
//@endcond INTERNAL
template <typename O>
struct FConvert2DImageToPixeltypeO: public TFilter<T2DImage<O>> {
template <typename T>
T2DImage<O> operator () (const T2DImage<T>& image) const
{
T2DImage<O> result(image.get_size(), image);
copy(image.begin(), image.end(), result.begin());
return result;
}
T2DImage<O> operator () (const C2DImage& image) const
{
return filter(*this, image);
}
T2DImage<O> operator () (P2DImage image) const
{
return filter(*this, *image);
}
};
typedef FConvert2DImageToPixeltypeO<float> FCopy2DImageToFloatRepn;
NS_MIA_END
#endif
C2DUSImage
T2DImage< uint16_t > C2DUSImage
2D image with unsigned 16 bit integer values
Definition 2d/image.hh:454
C2DUBImage
T2DImage< uint8_t > C2DUBImage
2D image with unsigned 8 bit integer values
Definition 2d/image.hh:448
C2DSIImage
T2DImage< int32_t > C2DSIImage
2D image with signed 32 bit integer values
Definition 2d/image.hh:457
P2DImageSeries
std::shared_ptr< C2DImageSeries > P2DImageSeries
Definition 2d/image.hh:125
P2DImage
C2DImage::Pointer P2DImage
Shared pointer representation of the 2D Image.
Definition 2d/image.hh:120
FCopy2DImageToFloatRepn
FConvert2DImageToPixeltypeO< float > FCopy2DImageToFloatRepn
short name for 2DImage to float pixel repn copy functor
Definition 2d/image.hh:547
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
C2DFImage
T2DImage< float > C2DFImage
2D image with single precsion floating point values
Definition 2d/image.hh:469
get_gradient
EXPORT_2D C2DFVectorfield get_gradient(const C2DImage &image)
C2DImageSeriesGroup
std::vector< C2DImageSeries > C2DImageSeriesGroup
Definition 2d/image.hh:127
C2DSBImage
T2DImage< int8_t > C2DSBImage
2D image with signed 8 bit integer values
Definition 2d/image.hh:445
C2DImageSeries
std::vector< P2DImage > C2DImageSeries
helper type for image series
Definition 2d/image.hh:123
operator!=
bool operator!=(const C2DImage &a, const C2DImage &b)
Definition 2d/image.hh:413
C2DImageGroupedSeries
std::map< std::string, C2DImageSeriesGroup > C2DImageGroupedSeries
Definition 2d/image.hh:128
C2DUIImage
T2DImage< uint32_t > C2DUIImage
2D image with unsigned 32 bit integer values
Definition 2d/image.hh:460
C2DSLImage
T2DImage< int64_t > C2DSLImage
2D image with signed 64 bit integer values
Definition 2d/image.hh:463
C2DSSImage
T2DImage< int16_t > C2DSSImage
2D image with signed 16 bit integer values
Definition 2d/image.hh:451
C2DULImage
T2DImage< uint64_t > C2DULImage
2D image with unsigned 64 bit integer values
Definition 2d/image.hh:466
C2DBounds
T2DVector< unsigned int > C2DBounds
unsigned int valued 2D vector - used as 2D size parameter
Definition 2d/vector.hh:540
C2DFVector
T2DVector< float > C2DFVector
float valued 2D vector
Definition 2d/vector.hh:534
vectorfield.hh
attributes.hh
operator==
bool operator==(const CAttribute &a, const CAttribute &b)
Definition attributes.hh:95
C2DFVectorfield
a 2D field of floating point single accuracy 2D vectors
Definition 2d/vectorfield.hh:80
C2DImage
This is the base class for 2D images that can hold generic pixel data.
Definition 2d/image.hh:48
C2DImage::set_pixel_size
void set_pixel_size(const C2DFVector &pixel)
C2DImage::make_single_ref
virtual void make_single_ref() __attribute__((deprecated))=0
C2DImage::Pointer
std::shared_ptr< C2DImage > Pointer
2D Image pointer type
Definition 2d/image.hh:58
C2DImage::clone
virtual C2DImage * clone() const __attribute__((warn_unused_result))=0
C2DImage::C2DImage
C2DImage(C2DImage &&other)
C2DImage::~C2DImage
virtual ~C2DImage()
C2DImage::dimsize_type
C2DBounds dimsize_type
a definition of the image dimension type for
Definition 2d/image.hh:55
C2DImage::get_pixel_size
C2DFVector get_pixel_size() const
C2DImage::get_size
const C2DBounds & get_size() const
C2DImage::set_origin
void set_origin(const C2DFVector &origin)
C2DImage::get_origin
C2DFVector get_origin() const
C2DImage::get_pixel_type
EPixelType get_pixel_type() const
C2DImage::data_descr
static const char * data_descr
Definition 2d/image.hh:52
C2DImage::get_minmax_intensity
virtual std::pair< double, double > get_minmax_intensity() const =0
CAttributedData
A collection of attributes.
Definition attributes.hh:260
CAttributedData::CAttributedData
CAttributedData()
CAttributedData::operator=
CAttributedData & operator=(const CAttributedData &org)
Assignemt operator.
CImageComparePrinter
a class to print out the intensity values of two images to compare them
Definition 2d/image.hh:373
CopyC2DImageToP2DImage
functor to copy an image into paointer representation
Definition 2d/image.hh:432
type
T2DDatafield
A class to hold data on a regular 2D grid.
Definition 2d/datafield.hh:90
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
T2DDatafield::begin_range
range_iterator begin_range(const C2DBounds &begin, const C2DBounds &end)
T2DDatafield::end_range
range_iterator end_range(const C2DBounds &begin, const C2DBounds &end)
T2DImage
This is the template version of a 2D image that is used for holding real data.
Definition 2d/image.hh:140
T2DImage::Super
C2DImage Super
define the super class of this class for generic processing
Definition 2d/image.hh:143
T2DImage::begin
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:269
T2DImage::T2DImage
T2DImage()
T2DImage::clone
virtual C2DImage * clone() const __attribute__((warn_unused_result))
T2DImage::get_gradient
C2DFVector get_gradient(const C2DFVector &p) const
T2DImage::get_minmax_intensity
std::pair< double, double > get_minmax_intensity() const
T2DImage::operator[]
const_reference operator[](size_t idx) const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:245
T2DImage::T2DImage
T2DImage(const T2DDatafield< T > &orig)
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::T2DImage
T2DImage(const C2DBounds &size, const CAttributedData &attr)
T2DImage::T2DImage
T2DImage(const C2DBounds &size, const std::vector< T > &init_data)
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::data
const T2DDatafield< T > & data() const
get direct access to the data field
T2DImage::operator[]
reference operator[](size_t idx)
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:251
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
iterator begin()
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:281
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::operator()
const_reference operator()(const C2DBounds &l) const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:257
T2DImage::T2DImage
T2DImage(const T2DDatafield< T > &orig, const CAttributedData &attr)
T2DImage::end
iterator end()
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:287
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
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::end
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:275
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
T2DImage< bool >::size
size_t size() const
T2DImage::make_single_ref
void make_single_ref() __attribute__((deprecated))
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::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::T2DImage
T2DImage(const C2DBounds &size, const T *init_data)
T2DImage::T2DImage
T2DImage(const C2DBounds &size)
T2DImage::get_gradient
C2DFVector get_gradient(size_t idx) const
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::operator()
reference operator()(size_t x, size_t y)
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:239
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
T2DImage::T2DImage
T2DImage(T2DImage &&orig)
T2DVector::y
T y
second element
Definition 2d/vector.hh:57
T2DVector::x
T x
first element
Definition 2d/vector.hh:54
Pointer
const_iterator
TPluginHandler::end
const_iterator end() const
TPluginHandler::begin
const_iterator begin() const
filter.hh
EXPORT_2D
#define EXPORT_2D
Definition defines2d.hh:37
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
filter
static F::result_type filter(const F &f, const B &b)
Definition core/filter.hh:258
msgstream.hh
cvdebug
CDebugSink & cvdebug()
Definition msgstream.hh:226
std
Definition gsl_iterator.hh:324
pixeltype.hh
EPixelType
EPixelType
Definition pixeltype.hh:33
FConvert2DImageToPixeltypeO
functor to convert an image with an abitrary pixel type to single floating point pixels
Definition 2d/image.hh:502
TFilter
base class for all filer type functors.
Definition core/filter.hh:70
tools.hh
type_traits.hh