Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
ecvl::Image Class Reference

Image class. More...

#include <image.h>

Inheritance diagram for ecvl::Image:
ecvl::ConstContiguousView< DT > ecvl::ConstContiguousViewXYC< DT > ecvl::ConstView< DT > ecvl::ContiguousView< DT > ecvl::ContiguousViewXYC< DT > ecvl::View< DT >

Public Member Functions

template<typename T >
Iterator< T > Begin ()
 Generic non-const Begin Iterator. More...
 
template<typename T >
Iterator< T > End ()
 Generic non-const End Iterator. More...
 
template<typename T >
ConstIterator< T > Begin () const
 Generic const Begin Iterator. More...
 
template<typename T >
ConstIterator< T > End () const
 Generic const End Iterator. More...
 
template<typename T >
ContiguousIterator< T > ContiguousBegin ()
 Contiguous non-const Begin Iterator. More...
 
template<typename T >
ContiguousIterator< T > ContiguousEnd ()
 Contiguous non-const End Iterator. More...
 
template<typename T >
ConstContiguousIterator< T > ContiguousBegin () const
 Contiguous const Begin Iterator. More...
 
template<typename T >
ConstContiguousIterator< T > ContiguousEnd () const
 Contiguous const End Iterator. More...
 
 Image ()
 Default constructor. More...
 
 Image (const std::vector< int > &dims, DataType elemtype, std::string channels, ColorType colortype, const std::vector< float > &spacings=std::vector< float >(), Device dev=Device::CPU)
 Initializing constructor. More...
 
 Image (const Image &img)
 Copy constructor. More...
 
 Image (Image &&img)
 Move constructor. More...
 
Imageoperator= (const Image &rhs)
 
Imageoperator= (Image &&rhs)
 
void To (Device dev)
 
void Create (const std::vector< int > &dims, DataType elemtype, std::string channels, ColorType colortype, const std::vector< float > &spacings=std::vector< float >(), Device dev=Device::CPU)
 Allocates new contiguous data if needed. More...
 
 ~Image ()
 Destructor. More...
 
bool IsEmpty () const
 To check whether the Image contains data or not, regardless of the owning status. More...
 
bool IsOwner () const
 To check whether the Image is owner of the data. More...
 
int Channels () const
 Returns the number of channels. More...
 
int Width () const
 Returns the width of Image. More...
 
int Height () const
 Returns the height of Image. More...
 
uint8_t * Ptr (const std::vector< int > &coords)
 Returns a non-const pointer to data at given coordinates. More...
 
const uint8_t * Ptr (const std::vector< int > &coords) const
 Returns a const pointer to data at given coordinates. More...
 
void Neg ()
 In-place negation. More...
 
template<typename T >
void Add (const T &rhs, bool saturate=true)
 In-place addition. More...
 
template<typename T >
void Sub (const T &rhs, bool saturate=true)
 In-place subtraction. More...
 
template<typename T >
void Mul (const T &rhs, bool saturate=true)
 In-place multiplication. More...
 
template<typename T >
void Div (const T &rhs, bool saturate=true)
 In-place division. More...
 
template<typename T >
void SetTo (T value)
 Set Image value to rhs. More...
 
void ConvertTo (DataType dtype, bool saturate=true)
 Convert Image to another DataType. More...
 
Image operator- () const
 
Imageoperator+= (const Image &rhs)
 
Imageoperator-= (const Image &rhs)
 
Imageoperator *= (const Image &rhs)
 
Imageoperator/= (const Image &rhs)
 

Public Attributes

DataType elemtype_
 Type of Image pixels, must be one of the values available in DataType. More...
 
uint8_t elemsize_
 Size (in bytes) of Image pixels. More...
 
std::vector< int > dims_
 
std::vector< int > strides_
 Vector of Image strides. More...
 
std::string channels_
 String which describes how Image planes are organized. More...
 
ColorType colortype_
 Image ColorType. More...
 
