libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
crn::Image< T > Class Template Reference

Abstract class for images. More...

#include <CRNImage.h>

+ Inheritance diagram for crn::Image< T >:
+ Collaboration diagram for crn::Image< T >:

Public Types

using pixel_type = T
 

Public Member Functions

 Image (size_t w, size_t h, pixel_type val=pixel_type(0))
 Constructor. More...
 
 Image ()
 Default constructor. More...
 
 Image (size_t w, size_t h, const pixel_type *data)
 Constructor from data. More...
 
 Image (const Image &img)=default
 Copy constructor. More...
 
template<typename Y >
 Image (const Image< Y > &img)
 Copy constructor. More...
 
 Image (const Image< typename BoolNotBool< T >::type > &img)
 Copy constructor. More...
 
template<typename Y >
 Image (const Image< Y > &img, const Rect &bbox)
 Crop constructor. More...
 
 Image (const Image< typename BoolNotBool< T >::type > &img, const Rect &bbox)
 Crop constructor. More...
 
 Image (Image &&img)=default
 Move constructor. More...
 
virtual ~Image () override=default
 Destructor. More...
 
Imageoperator= (const Image &img)=default
 Copy operator. More...
 
template<typename Y >
Imageoperator= (const Image< Y > &img)
 Copy operator. More...
 
Imageoperator= (const Image< typename BoolNotBool< T >::type > &img)
 Copy operator. More...
 
template<typename Y >
void Assign (const Image< Y > &img)
 Force copy operator (pixel cast) More...
 
Imageoperator= (Image &&img)=default
 Move operator. More...
 
virtual std::unique_ptr
< ImageBase
Clone () const override
 
void Swap (Image &other)
 Swaps two images. More...
 
virtual void SavePNG (const Path &fname) const override
 Saves as PNG file. More...
 
virtual void SaveJPEG (const Path &fname, unsigned int qual) const override
 Saves as JPEG file. More...
 
template<typename MAT >
MAT ToMatrix () const
 Converts to matrix. More...
 
std::vector< pixel_type >::iterator begin ()
 
std::vector< pixel_type >
::const_iterator 
begin () const
 
std::vector< pixel_type >::iterator end ()
 
std::vector< pixel_type >
::const_iterator 
end () const
 
std::vector< pixel_type >
::const_iterator 
cbegin () const
 
std::vector< pixel_type >
::const_iterator 
cend () const
 
std::vector< pixel_type >::pointer GetPixels () noexcept
 Gets a pointer to the pixels. More...
 
std::vector< pixel_type >
::const_pointer 
GetPixels () const noexcept
 Gets a const pointer to the pixels. More...
 
std::vector< pixel_type >
::reference 
At (size_t x, size_t y) noexcept
 Returns a reference to a pixel. More...
 
std::vector< pixel_type >
::reference 
At (size_t offset) noexcept
 Returns a reference to a pixel. More...
 
std::vector< pixel_type >
::const_reference 
At (size_t x, size_t y) const noexcept
 Returns a reference to a pixel. More...
 
std::vector< pixel_type >
::const_reference 
At (size_t offset) const noexcept
 Returns a reference to a pixel. More...
 
bool operator== (const Image &other) const
 Tests equality. More...
 
bool operator!= (const Image &other) const
 Tests equality. More...
 
Imageoperator+= (const Image &img)
 Adds another image. More...
 
Imageoperator-= (const Image &img)
 Subtracts another image. More...
 
Imageoperator*= (double f)
 Multiplies all pixels. More...
 
Imageoperator*= (const Image &img)
 Multiplies with another image's pixels. More...
 
Imageoperator/= (const Image &img)
 Divides by another image's pixels. More...
 
void Negative ()
 Negative. More...
 
void Complement (pixel_type maxval=std::numeric_limits< pixel_type >::max())
 Complement. More...
 
template<typename Y >
void Blit (const Image< Y > &src, const Rect &srczone, size_t dx, size_t dy)
 Copies a part of an image. More...
 
void FloodFill (size_t x, size_t y, const pixel_type &val, crn::DistanceType dist=crn::DistanceType::D4)
 Flood fills a portion of the image. More...
 
