Template Class Image

Inheritance Relationships

Base Type

  • public cv::Mat

Class Documentation

template<typename T, int l>
class Image : public cv::Mat

Base class for image data used in 3D image processing.

The lib3d::types::Image class provides a more convenient and consistent use of cv::Mat. It is templated with a typename T and a number of channels l (layers). It subclasses cv::Mat.

A number of manifistations, which are key to the lib3D and 3D processing, are predefined with a fixed datatype and a fixed number of channels:

  • ColorImage: three-channel RGB image with pixel data of type uchar. Content string: ‘RGB’

  • GrayscaleImage: single-channel grayscale image with pixel data of type uchar. Content string: ‘Luminance’

  • DepthMap: single-channel image with pixel data of type float. Content string: ‘Depth’

  • DDepthMap: single-channel image with pixel data of type double. Content string: ‘Depth’

  • DisparityMap: single-channel image with pixel data of type float. Content string: ‘Disparity’

  • DDisparityMap: single-channel image with pixel data of type double. Content string: ‘Disparity’

  • ConfidenceMap: single-channel image with pixel data of type float. Content string: ‘Confidence’

  • DConfidenceMap: single-channel image with pixel data of type double. Content string: ‘Confidence’

  • NormalMap: three-channel image with pixel data of type float. Content string: ‘Normal’

  • DNormalMap: three-channel image with pixel data of type double. Content string: ‘Normal’

Note: The content string of the generic lib3d::types::Image class will be initialized with ‘Image’. This can be changed with setContentStr().

The lib3d::types::Image class can be used in the same way as cv::Mat. However, the member function valueAt() provides a ‘type-aware’ access to the image data. In this, the data can be indexed by either passing the x, y and c (channel) coordiantes separately, or by passing a cv::Point2i or cv::Point3i. Dependent on the number of channels the data can be accessed with a two-fold (i.e. x-y or cv::Point2i) or a three-fold (i.e. x-y-c or cv::Point3i) index.

Note: When passing the indices separately, the horizontal index (x) comes before the vertical index (y). This is different to using cv::Mat::at() but provides a more intuitive interface.

An instance of a cv::Mat can directly be assigned to lib3d::types::Image, by emplyoing the Image::operator=(const Mat& m) function. This is particularly needed for using functions returning a cv::Mat, e.g. cv::imread().

Note: In the Image::operator=(const Mat& m) function it is evaluated whether the type of the passed cv::Mat corresponds to the type of the Image instance. If this is not the case, the cv::Mat is not assigned to the lib3d::types::Image.

Template Parameters:
  • T – Type name of pixel data (e.g. uchar, float, …).

  • l – Number of channels (layers) inside the image.

Public Functions

inline Image()

Default constructor.

inline Image(const std::string iContentStr)

Zero initialization constructor creating an empty image.

inline Image(const int &iWidth, const int &iHeight, const std::string iContentStr = "Image")

Class constructor creating a zero-initialized image of size iWidth \(\times\) iHeight.

inline Image(const cv::Size &iSize, const std::string iContentStr = "Image")

Class constructor creating a zero-initialized image of size iSize.

inline virtual ~Image()

Destructor.

inline Image &operator=(const Mat &m)

Assignment operator allowing to assign an instance of cv::Mat to an instance of lib3d::types::Image.

Note

In this, it is evaluated whether the type of the passed cv::Mat corresponds to the type of the image instance. If this is not the case, the image object is kept unchanged.

template<int ch = l>
inline std::enable_if<(ch == 1), T&>::type valueAt(int x, int y)

Various methods providing easy access to the pixel data. Depending on the datatype and the channel number of the image the parameters and the return value differ.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

Returns:

Reference of type T if the Image has 1 channel.

template<int ch = l>
inline std::enable_if<(ch == 1), constT&>::type valueAt(int x, int y) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

Returns:

Const reference of type T if the Image has 1 channel.

template<int ch = l>
inline std::enable_if<(ch > 1), cv::Vec<T, ch>&>::type valueAt(int x, int y)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

Returns:

Reference of a l-dimensional cv::Vec of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), constcv::Vec<T, ch>&>::type valueAt(int x, int y) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

Returns:

Const reference of a l-dimensional cv::Vec of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), T&>::type valueAt(int x, int y, int c)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

  • c[in] Channel of the pixel to access.

Returns:

Reference of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), constT&>::type valueAt(int x, int y, int c) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x[in] X-coordinate of the pixel to access.

  • y[in] Y-coordinate of the pixel to access.

  • c[in] Channel of the pixel to access.

Returns:

Const reference of type T.

template<int ch = l>
inline std::enable_if<(ch == 1), T&>::type valueAt(cv::Point2i px)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 2D-Coordinate of the pixel to access.

Returns:

Reference of type T if the Image has 1 channel.

template<int ch = l>
inline std::enable_if<(ch == 1), constT&>::type valueAt(cv::Point2i px) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 2D-Coordinate of the pixel to access.

Returns:

Const reference of type T if the Image has 1 channel.

template<int ch = l>
inline std::enable_if<(ch > 1), cv::Vec<T, ch>&>::type valueAt(cv::Point2i px)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 2D-Coordinate of the pixel to access.

Returns:

Reference of a l-dimensional cv::Vec of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), constcv::Vec<T, ch>&>::type valueAt(cv::Point2i px) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 2D-Coordinate of the pixel to access.

Returns:

Const reference of a l-dimensional cv::Vec of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), T&>::type valueAt(cv::Point3i px)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 3D-Coordinate of the pixel to access.

Returns:

Reference of type T.

template<int ch = l>
inline std::enable_if<(ch > 1), constT&>::type valueAt(cv::Point3i px) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

px[in] 3D-Coordinate of the pixel to access.

Returns:

Const reference of type T.

inline std::string contentStr() const

Returns a string that classifys the content of the image.

inline void setContentStr(const std::string &iContentStr)

Set content string which classifying the content of the image.

Protected Attributes

std::string mContentStr

String to classify the content of the image.