std::vector< float > spacings_
 Space between pixels/voxels. More...
 
uint8_t * data_
 Pointer to Image data. More...
 
size_t datasize_
 Size of Image data in bytes. More...
 
bool contiguous_
 Whether the image is stored contiguously or not in memory. More...
 
MetaDatameta_
 Pointer to Image MetaData. More...
 
HardwareAbstractionLayerhal_
 Pointer to the HardwareAbstractionLayer employed by the Image. More...
 
Device dev_
 Identifier for the device on which the image data is. More...
 

Protected Member Functions

void SetDefaultStrides ()
 Sets default strides for contiguous memory layouts. More...
 
size_t GetDefaultDatasize ()
 Gets the default datasize for contiguous images. More...
 
void SetDefaultDatasize ()
 Sets the default datasize for contiguous images. More...
 

Friends

class HardwareAbstractionLayer
 
void swap (Image &lhs, Image &rhs)
 
Image operator+ (Image lhs, const Image &rhs)
 
Image operator- (Image lhs, const Image &rhs)
 
Image operator * (Image lhs, const Image &rhs)
 
Image operator/ (Image lhs, const Image &rhs)
 

Detailed Description

Image class.

Examples
example_core_iterators.cpp, example_ecvl_eddl.cpp, example_ecvl_gui.cpp, example_image_view.cpp, example_imgcodecs.cpp, example_imgproc.cpp, example_moments.cpp, example_nifti_dicom.cpp, example_openslide.cpp, and example_threshold.cpp.

Definition at line 72 of file image.h.

Constructor & Destructor Documentation

◆ Image() [1/4]

ecvl::Image::Image ( )
inline

Default constructor.

The default constructor creates an empty image without any data.

Definition at line 263 of file image.h.

◆ Image() [2/4]

ecvl::Image::Image ( const std::vector< int > &  dims,
DataType  elemtype,
std::string  channels,
ColorType  colortype,
const std::vector< float > &  spacings = std::vector<float>(),
Device  dev = Device::CPU 
)
inline

Initializing constructor.

The initializing constructor creates a proper image and allocates the data.

Definition at line 284 of file image.h.

◆ Image() [3/4]

ecvl::Image::Image ( const Image img)
inline

Copy constructor.

The copy constructor creates an new Image copying (Deep Copy) the input one. The new Image will be contiguous regardless of the contiguity of the to be copied Image.

Definition at line 312 of file image.h.

◆ Image() [4/4]

ecvl::Image::Image ( Image &&  img)
inline

Move constructor.

Move constructor

Definition at line 334 of file image.h.

◆ ~Image()

ecvl::Image::~Image ( )
inline

Destructor.

If the Image is the owner of data they will be deallocate. Otherwise nothing will happen.

Definition at line 447 of file image.h.

Member Function Documentation

◆ Add()

template<typename T >
void ecvl::Image::Add ( const T &  rhs,
bool  saturate = true 
)
inline

In-place addition.

Definition at line 523 of file image.h.

◆ Begin() [1/2]

template<typename T >
Iterator<T> ecvl::Image::Begin ( )
inline

Generic non-const Begin Iterator.

This function gives you a non-const generic Begin Iterator that can be used both for contiguous and non-contiguous non-const Images. It is useful to iterate over a non-const Image. If the Image is contiguous prefer the use of ContiguousIterato which in most cases improve the performance.

Examples
example_ecvl_gui.cpp, and example_imgproc.cpp.

Definition at line 199 of file image.h.

◆ Begin() [2/2]

template<typename T >
ConstIterator<T> ecvl::Image::Begin ( ) const
inline

Generic const Begin Iterator.

This function gives you a const generic Begin Iterator that can be used both for contiguous and non-contiguous const Images. It is useful to iterate over a const Image. If the Image is contiguous prefer the use of ConstContiguousIterator which in most cases improve the performance.

Definition at line 216 of file image.h.