void ScanFill (size_t x, size_t y, const pixel_type &val, crn::DistanceType dist=crn::DistanceType::D4)
 Fills a portion of the image. More...
 
void DrawRect (const Rect &r, pixel_type color, bool filled=false)
 Draws a rectangle using a specified color. More...
 
void DrawLine (size_t x1, size_t y1, size_t x2, size_t y2, pixel_type color)
 Draws a line using a specified color. More...
 
virtual void ScaleToSize (size_t w, size_t h) override
 Scales the image. More...
 
void Flip (const Orientation &ori)
 Flips the image. More...
 
template<typename CMP = std::less<pixel_type>>
void Dilate (const MatrixInt &strel, CMP cmp=std::less< pixel_type >{})
 Morphological dilatation. More...
 
template<typename CMP = std::less<pixel_type>>
void Erode (const MatrixInt &strel, CMP cmp=std::less< pixel_type >{})
 Morphological erosion. More...
 
template<typename CMP = std::less<pixel_type>>
void FastDilate (size_t halfwin, size_t index=0, CMP cmp=std::less< pixel_type >{})
 Morphological dilatation. More...
 
template<typename CMP = std::less<pixel_type>>
void FastErode (size_t halfwin, size_t index=0, CMP cmp=std::less< pixel_type >{})
 Morphological erosion. More...
 
void Convolve (const MatrixDouble &mat)
 Convolution. More...
 
void GaussianBlur (double sigma)
 Gaussian blur. More...
 
template<typename Y >
Image< T > & operator= (const Image< Y > &img)
 
- Public Member Functions inherited from crn::ImageBase
virtual ~ImageBase ()
 
 ImageBase (size_t w, size_t h)
 
 ImageBase (const ImageBase &)=default
 
 ImageBase (ImageBase &&)=default
 
ImageBaseoperator= (const ImageBase &)=default
 
ImageBaseoperator= (ImageBase &&)=default
 
size_t GetWidth () const noexcept
 
size_t GetHeight () const noexcept
 
Rect GetBBox () const noexcept
 
size_t Size () const noexcept
 

Protected Attributes

std::vector< pixel_typepixels
 
- Protected Attributes inherited from crn::ImageBase
size_t width
 
size_t height
 

Detailed Description

template<class T>
class crn::Image< T >

Abstract class for images.

This class is the highest ancestor for all image classes.

Author
Yann LEYDIER
Date
August 2007
Version
0.4

Definition at line 141 of file CRNImage.h.

Member Typedef Documentation

template<class T>
using crn::Image< T >::pixel_type = T

Definition at line 144 of file CRNImage.h.

Constructor & Destructor Documentation

template<typename T >
crn::Image< T >::Image ( size_t  w,
size_t  h,
pixel_type  val = pixel_type(0) 
)

Constructor.

Constructor for this class

Exceptions
ExceptionRuntimecannot allocate pixels
Parameters
[in]wwidth value to be set for this image
[in]hheight value to be set for this image
[in]valdefault value for pixels

Definition at line 55 of file CRNImage.hpp.

template<class T>
crn::Image< T >::Image ( )
inline

Default constructor.

Definition at line 153 of file CRNImage.h.

template<typename T >
crn::Image< T >::Image ( size_t  w,
size_t  h,
const pixel_type data 
)

Constructor from data.

Constructor for this class

Exceptions
ExceptionRuntimecannot allocate pixels
Parameters
[in]wwidth value to be set for this image
[in]hheight value to be set for this image
[in]datathe data to copy to the new image

Definition at line 71 of file CRNImage.hpp.

template<class T>
crn::Image< T >::Image ( const Image< T > &  img)
default

Copy constructor.

template<typename T >
template<typename Y >
crn::Image< T >::Image ( const Image< Y > &  img)
explicit

Copy constructor.

Copy constructor

Parameters
[in]imgthe image to copy

Definition at line 79 of file CRNImage.hpp.

template<typename T>
crn::Image< T >::Image ( const Image< typename BoolNotBool< T >::type > &  img)
explicit

Copy constructor.

Copy constructor

Parameters
[in]imgthe image to copy

Definition at line 87 of file CRNImage.hpp.

template<typename T >
template<typename Y >
crn::Image< T >::Image ( const Image< Y > &  img,
const Rect bbox 
)

Crop constructor.

Crop constructor

Parameters
[in]imgthe image to copy
[in]bboxthe zone to copy

Definition at line 99 of file CRNImage.hpp.

template<typename T>
crn::Image< T >::Image ( const Image< typename BoolNotBool< T >::type > &  img,
const Rect bbox 
)

Crop constructor.

Crop constructor

Parameters
[in]imgthe image to copy
[in]bboxthe zone to copy

Definition at line 111 of file CRNImage.hpp.

template<class T>
crn::Image< T >::Image ( Image< T > &&  img)
default

Move constructor.

template<class T>
virtual crn::Image< T >::~Image ( )
overridevirtualdefault

Destructor.

Member Function Documentation

template<typename T >
template<typename Y >
void crn::Image< T >::Assign ( const Image< Y > &  img)

Force copy operator (pixel cast)

Force copy operator: pixel values are cast

Parameters
[in]imgthe image to copy

Definition at line 147 of file CRNImage.hpp.

template<class T>
std::vector<pixel_type>::reference crn::Image< T >::At ( size_t  x,
size_t  y 
)
inlinenoexcept

Returns a reference to a pixel.

Definition at line 224 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::reference crn::Image< T >::At ( size_t  offset)
inlinenoexcept

Returns a reference to a pixel.

Definition at line 226 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_reference crn::Image< T >::At ( size_t  x,
size_t  y 
) const
inlinenoexcept

Returns a reference to a pixel.

Definition at line 228 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_reference crn::Image< T >::At ( size_t  offset) const
inlinenoexcept

Returns a reference to a pixel.

Definition at line 230 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::iterator crn::Image< T >::begin ( )
inline

Definition at line 211 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_iterator crn::Image< T >::begin ( ) const
inline

Definition at line 212 of file CRNImage.h.

template<typename T >
template<typename Y >
void crn::Image< T >::Blit ( const Image< Y > &  src,
const Rect srczone,
size_t  dx,
size_t  dy 
)

Copies a part of an image.

Copies a part of an image

Parameters
[in]srcthe image to copy
[in]srczonethe zone to copy
[in]dxthe abscissa where to copy
[in]dythe ordinate where to copy

Definition at line 282 of file CRNImage.hpp.

template<class T>
std::vector<pixel_type>::const_iterator crn::Image< T >::cbegin ( ) const
inline

Definition at line 215 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_iterator crn::Image< T >::cend ( ) const
inline

Definition at line 216 of file CRNImage.h.

template<class T>
virtual std::unique_ptr<ImageBase> crn::Image< T >::Clone ( ) const
inlineoverridevirtual

Implements crn::ImageBase.

Definition at line 184 of file CRNImage.h.

template<typename T >
void crn::Image< T >::Complement ( pixel_type  maxval = std::numeric_limits<pixel_type>::max())

Complement.

Complement

Parameters
[in]maxvalmaximum value

Definition at line 270 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::Convolve ( const MatrixDouble mat)

Convolution.

Convolves the image with a matrix.

Exceptions
ExceptionDimensioneven matrix
ExceptionDomainmatrix bigger than image
Parameters
[in]matThe convolution matrix

Definition at line 1023 of file CRNImage.hpp.

template<typename T >
template<typename CMP >
void crn::Image< T >::Dilate ( const MatrixInt strel,
CMP  cmp = std::less<pixel_type>{} 
)

Morphological dilatation.

Morphological dilatation

Warning
Invalidates proxy
Exceptions
ExceptionDimensioneven element
Parameters
[in]strelThe structuring element

Definition at line 761 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::DrawLine ( size_t  x1,
size_t  y1,
size_t  x2,
size_t  y2,
pixel_type  color 
)

Draws a line using a specified color.

Draws a line using a specified color

Parameters
[in]x1the beginning abscissa
[in]y1the beginning ordinate
[in]x2the ending abscissa
[in]y2the ending ordinate
[in]colora pixel in any compatible format

Definition at line 543 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::DrawRect ( const Rect r,
pixel_type  color,
bool  filled = false 
)

Draws a rectangle using a specified color.

Draws a rectangle using a specified color