◆ Channels()

int ecvl::Image::Channels ( ) const
inline

Returns the number of channels.

Definition at line 465 of file image.h.

◆ ContiguousBegin() [1/2]

template<typename T >
ContiguousIterator<T> ecvl::Image::ContiguousBegin ( )
inline

Contiguous non-const Begin Iterator.

This function gives you a contiguous non-const Begin Iterator that can be used only for contiguous Images. If the Image is contiguous it is preferable to the non-contiguous iterator since it has usually better performance.

Examples
example_core_iterators.cpp.

Definition at line 233 of file image.h.

◆ ContiguousBegin() [2/2]

template<typename T >
ConstContiguousIterator<T> ecvl::Image::ContiguousBegin ( ) const
inline

Contiguous const Begin Iterator.

This function gives you a contiguous const Begin Iterator that can be used only for contiguous Images. If the Image is contiguous it is preferable to the non-contiguous iterator since it has usually better performance.

Definition at line 250 of file image.h.

◆ ContiguousEnd() [1/2]

template<typename T >
ContiguousIterator<T> ecvl::Image::ContiguousEnd ( )
inline

Contiguous non-const End Iterator.

This function gives you a contiguous non-const End Iterator that can be used only for contiguous Images.

Examples
example_core_iterators.cpp.

Definition at line 241 of file image.h.

◆ ContiguousEnd() [2/2]

template<typename T >
ConstContiguousIterator<T> ecvl::Image::ContiguousEnd ( ) const
inline

Contiguous const End Iterator.

This function gives you a contiguous const End Iterator that can be used only for contiguous Images.

Definition at line 257 of file image.h.

◆ ConvertTo()

void ecvl::Image::ConvertTo ( DataType  dtype,
bool  saturate = true 
)
inline

Convert Image to another DataType.

Definition at line 557 of file image.h.

◆ Create()

void ecvl::Image::Create ( const std::vector< int > &  dims,
DataType  elemtype,
std::string  channels,
ColorType  colortype,
const std::vector< float > &  spacings = std::vector< float >(),
Device  dev = Device::CPU 
)

Allocates new contiguous data if needed.

The Create method allocates Image data as specified by the input parameters. The procedures tries to avoid the allocation of new memory when possible. The resulting image will be contiguous in any case. Calling this method on an Image that does not own data will always cause a new allocation, and the Image will become the owner of the data.

Parameters
[in]dimsNew Image dimensions.
[in]elemtypeNew Image DataType.
[in]channelsNew Image channels.
[in]colortypeNew Image colortype.
[in]spacingsNew Image spacings. Default is an empty vector.
[in]devDevice on which the Image is stored. Default is Device::CPU.
Examples
example_image_view.cpp.

◆ Div()

template<typename T >
void ecvl::Image::Div ( const T &  rhs,
bool  saturate = true 
)
inline

In-place division.

Definition at line 544 of file image.h.

◆ End() [1/2]

template<typename T >
Iterator<T> ecvl::Image::End ( )
inline

Generic non-const End Iterator.

This function gives you a non-const generic End Iterator that can be used both for contiguous and non-contiguous non-const Images. It is useful to iterate over over a non-const Image.

Definition at line 207 of file image.h.

◆ End() [2/2]

template<typename T >
ConstIterator<T> ecvl::Image::End ( ) const
inline

Generic const End Iterator.

This function gives you a const generic End Iterator that can be used both for contiguous and non-contiguous const Images. It is useful to iterate over a const Image.

Definition at line 224 of file image.h.

◆ GetDefaultDatasize()

size_t ecvl::Image::GetDefaultDatasize ( )
inlineprotected

Gets the default datasize for contiguous images.

This function returns the product of elemsize_ and all dims_.

Requires elemsize_ and dims_ to be correctly setup.

Definition at line 101 of file image.h.

◆ Height()

int ecvl::Image::Height ( ) const
inline