Parameters
[in]rthe rectangle to draw
[in]colora pixel in any compatible format
[in]filledis the rectangle filled? (default = no)

Definition at line 515 of file CRNImage.hpp.

template<class T>
std::vector<pixel_type>::iterator crn::Image< T >::end ( )
inline

Definition at line 213 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_iterator crn::Image< T >::end ( ) const
inline

Definition at line 214 of file CRNImage.h.

template<typename T >
template<typename CMP >
void crn::Image< T >::Erode ( const MatrixInt strel,
CMP  cmp = std::less<pixel_type>{} 
)

Morphological erosion.

Morphological erosion.

Warning
Invalidates proxy
Exceptions
ExceptionDimensioneven element
Parameters
[in]strelThe structuring element
Returns
true if success, false else

Definition at line 827 of file CRNImage.hpp.

template<typename T >
template<typename CMP >
void crn::Image< T >::FastDilate ( size_t  halfwin,
size_t  index = 0,
CMP  cmp = std::less<pixel_type>{} 
)

Morphological dilatation.

Morphological dilatation (faster than normal dilatation for halfwin >= 8)

Warning
Invalidates proxy
Parameters
[in]halfwinthe half window size (window width and height = 2*halfwin+1)
[in]indexthe rank of the value to use on each column (0 = regular dilatation, halfwin = something closer to a median filter)

Definition at line 890 of file CRNImage.hpp.

template<typename T >
template<typename CMP >
void crn::Image< T >::FastErode ( size_t  halfwin,
size_t  index = 0,
CMP  cmp = std::less<pixel_type>{} 
)

Morphological erosion.

Morphological erosion (faster than normal erosion for halfwin >= 8)

Warning
Invalidates proxy
Parameters
[in]halfwinthe half window size (window width and height = 2*halfwin+1)
[in]indexthe rank of the value to use on each column (0 = regular erosion, halfwin = something closer to a median filter)

Definition at line 956 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::Flip ( const Orientation ori)

Flips the image.

Flips the image

Exceptions
ExceptionInvalidArgumentinvalid orientation
Parameters
[in]orithe orientation of the flip

Definition at line 729 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::FloodFill ( size_t  x,
size_t  y,
const pixel_type val,
crn::DistanceType  dist = crn::DistanceType::D4 
)

Flood fills a portion of the image.

Flood fills a portion of the image.

Warning
Be careful of stack overflows!
Exceptions
ExceptionDomaincoordinates out of bounds
Parameters
[in]xthe beginning abscissa
[in]ythe beginning ordinate
[in]valthe value used to fill
[in]distthe distance to use (DistanceType::D4 or DistanceType::D8)

Definition at line 311 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::GaussianBlur ( double  sigma)

Gaussian blur.

Gaussian blur

Exceptions
ExceptionDomainnull or negative sigma
ExceptionDimensionmatrix bigger than image
Parameters
[in]sigmathe standard deviation of the Gaussian

Definition at line 1132 of file CRNImage.hpp.

template<class T>
std::vector<pixel_type>::pointer crn::Image< T >::GetPixels ( )
inlinenoexcept

Gets a pointer to the pixels.

Definition at line 219 of file CRNImage.h.

template<class T>
std::vector<pixel_type>::const_pointer crn::Image< T >::GetPixels ( ) const
inlinenoexcept

Gets a const pointer to the pixels.

Definition at line 221 of file CRNImage.h.

template<typename T >
void crn::Image< T >::Negative ( )

Negative.

Negative

Definition at line 261 of file CRNImage.hpp.

template<class T>
bool crn::Image< T >::operator!= ( const Image< T > &  other) const
inline

Tests equality.

Definition at line 235 of file CRNImage.h.

template<typename T >
Image< T > & crn::Image< T >::operator*= ( double  f)

Multiplies all pixels.

Multiplies all pixels

Parameters
[in]fthe factor
Returns
a self reference

Definition at line 221 of file CRNImage.hpp.

template<typename T >
Image< T > & crn::Image< T >::operator*= ( const Image< T > &  img)

Multiplies with another image's pixels.

Multiplies with another image's pixels