Returns the height of Image.

Definition at line 493 of file image.h.

◆ IsEmpty()

bool ecvl::Image::IsEmpty ( ) const
inline

To check whether the Image contains data or not, regardless of the owning status.

Definition at line 455 of file image.h.

◆ IsOwner()

bool ecvl::Image::IsOwner ( ) const
inline

To check whether the Image is owner of the data.

Todo:
Move the implementation to the specific hals if other shallow hals will be introduced.

Definition at line 462 of file image.h.

◆ Mul()

template<typename T >
void ecvl::Image::Mul ( const T &  rhs,
bool  saturate = true 
)
inline

In-place multiplication.

Definition at line 537 of file image.h.

◆ Neg()

void ecvl::Image::Neg ( )
inline

In-place negation.

Definition at line 516 of file image.h.

◆ operator *=()

Image& ecvl::Image::operator *= ( const Image rhs)

◆ operator+=()

Image& ecvl::Image::operator+= ( const Image rhs)

◆ operator-()

Image ecvl::Image::operator- ( ) const

◆ operator-=()

Image& ecvl::Image::operator-= ( const Image rhs)

◆ operator/=()

Image& ecvl::Image::operator/= ( const Image rhs)

◆ operator=() [1/2]

Image& ecvl::Image::operator= ( const Image rhs)
inline

Definition at line 370 of file image.h.

◆ operator=() [2/2]

Image& ecvl::Image::operator= ( Image &&  rhs)
inline

Definition at line 380 of file image.h.

◆ Ptr() [1/2]

uint8_t* ecvl::Image::Ptr ( const std::vector< int > &  coords)
inline

Returns a non-const pointer to data at given coordinates.

Examples
example_imgcodecs.cpp.

Definition at line 503 of file image.h.

◆ Ptr() [2/2]

const uint8_t* ecvl::Image::Ptr ( const std::vector< int > &  coords) const
inline

Returns a const pointer to data at given coordinates.

Definition at line 509 of file image.h.

◆ SetDefaultDatasize()

void ecvl::Image::SetDefaultDatasize ( )
inlineprotected

Sets the default datasize for contiguous images.

This function sets the detasize field as the product of elemsize_ and all dims_.

Requires elemsize_ and dims_ to be correctly setup.

Definition at line 112 of file image.h.

◆ SetDefaultStrides()

void ecvl::Image::SetDefaultStrides ( )
inlineprotected

Sets default strides for contiguous memory layouts.

This function sets the strides so that by incrementing the data pointer by strides_[0] it moves to the next element (increments dimension 0), strides_[1] moves to the next dimension, and so on. For example for "xyc" images, incrementing by strides_[0] increments the column, incrementing by strides_[1] increments the row, incrementing by strides_[2] moves to the next color plane.

Requires elemsize_ and dims_ to be correctly setup.

Definition at line 85 of file image.h.

◆ SetTo()

template<typename T >
void ecvl::Image::SetTo ( value)
inline

Set Image value to rhs.

Definition at line 551 of file image.h.

◆ Sub()

template<typename T >
void ecvl::Image::Sub ( const T &  rhs,
bool  saturate = true 
)
inline

In-place subtraction.

Definition at line 530 of file image.h.

◆ To()

void ecvl::Image::To ( Device  dev)
inline

Definition at line 404 of file image.h.

◆ Width()

int ecvl::Image::Width ( ) const
inline

Returns the width of Image.

Definition at line 483 of file image.h.

Friends And Related Function Documentation

◆ HardwareAbstractionLayer

friend class HardwareAbstractionLayer
friend

Definition at line 117 of file image.h.

◆ operator *

Image operator * ( Image  lhs,
const Image rhs 
)
friend

◆ operator+

Image operator+ ( Image  lhs,
const Image rhs 
)
friend

◆ operator-

Image operator- ( Image  lhs,
const Image rhs 
)
friend

◆ operator/