Exceptions
ExceptionDimensionimages have different sizes
Parameters
[in]imgthe image to multiply
Returns
a self reference

Definition at line 233 of file CRNImage.hpp.

template<typename T >
Image< T > & crn::Image< T >::operator+= ( const Image< T > &  img)

Adds another image.

Adds another image

Exceptions
ExceptionDimensionimages have different sizes
Parameters
[in]imgthe image to add
Returns
a self reference

Definition at line 194 of file CRNImage.hpp.

template<typename T >
Image< T > & crn::Image< T >::operator-= ( const Image< T > &  img)

Subtracts another image.

Subtracts another image

Exceptions
ExceptionDimensionimages have different sizes
Parameters
[in]imgthe image to subtract
Returns
a self reference

Definition at line 208 of file CRNImage.hpp.

template<typename T >
Image< T > & crn::Image< T >::operator/= ( const Image< T > &  img)

Divides by another image's pixels.

Divides by another image's pixels

Exceptions
ExceptionDimensionimages have different sizes
Parameters
[in]imgthe image to divide with
Returns
a self reference

Definition at line 247 of file CRNImage.hpp.

template<class T>
template<typename Y >
Image<T>& crn::Image< T >::operator= ( const Image< Y > &  img)

Copy operator: pixel values are not cast

Parameters
[in]imgthe image to copy
Returns
a self reference

Definition at line 123 of file CRNImage.hpp.

template<class T>
Image& crn::Image< T >::operator= ( const Image< T > &  img)
default

Copy operator.

template<class T>
template<typename Y >
Image& crn::Image< T >::operator= ( const Image< Y > &  img)

Copy operator.

template<typename T>
Image< T > & crn::Image< T >::operator= ( const Image< typename BoolNotBool< T >::type > &  img)

Copy operator.

Copy operator: pixel values are not cast

Parameters
[in]imgthe image to copy
Returns
a self reference

Definition at line 135 of file CRNImage.hpp.

template<class T>
Image& crn::Image< T >::operator= ( Image< T > &&  img)
default

Move operator.

template<typename T >
bool crn::Image< T >::operator== ( const Image< T > &  other) const

Tests equality.

Tests equality

Parameters
[in]otherthe image to compare
Returns
true if dimensions are equal and pixels are equal

Definition at line 178 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::SaveJPEG ( const Path fname,
unsigned int  qual 
) const
overridevirtual

Saves as JPEG file.

Saves as JPEG file

Exceptions
ExceptionInvalidArgumentunsupported pixel format
Parameters
[in]fnamefull path to the image to save
[in]qualcompression quality [0..100]

Implements crn::ImageBase.

Definition at line 169 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::SavePNG ( const Path fname) const
overridevirtual

Saves as PNG file.

Saves as PNG file

Exceptions
ExceptionInvalidArgumentunsupported pixel format
Parameters
[in]fnamefull path to the image to save

Implements crn::ImageBase.

Definition at line 160 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::ScaleToSize ( size_t  w,
size_t  h 
)
overridevirtual

Scales the image.

Scales the image

Parameters
[in]wthe new width
[in]hthe new height

Implements crn::ImageBase.

Definition at line 614 of file CRNImage.hpp.

template<typename T >
void crn::Image< T >::ScanFill ( size_t  x,
size_t  y,
const pixel_type val,
crn::DistanceType  dist = crn::DistanceType::D4 
)

Fills a portion of the image.

Fills a portion of the image.

Exceptions
ExceptionDomaincoordinates out of bounds
Parameters
[in]xthe beginning abscissa
[in]ythe beginning ordinate
[in]valthe value used to fill
[in]distthe distance to use (DistanceType::D4 or DistanceType::D8)

Definition at line 363 of file CRNImage.hpp.

template<class T>
void crn::Image< T >::Swap ( Image< T > &  other)
inline

Swaps two images.

Definition at line 187 of file CRNImage.h.

template<class T>
template<typename MAT >
MAT crn::Image< T >::ToMatrix ( ) const
inline

Converts to matrix.

Definition at line 200 of file CRNImage.h.

Member Data Documentation

template<class T>
std::vector<pixel_type> crn::Image< T >::pixels
protected

the pixels

Definition at line 295 of file CRNImage.h.


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