Image operator/ ( Image  lhs,
const Image rhs 
)
friend

◆ swap

void swap ( Image lhs,
Image rhs 
)
friend

Definition at line 352 of file image.h.

Member Data Documentation

◆ channels_

std::string ecvl::Image::channels_

String which describes how Image planes are organized.

A single character provides the information related to the corresponding channel. The possible values are:

  • 'x': horizontal spatial dimension
  • 'y': vertical spatial dimension
  • 'z': depth spatial dimension
  • 'c': color dimension
  • 't': temporal dimension
  • 'o': any other dimension For example, "xyc" describes a 2-dimensional Image structured in color planes. This could be for example a ColorType::GRAY Image with dims_[2] = 1 or a ColorType::RGB Image with dims_[2] = 3 an so on. The ColorType constrains the value of the dimension corresponding to the color channel. Another example is "cxy" with dims_[0] = 3 and ColorType::BGR. In this case the color dimension is the one which changes faster as it is done in other libraries such as OpenCV.
Examples
example_ecvl_eddl.cpp, and example_image_view.cpp.

Definition at line 130 of file image.h.

◆ colortype_

ColorType ecvl::Image::colortype_

Image ColorType.

If this is different from ColorType::none, the channels_ string must contain a 'c' and the corresponding dimension must have the appropriate value. See ColorType for the possible values.

If colortype_ is ColorType::none, then the image should not have a 'c' in the channels_ string.

Examples
example_ecvl_eddl.cpp, and example_image_view.cpp.

Definition at line 153 of file image.h.

◆ contiguous_

bool ecvl::Image::contiguous_

Whether the image is stored contiguously or not in memory.

Definition at line 176 of file image.h.

◆ data_

uint8_t* ecvl::Image::data_

Pointer to Image data.

                If the Image is not the owner
                of data, for example when using Image views, this
                attribute will point to the data of another Image.
                The possession or not of the data depends on the
                HardwareAbstractionLayer. 
Examples
example_image_view.cpp.

Definition at line 168 of file image.h.

◆ datasize_

size_t ecvl::Image::datasize_

Size of Image data in bytes.

Definition at line 175 of file image.h.

◆ dev_

Device ecvl::Image::dev_

Identifier for the device on which the image data is.

This is just informative and should be always synchronized with the HAL pointer.

Definition at line 187 of file image.h.

◆ dims_

std::vector<int> ecvl::Image::dims_

Vector of Image dimensions. Each dimension is given in pixels/voxels.

Examples
example_image_view.cpp.

Definition at line 123 of file image.h.

◆ elemsize_

uint8_t ecvl::Image::elemsize_

Size (in bytes) of Image pixels.

Definition at line 122 of file image.h.

◆ elemtype_

DataType ecvl::Image::elemtype_

Type of Image pixels, must be one of the values available in DataType.

Definition at line 120 of file image.h.

◆ hal_

HardwareAbstractionLayer* ecvl::Image::hal_

Pointer to the HardwareAbstractionLayer employed by the Image.

It can be CpuHal or ShallowCpuHal. The former is responsible for allocating and deallocating data, when using the CpuHal the Image is the owner of data. When ShallowCpuHal is employed the Image does not own data and operations on memory are not allowed or does not produce any effect.

Definition at line 179 of file image.h.

◆ meta_

MetaData* ecvl::Image::meta_

Pointer to Image MetaData.

Definition at line 178 of file image.h.

◆ spacings_

std::vector<float> ecvl::Image::spacings_

Space between pixels/voxels.

Vector with the same size as dims_, storing the distance in mm between consecutive pixels/voxels on every axis.

Definition at line 163 of file image.h.

◆ strides_

std::vector<int> ecvl::Image::strides_

Vector of Image strides.

Strides represent the number of bytes the pointer on data has to move to reach the next pixel/voxel on the correspondent size.

Definition at line 125 of file image.h.


The documentation for this class was generated from the following file: