Population
Image processing library in C++
Public Types | Public Member Functions | Protected Attributes | List of all members
pop::MatN< Dim, PixelType > Class Template Reference

template class for matrix (or Image) More...

#include <MatN.h>

Inheritance diagram for pop::MatN< Dim, PixelType >:
pop::Vec< PixelType >

Public Types

enum  { DIM =Dim }
 
typedef PixelType F
 
typedef VecN< Dim, I32E
 
typedef VecN< Dim, int > Domain
 
typedef MatNIteratorEDomain< EIteratorEDomain
 
typedef MatNIteratorEROI< MatN< Dim, PixelType > > IteratorEROI
 
typedef MatNIteratorENeighborhood< E, MatNBoundaryConditionBounded > IteratorENeighborhood
 
typedef MatNIteratorENeighborhood< E, MatNBoundaryConditionMirror > IteratorENeighborhoodMirror
 
typedef MatNIteratorENeighborhood< E, MatNBoundaryConditionPeriodic > IteratorENeighborhoodPeriodic
 
typedef MatNIteratorENeighborhoodAmoebas< MatNIteratorENeighborhoodAmoebas
 
typedef MatNIteratorEOrder< EIteratorEOrder
 
typedef MatNBoundaryCondition BoundaryCondition
 
typedef MatNIteratorERectangle< EIteratorERectangle
 
typedef Vec< PixelType >::iterator iterator
 
typedef Vec< PixelType >::value_type value_type
 
typedef Vec< PixelType >::pointer pointer
 
typedef Vec< PixelType >::const_pointer const_pointer
 
typedef Vec< PixelType >::reference reference
 
typedef Vec< PixelType >::const_reference const_reference
 
typedef Vec< PixelType >::const_iterator const_iterator
 
typedef Vec< PixelType >::const_reverse_iterator const_reverse_iterator
 
typedef Vec< PixelType >::reverse_iterator reverse_iterator
 
typedef Vec< PixelType >::size_type size_type
 
typedef Vec< PixelType >::difference_type difference_type
 
typedef Vec< PixelType >::allocator_type allocator_type
 
- Public Types inherited from pop::Vec< PixelType >
typedef int E
 
typedef PixelType F
 
typedef unsigned int Domain
 
typedef VecNIteratorEDomain IteratorEDomain
 
typedef std::vector< PixelType >::value_type value_type
 
typedef std::vector< PixelType >::pointer pointer
 
typedef std::vector< PixelType >::const_pointer const_pointer
 
typedef std::vector< PixelType >::reference reference
 
typedef std::vector< PixelType >::const_reference const_reference
 
typedef std::vector< PixelType >::iterator iterator
 
typedef std::vector< PixelType >::const_iterator const_iterator
 
typedef std::vector< PixelType >::const_reverse_iterator const_reverse_iterator
 
typedef std::vector< PixelType >::reverse_iterator reverse_iterator
 
typedef std::vector< PixelType >::size_type size_type
 
typedef std::vector< PixelType >::difference_type difference_type
 
typedef std::vector< PixelType >::allocator_type allocator_type
 

Public Member Functions

template<class T1 >
MatN< Dim, PixelType > & operator= (const MatN< Dim, T1 > &img)
 
Constructor
 MatN ()
 
 MatN (const VecN< Dim, int > &domain, PixelType v=PixelType())
 
 MatN (unsigned int sizei, unsigned int sizej)
 
 MatN (unsigned int sizei, unsigned int sizej, unsigned int sizek)
 
 MatN (const VecN< Dim, int > &x, const Vec< PixelType > &data_values)
 
 MatN (const VecN< Dim, int > &x, const PixelType *v_value)
 
template<class T1 >
 MatN (const MatN< Dim, T1 > &img)
 
 MatN (const MatN &img)
 
 MatN (const Mat2x< PixelType, 2, 2 > m)
 
 MatN (const Mat2x< PixelType, 3, 3 > m)
 
template<int SIZEI, int SIZEJ>
 MatN (const Mat2x< PixelType, SIZEI, SIZEJ > m)
 
 MatN (const char *filepath)
 
 MatN (const MatN &img, const VecN< Dim, int > &xmin, const VecN< Dim, int > &xmax)
 
Domain
Domain getDomain () const
 
unsigned int sizeI () const
 
unsigned int rows () const
 
unsigned int sizeJ () const
 
unsigned int columns () const
 
unsigned int sizeK () const
 
unsigned int depth () const
 
bool isValid (const E &x) const
 
bool isValid (int i, int j) const
 
bool isValid (int i, int j, int k) const
 
void resize (unsigned int sizei, unsigned int sizej)
 
void resize (unsigned int sizei, unsigned int sizej, unsigned int sizek)
 
void resize (const VecN< Dim, int > &d)
 
void resizeInformation (unsigned int sizei, unsigned int sizej)
 
void resizeInformation (unsigned int sizei, unsigned int sizej, unsigned int sizek)
 
void resizeInformation (const VecN< Dim, int > &d)
 
bool isEmpty () const
 
void clear ()
 
Accessor cell or sub-matrix
Foperator() (const VecN< Dim, int > &x)
 
const Foperator() (const VecN< Dim, int > &x) const
 
PixelType & operator() (unsigned int i, unsigned int j)
 
const PixelType & operator() (unsigned int i, unsigned int j) const
 
PixelType & operator() (unsigned int i, unsigned int j, unsigned int k)
 
const PixelType & operator() (unsigned int i, unsigned int j, unsigned int k) const
 
MatN operator() (const VecN< Dim, int > &xmin, const VecN< Dim, int > &xmax) const
 
PixelType & operator() (unsigned int index)
 
PixelType & operator() (size_type i, size_type j, const Vec< size_type > &_table)
 
const PixelType & operator() (unsigned int index) const
 
PixelType interpolationBilinear (const VecN< DIM, F32 > xf) const
 
PixelType * data ()
 
const PixelType * data () const
 
In-out facility
void loadFromDirectory (const char *pathdir, const char *basefilename="", const char *extension="")
 
bool load (const char *file)
 
bool load (const std::string file)
 
bool loadRaw (const char *file, const Domain &d)
 
void saveFromDirectory (const char *pathdir, const char *basefilename="toto", const char *extension=".pgm") const
 
void save (const char *file) const
 
void save (const std::string file) const
 
void saveRaw (const char *file) const
 
void saveAscii (const char *file, std::string header="") const
 
void display (const char *title="", bool stoprocess=true, bool automaticresize=true) const
 
Iterators
IteratorEDomain getIteratorEDomain () const
 
IteratorEROI getIteratorEROI () const
 
IteratorENeighborhood getIteratorENeighborhood (F32 radius=1, int norm=1) const
 
template<typename Type1 >
IteratorENeighborhood getIteratorENeighborhood (const MatN< Dim, Type1 > &structural_element, int dilate=1) const
 
IteratorEOrder getIteratorEOrder (int coordinatelastloop=0, int direction=1) const
 
IteratorERectangle getIteratorERectangle (const E &xmin, const E &xmax) const
 
IteratorENeighborhoodAmoebas getIteratorENeighborhoodAmoebas (F32 distance_max=4, F32 lambda_param=0.01) const
 Amoeabas kernel. More...
 
Arithmetics
template<class T1 >
MatNoperator= (const MatN< Dim, T1 > &img)
 
MatNoperator= (const MatN &img)
 
MatN< Dim, PixelType > & operator= (PixelType value)
 
MatN< Dim, PixelType > & fill (PixelType value)
 
MatN< Dim, PixelType > opposite (int mode=0) const
 
bool operator== (const MatN< Dim, PixelType > &f) const
 
bool operator!= (const MatN< Dim, PixelType > &f) const
 
MatN< Dim, PixelType > & operator+= (const MatN< Dim, PixelType > &f)
 
MatN< Dim, PixelType > operator+ (const MatN< Dim, PixelType > &f) const
 
MatN< Dim, PixelType > & operator+= (PixelType value)
 
MatN< Dim, PixelType > operator+ (PixelType value) const
 
MatN< Dim, PixelType > & operator-= (const MatN< Dim, PixelType > &f)
 
MatN< Dim, PixelType > & operator-= (PixelType value)
 
MatN< Dim, PixelType > operator- (const MatN< Dim, PixelType > &f) const
 
MatN< Dim, PixelType > operator- () const
 
MatN< Dim, PixelType > operator- (PixelType value) const
 
MatN operator* (const MatN &m) const
 
MatNoperator*= (const MatN &m)
 
Vec< PixelType > operator* (const Vec< PixelType > &v) const
 
MatN multTermByTerm (const MatN &f) const
 
MatN< Dim, PixelType > & operator*= (PixelType value)
 
MatN< Dim, PixelType > operator* (PixelType value) const
 
MatN< Dim, PixelType > divTermByTerm (const MatN &f)
 
MatN< Dim, PixelType > & operator/= (PixelType value)
 
MatN< Dim, PixelType > operator/ (PixelType value) const
 
Linear algebra facilities
MatN deleteRow (unsigned int i) const
 
MatN deleteCol (unsigned int j) const
 
Vec< FgetRow (unsigned int i) const
 
Vec< FgetCol (unsigned int j) const
 
void setRow (unsigned int i, const Vec< F > &v)
 
void setCol (unsigned int j, const Vec< F > &v)
 
void swapRow (unsigned int i_0, unsigned int i_1)
 
void swapCol (unsigned int j_0, unsigned int j_1)
 
F minorDet (unsigned int i, unsigned int j) const
 
F cofactor (unsigned int i, unsigned int j) const
 
MatN cofactor () const
 
MatN transpose () const
 
F determinant () const
 
F trace () const
 
MatN inverse () const
 
MatN identity (int size_mat=0) const
 $I_n = \begin{bmatrix}1 & 0 & \cdots & 0 \\0 & 1 & \cdots & 0 \\\vdots & \vdots & \ddots & \vdots \\0 & 0 & \cdots & 1 \end{bmatrix}$ More...
 
- Public Member Functions inherited from pop::Vec< PixelType >
 Vec ()
 
 Vec (const Vec< CoordinateType1 > &v)
 
 Vec (const Vec &v)
 
 Vec (const std::vector< CoordinateType1 > &v)
 
 Vec (int size_vec, PixelTypevalue=PixelType())
 
 Vec (const VecN< 1, CoordinateType1 > &x)
 
 Vec (const VecN< 2, CoordinateType1 > &x)
 
 Vec (const VecN< 3, CoordinateType1 > &x)
 
 Vec (const VecN< 4, CoordinateType1 > &x)
 
 Vec (const VecN< 5, CoordinateType1 > &x)
 
 Vec (_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
 
Domain getDomain () const
 
PixelType & operator() (unsigned int i)
 
const PixelType & operator() (unsigned int i) const
 
Vec< PixelType > & operator+= (const Vec< PixelType > &v)
 
Vecoperator+= (PixelTypevalue)
 
Vec< PixelType > operator+ (const Vec< PixelType > &v) const
 
Vec operator+ (PixelTypevalue) const
 
Vec< PixelType > & operator-= (const Vec< PixelType > &v)
 
Vecoperator-= (PixelTypevalue)
 
Vec< PixelType > operator- (const Vec< PixelType > &v) const
 
Vec< PixelType > operator- ()
 
Vec operator- (PixelTypevalue) const
 
Vec< PixelType > & operator*= (const Vec< PixelType > &v)
 
Vecoperator*= (PixelTypevalue)
 
Vec operator* (PixelTypevalue) const
 
Vec< PixelType > operator* (const Vec< PixelType > &v) const
 
Vec< PixelType > & operator/= (const Vec< PixelType > &v)
 
Vecoperator/= (PixelTypevalue)
 
Vec< PixelType > operator/ (const Vec< PixelType > &v) const
 
Vec operator/ (PixelTypevalue) const
 
F32 norm (int p=2) const
 
F32 normPower (int p=2) const
 
PixelType multCoordinate ()
 
void load (std::string file)
 
void save (std::string file) const
 
Vecclone ()
 
void display ()
 
IteratorEDomain getIteratorEDomain () const
 

Protected Attributes

VecN< Dim, int > _domain
 
VecN2IndiceByTable< Dim > _vec2_indice
 

Detailed Description

template<int Dim, typename PixelType>
class pop::MatN< Dim, PixelType >

template class for matrix (or Image)

Author
Tariel Vincent
Template Parameters
DimSpace dimension
PixelTypePixel/Voxel type

A matrix is a regular tessellation of a domain of the n-dimensional euclidean space where each cell is a n-square (a square in 2-dimension called pixel, a cube in 3-dimension called voxel). A cell is located with n integers (2 integers for a pixel and 3 integers for a voxel). In 2d, the horizontal and vertical lines in a matrix are called rows and columns, respectively. To access a cell, we use the matrix notation f(i,j) refering to the i-th row and the j-th column. Each cell contains an information. For a gray-level matrix, this information is a grey-level value. This value can be coded in one byte representing the range (0, 28 −1) = (0, 255) where the value 0 represents the black color, 255 the white color, and any value between (0, 255) a fraction between both colors. This class is a model of Function concept.

grid2.png
Left: 2D matrix with 6 rows and 5 columns with a pixel type coded in one byte, right: grey-level representation

Pixel(Voxel) Type

This class is written in generic programming with template parameters. The first one is the dimension, the second one the pixel/voxel type. To facilite its utilisation, we use some typedef declarations to define the usual types to allow coding in C-style as these ones:

Structure

The cell values are stored in a vector container, a class template of STL, which works like a dynamic array in a strict linear sequence. The position of the cell can be located by an index or a point VecN<Dim,int> as n integers (in 2D II32=(i,j), in 3D Vec3I32=(i,j,k)) as explained in the below figure:

vector.png
the value f(i,j) corresponds to the element v[j+i*ColSize] of the vector container.

We make the choice to have a single Vec and not a Vec of Vec as the classical ways because the matrix can be nD and also for optimization purpose in the case of iteration.
As explained in my book, this data-structure is a model of the Function concept represented that

\[ \begin{matrix} f\colon \mathcal{D}\subset E & \to& F \\ x & \mapsto& y = f(x) \end{matrix} \]

such that the input quantity completely determines the output quantity. The input quantity belongs to a space $E$ and the output to the space $F$ and $\mathcal{D}$ a subset of $E$ that is the domain of definition of the function. In this model, $E$ is VecN<Dim,int>, $F$ is pixel/voxel type and $\mathcal{D}$ is VecN<Dim,int>.

Constructor

The construction of an object requires the domain of the definition that is the number of rows and columns in 2D MatN(int sizei,int sizej) or MatN(const VecN<DIM,int> & domain). For instance, this code:

Mat2UI8 img(3,2);//construct an matrix with 3 rows and 2 columns
Vec2I32 domain(3,2);
Mat2UI8 img(domain);//construct an matrix with 3 rows and 2 columns

Object function to access element

The matrix access of the pixel/voxel value, f(i,j) or f(x=(i,j)), is called as if it were an ordinary function operator ()(int i, int j) or operator ()(const E & x). The first one is the simplest one but less generic. For instance, this code

Mat2UI8 img(2,3);//construct an matrix with 3 columns and 2 rows
img(1,2)=255;//set the pixel value at 255
std::cout<<img;

produces this output:
0 0 0
0 0 255
In similarly way, this code:

Vec2I32 x(2,3);
Mat2UI8 img(x);//construct an matrix with 3 columns and 2 rows
x(0)=1;
x(1)=2;
img(x)=255;//set the pixel value at 255
std::cout<<img;

produces the same output.

Iteration

We have two major categories of iterative loops: through the domain and through the neighborhood.

Iterared over all points of the domain

This class provides four ways for the iterative loops on the domain: $ \forall x \in \mathcal{D}$. Each time, we illustrate with a code generating an matrix with a constant value:

The first one is the simplest one but less generic than the second one independant of the space. The last one is more optimized but you lost the point position that can be required for the subsequent process as in the erosion algorithm.

Iterared over all points on a neighborhood of a point

This class provides two ways for the iterative loops on a point neighborhood: $ \forall x' \in N(x)$.

The abstraction with IteratorENeighborhood concept provides an efficient and generic ways to iterate through a neighborhood (see this tutorial Template progamming ).

Load/Save

You have many information in this tutorial Load/save .

The implementation of these methods are Included in the hedader MatNInOut.h. So do not forget to Include "#include"data/mat/MatNInOut.h" to avoid a such error message "undefined reference to "'pop::MatN<2, unsigned char>::save(char const*) const'". You can load/save various matrix formats, png, pgm, jpg, bmp. , the naturel format is pgm. To load/save a stack of matrices, you can use MatN::loadFromDirectory or MatN::saveFromDirectory. However, I extend the pgm format to directly save a 3D matrix in a single file.

Display

You have many information in these tutorials 2d visualization 3d visualization.

In good architectur design, the data and its representation are separeted in two classes. However for conveniency, you provide the member display() in this data class for simple display and you provide the MatNDisplay class for extended display.

See also
VecN RGB Complex MatNDisplay

Member Typedef Documentation

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::Domain

Domain type that is VecN<Dim,int>

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::E

E=VecN<Dim,int> for the pixel/voxel localization

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::F

Pixel/voxel type

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::iterator

Stl iterator (vector::iterator)

See also
begin() end()
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::IteratorEDomain

This iterator allows the iteration through all elements of E in order to pick up one time and only one time each element of E without any order. The corresponding mathematical object is : $\forall x \in \mathcal{D} $. This iterator does not impose more requirements than IteratorE concept pattern. Its construction requires a domain of definition as argument given by the member getIteratorEDomain() of this class. Its member next() advances to the next element in returning a boolean to indicate if the end of the collection is reached. Its member x() returns the current element x.

For intance, to define an ouput matrix as follows:
$ \forall x \in \mathcal{D} : h(x) = f(x)+v$
we can write this code:

Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8::IteratorEDomain it(img.getIteratorEDomain());
Mat2UI8::F v =100;
FunctorF::FunctorAdditionF2<UI8,UI8,UI8> op;
while(it.next()){
img(it.x()) = op(img(it.x()),v);
}
img.save("lenaaddconst.pgm");

produce this matrix

lenaadd.jpg
See also
getIteratorEDomain
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::IteratorENeighborhood

This iterator allows the iteration through the neighborhood of an element x of E without any order. The corresponding mathematical object is : $\forall x' \in N(x)$. This iterator plays an important role in algorithms of mathematical morphology and region growing. Its construction requires a domain of definition as argument given by the member getIteratorENeighborhood(F32 radius,F32 norm). $N(x) =\{\forall x' \in \mathcal{D} : \|x'-x\|_{norm} \leq radius \}$, for instance for norm=1, radius=1 and dim=2 N(x=(i,j)) is equal to {(i,j),(i-1,j),(i+1,j),(i,j-1),(i,j+1)} that is the 4-connectivity. Its member next() advances to the next element in returning a boolean to indicate if the end of the collection is reached. Its member x() returns the current element x. Its member init(const E & x) initializes the iteration on the neighborhood of the VecN x.

For intance, the erosion is:
$ \forall x \in \mathcal{D} : h(x) = \min_{\forall x'\in N(x) }f(x')$
we can write this code:

Mat2RGBUI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2RGBUI8 img_erosion(img.getDomain());
Mat2RGBUI8::IteratorEDomain it_total(img.getIteratorEDomain());
F32 norm =2;
F32 radius =4.5;
Mat2RGBUI8::IteratorENeighborhood it_neigh(img.getIteratorENeighborhood(radius,norm));
while(it_total.next()){
Mat2RGBUI8::F mini(255);
it_neigh.init(it_total.x());MatN
while(it_neigh.next()){
mini = min(mini, img(it_neigh.x()));
}
img_erosion(it_total.x()) = mini;
}
img_erosion.save("/home/vincent/Desktop/_.bmp");

produce this matrix

lenaero.jpg
See also
RGB getIteratorENeighborhood
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::IteratorERectangle

Iterate in rectangle

Mat2UI8 img2;
img2.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8::IteratorERectangle itrec = img2.getIteratorERectangle(Vec2I32(50,200),Vec2I32(500,300));
Mat2UI8::IteratorENeighborhood itloc =img2.getIteratorENeighborhood(3,2);
img2 = maximum(img2,ProcessingAdvanced::dilation(img2,itrec,itloc));
img2.display();
lenadilarec.png
See also
getIteratorERectangle
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::IteratorEROI

This iterator allows the iteration through all elements of subset E called a Region Of Interest (ROI) in order to pick up one time and only one time each element of this subset without any order. The corresponding mathematical object is : $\forall x \in \mathcal{D}' $. This iterator does not impose more requirements than IteratorE concept pattern. Its construction requires a domain of definition as argument given by the member getIteratorEROI() of this class. Its member next() advances to the next element in returning a boolean to indicate if the end of the collection is reached. Its member x() returns the current element x.

For intance, to define an ouput matrix as follows:
$ \forall x \in \mathcal{D}'=\{x\in \mathcal{D}:mask(x)\neq 0\} : h(x) = f(x)+v$
we can write this code:

Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8 mask;
mask.load("mask.pgm");
Mat2UI8::IteratorEROI it(mask.getIteratorEROI());
Mat2UI8::F addvalue =100;
FunctorF::FunctorAdditionF2<UI8,UI8,UI8> op;
while(it.next()){
img(it.x()) = op(img(it.x()),addvalue);
}
img.save("lenaaddconstROI.pgm");

The mask matrix is as follows:

roi.jpg

and the lenaaddconstROI matrix is as follows:

lenaroi.jpg
See also
getIteratorEROI

Member Enumeration Documentation

template<int Dim, typename PixelType>
anonymous enum
Enumerator
DIM 

Space dimension

Constructor & Destructor Documentation

template<int Dim, typename PixelType >
pop::MatN< Dim, PixelType >::MatN ( )

default constructor

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const VecN< Dim, int > &  domain,
PixelType  v = PixelType() 
)
explicit
Parameters
domaindomain of definition
vinit pixel/voxel value

construct an matrix of size domain(0),domain(1) for 2D matrix and domain(0),domain(1),domain(2) for 3D matrix where each pixel/voxel value is set at 0.
This code:

Vec2I32 x;
x(0)=2;
x(1)=4;
Mat2UI8 img(x);
x(0)=1;x(1)=1;
img(x)=255;
std::cout<<img;

produce this output

0 0 0 0
0 255 0 0
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( unsigned int  sizei,
unsigned int  sizej 
)
explicit
Parameters
sizeinumber of columns
sizejnumber of rows

construct an matrix of size i,j where each pixel/voxel value is set at 0
This code:

Mat2UI8 img(2,4);
Vec2I32 x;
x(0)=1;x(1)=1;
img(x)=255;
std::cout<<img;

produce this output

0 0 0 0
0 255 0 0
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( unsigned int  sizei,
unsigned int  sizej,
unsigned int  sizek 
)
explicit
Parameters
sizeinumber of columns
sizejnumber of rows
sizeknumber of depths

construct an matrix of size i,j,k where each pixel/voxel value is set at 0

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const VecN< Dim, int > &  x,
const Vec< PixelType > &  data_values 
)
explicit
Parameters
xdomain size of the matrix
data_valuesvalue of each pixel/voxel

construct an matrix of size domain(0),domain(1) for 2D matrix and domain(0),domain(1),domain(2) for 3D matrix where each pixel/voxel is set by the values contained in the Vec
This code:

x(0)=2;
x(1)=4;
Vec<Mat2UI8::F> v;
v.push_back(0);v.push_back(1);v.push_back(2);v.push_back(3);
v.push_back(3);v.push_back(2);v.push_back(1);v.push_back(0);
Mat2UI8 img(x,v);
std::cout<<img;

produce this output

0 1 2 3
3 2 1 0
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const VecN< Dim, int > &  x,
const PixelType *  v_value 
)
explicit
Parameters
xdomain size of the matrix
v_valueaffection values for the matrix elements
UI8 _A[]={1,1,1,1,1,
1,0,0,0,1,
1,0,0,0,1,
1,1,1,1,1,
1,0,0,0,1,
1,0,0,0,1,
1,0,0,0,1
};
Mat2UI8 LetterA(Vec2I32(7,5),_A);
cout<<LetterA<<endl;
template<int Dim, typename PixelType >
template<typename T1 >
pop::MatN< Dim, PixelType >::MatN ( const MatN< Dim, T1 > &  img)
Parameters
imgobject to copy

copy construct
This code:

x(0)=2;
x(1)=4;
Vec<Mat2UI8::F> v;
v.push_back(0);v.push_back(1);v.push_back(2);v.push_back(3);
v.push_back(3);v.push_back(2);v.push_back(1);v.push_back(0);
Mat2UI8 img1(x,v);
Mat2UI8 img2(img1);
std::cout<<img1;

produce this output

0 1 2 3
3 2 1 0
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const MatN< Dim, PixelType > &  img)
Parameters
imgobject to copy

copy construct
This code:

x(0)=2;
x(1)=4;
Vec<Mat2UI8::F> v;
v.push_back(0);v.push_back(1);v.push_back(2);v.push_back(3);
v.push_back(3);v.push_back(2);v.push_back(1);v.push_back(0);
Mat2UI8 img1(x,v);
Mat2UI8 img2(img1);
std::cout<<img1;

produce this output

0 1 2 3
3 2 1 0
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const Mat2x< PixelType, 2, 2 >  m)
Parameters
msmall 2d matrix of size (2,2)

type conversion

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const Mat2x< PixelType, 3, 3 >  m)
Parameters
msmall 2d matrix of size (3,3)

type conversion

template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const char *  filepath)
Parameters
filepathpath of the matrix

construct the matrix from an matrix file

Mat2UI8 img((POP_PROJECT_SOURCE_DIR+std::string("/image/Lena.bmp")).c_str());
img.display();
template<int Dim, typename PixelType>
pop::MatN< Dim, PixelType >::MatN ( const MatN< Dim, PixelType > &  img,
const VecN< Dim, int > &  xmin,
const VecN< Dim, int > &  xmax 
)
Parameters
imgbigger matrix
xmininclusive lower bound
xmaxexclusive upper bound

construct a matrix for a part of the bigger matrix

in 2D

Mat3UI8 img2;
img2.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8 img3 (img2,Vec2I32(300,200),Vec2I32(400,400));
img3.display();

in 3D

Mat3UI8 img2;
img2.load("/home/vincent/Desktop/work/Population/image/rock3d.pgm");
Mat3UI8 smallcube(img2,Vec3I32(29,67,20),Vec3I32(159,167,200));
smallcube.display();

Member Function Documentation

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::clear ( )

clear the content of the matrix

template<int DIM, typename PixelType >
PixelType pop::MatN< DIM, PixelType >::cofactor ( unsigned int  i,
unsigned int  j 
) const
Parameters
irow entry
jcolumn entry

the cofactor of a matrix minor A is the minor determinant multiply by $(-1)^{i+j}$

See also
minorDet(int i, int j)const
template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::cofactor ( ) const

the matrix of cofactors is the matrix whose (i,j) entry is the cofactor C_{i,j} of A

See also
cofactor(int i, int j)const
template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::columns ( ) const
Returns
number of columns

return the number of columns

template<int Dim, typename PixelType >
PixelType * pop::MatN< Dim, PixelType >::data ( )

Return a ptr to the first pixel value

Exception direct access to the matrix data that can be usefull for optimized purposes

template<int Dim, typename PixelType >
const PixelType * pop::MatN< Dim, PixelType >::data ( ) const

Return a ptr to the first pixel value

direct access to the matrix data that can be usefull for optimized purposes

template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::deleteCol ( unsigned int  j) const
Parameters
jcolumn entry

delete the column of index j

template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::deleteRow ( unsigned int  i) const
Parameters
irow entry

delete the row of index i

template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::depth ( ) const
Returns
number of depths

return the number of depths

template<int DIM, typename PixelType >
PixelType pop::MatN< DIM, PixelType >::determinant ( ) const

the determinant is a value associated with a square matrix f wiki

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::display ( const char *  title = "",
bool  stoprocess = true,
bool  automaticresize = true 
) const
Parameters
titlewindows title
stoprocessfor stoprocess=true, stop the process until the windows is closed, otherwise the process is still running
automaticresizefor automaticresize=true, you scale the matrix before the display, we do nothing otherwise

Display the matrix using the CIMG facility.

Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
img.display();
Mat2F32 gradx(img);
gradx = pop::Processing::gradientDeriche(gradx,0,0.5);
gradx = pop::Processing::greylevelRange(gradx,0,255);//to display the matrix with a float type, the good thing is to translate the grey-level range between [0-255] before
gradx.display();

display the matrix

template<int Dim, typename PixelType >
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::divTermByTerm ( const MatN< Dim, PixelType > &  f)
Parameters
fmatrix
Returns
output matrix

division term by term h(x)= (*this)(x)/f(x) (to avoid the the confusion with the matrix division, we use this signature)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::fill ( PixelType  value)
Parameters
valuevalue
Returns
this matrix

Basic assignement of all pixel/voxel values by value

template<int DIM, typename PixelType >
Vec< PixelType > pop::MatN< DIM, PixelType >::getCol ( unsigned int  j) const
Parameters
jcolumn entry
Returns
the column in a Vec

the output Vec contained the column at the given index j

See also
Vec
template<int Dim, typename PixelType >
MatN< Dim, PixelType >::Domain pop::MatN< Dim, PixelType >::getDomain ( ) const
Returns
Domain domain of definition

return domain of definition of the matrix

See also
VecN
template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorEDomain pop::MatN< Dim, PixelType >::getIteratorEDomain ( ) const
Returns
total iterator

return the total iterator of the matrix that will iterate through the domain + x

template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorENeighborhood pop::MatN< Dim, PixelType >::getIteratorENeighborhood ( F32  radius = 1,
int  norm = 1 
) const
Parameters
radiusball radius
normball norm
Returns
Neighborhood iterator

The neighborhood is defined using the iterative stuctural element, $S^n$,
The initial stuctural element $S= \{x :\mbox{structural}(x-center)\neq 0\}$ with center the center domain of the matrix.
For instance, with structural= $\begin{pmatrix} 0 & 0 & 0\\0 & 255 & 255\\0 & 255 & 0\end{pmatrix}$, we have $ S=\{(0,0),(1,0),(0,1)\}$.
The iterative stuctural element, $S^n$ is n times the mean by itselt : $ S\oplus S\ldots \oplus S$ n times. For instance, return the Neighborhood iterator domain of the matrix as argument of the IteratorENeighborhood constructor with the given norm and radiu

See also
IteratorENeighborhood
template<int Dim, typename PixelType >
template<typename Type1 >
MatN< Dim, PixelType >::IteratorENeighborhood pop::MatN< Dim, PixelType >::getIteratorENeighborhood ( const MatN< Dim, Type1 > &  structural_element,
int  dilate = 1 
) const
Parameters
structural_elementstructural element
dilatenumber of dilation of the structural element
Returns
Neighborhood iterator
Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8 S(3,3);
S(1,1)=255;S(2,2)=255;
Mat2UI8::IteratorENeighborhood itn(img.getIteratorENeighborhood(S,20));
Mat2UI8::IteratorEDomain itg(img.getIteratorEDomain());
Mat2UI8 ero(img.getDomain());
while(itg.next()){
UI8 value = 255;
itn.init(itg.x());
while(itn.next()){
value = min(value, img(itn.x()));
}
ero(itg.x())=value;
}
ero.display();
See also
IteratorENeighborhood
template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorENeighborhoodAmoebas pop::MatN< Dim, PixelType >::getIteratorENeighborhoodAmoebas ( F32  distance_max = 4,
F32  lambda_param = 0.01 
) const

Amoeabas kernel.

Parameters
distance_maxmaximum distance
lambda_paramparameter of ameaba distance
Returns
Neighborhood iterator

R. Lerallut, E. Decenciere, and F. Meyer. Image filtering using morphological amoebas. Image and Vision Computing, 25(4), 395–404 (2007)

Mat2UI8 m;
m.load("../doc/image/plate.jpg");
m.display("init",false);
Mat2UI8::IteratorENeighborhoodAmoebas it_local = m.getIteratorENeighborhoodAmoebas(6,0.01);
Mat2UI8::IteratorEDomain it_global = m.getIteratorEDomain();
Mat2UI8 m_median = ProcessingAdvanced::median(m,it_global,it_local);
m_median.display();
plate.jpg
initial image
plate_median_classic.jpg
median filter with fixed kernel
plate_median_amoeba.jpg
median filter with ameaba kernel
template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorEOrder pop::MatN< Dim, PixelType >::getIteratorEOrder ( int  coordinatelastloop = 0,
int  direction = 1 
) const
Parameters
coordinatelastloopcoordinate of the last loop of iteratation
direction1=0 to N , otherwise N to 0
Returns
order iterator

Iteration through to the domain of definition such the last loop of iteration is given by the coordinate and the way of iteration by the direction.
For instance in 2D,

Mat2UI8 m(512,256);
Mat2UI8::IteratorEOrder it (0,-1);
while(it.next()){
// do something
}
// this code os equivalent to
for(unsigned int j=0;j<m.sizeJ();j++)
for(unsigned int i=m.sizeJ()-1;i>=0;i++){// last loop is the 0-cooridnate in reverse ways
// do something
}
template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorERectangle pop::MatN< Dim, PixelType >::getIteratorERectangle ( const E xmin,
const E xmax 
) const
Parameters
xmintop left corner
xmaxbuttom right corner
Returns
Rectangle iterator

Iteration through to the rectangle define by these two points [xmin,xmax].
For instance in 2D,

Mat2UI8 m(1024,512);
Mat2UI8::IteratorERectangle it(m.getIteratorERectangle(Vec2I32(100,200),Vec2I32(102,201)));
while(it.next()){
std::cout<<it.x()<<std::endl;
}

produce this output 100

200


101

200


102

200


100

201


101

201


102

201

template<int Dim, typename PixelType >
MatN< Dim, PixelType >::IteratorEROI pop::MatN< Dim, PixelType >::getIteratorEROI ( ) const
Returns
ROI iterator

return the ROI iterator of the matrix where the iteration is done on pixel/voxel values different to 0.

template<int DIM, typename PixelType >
Vec< PixelType > pop::MatN< DIM, PixelType >::getRow ( unsigned int  i) const
Parameters
irow entry
Returns
the row in a Vec

the output Vec contained the row at the given index i

See also
Vec
template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::identity ( int  size_mat = 0) const

$I_n = \begin{bmatrix}1 & 0 & \cdots & 0 \\0 & 1 & \cdots & 0 \\\vdots & \vdots & \ddots & \vdots \\0 & 0 & \cdots & 1 \end{bmatrix}$

Parameters
size_matsize of the output matrix
Returns
Identity matrix

Generate the identity matrix or unit matrix of square matrix with the given size for size!=0 or this matrix size with ones on the main diagonal and zeros elsewhere

template<int Dim, typename PixelType >
PixelType pop::MatN< Dim, PixelType >::interpolationBilinear ( const VecN< DIM, F32 xf) const
Parameters
xfvector position in float value
Returns
pixel/voxel value

access the interpolated pixel/voxel value at the float position

template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::inverse ( ) const
Returns
matrix reference

the inverse of the matrix wiki

Mat2F32 m(3,3);
m(0,0)=1;m(0,1)=1;m(0,2)=2;
m(1,0)=2;m(1,1)=1;m(1,2)=2;
m(2,0)=1;m(2,1)=3;m(2,2)=3;
Mat2F32 minverse;
minverse = m.inverse();
std::cout<<minverse<<std::endl;
std::cout<<m*minverse<<std::endl;

For large matrix, you should use LinearAlgebra::inverseGaussianElimination()

template<int Dim, typename PixelType >
bool pop::MatN< Dim, PixelType >::isEmpty ( ) const
Returns
true if matrix is empty

return true if the the matrix empty

template<int Dim, typename PixelType >
bool pop::MatN< Dim, PixelType >::isValid ( const E x) const
Parameters
xVecN
Returns
boolean

return true if the VecN belongs to the domain, false otherwise

template<int Dim, typename PixelType >
bool pop::MatN< Dim, PixelType >::isValid ( int  i,
int  j 
) const
Parameters
ii coordinate of the VecN
jj coordinate of the VecN
Returns
boolean

return true if the VecN (i,j) belongs to the domain, false otherwise

template<int Dim, typename PixelType >
bool pop::MatN< Dim, PixelType >::isValid ( int  i,
int  j,
int  k 
) const
Parameters
ii coordinate of the VecN
jj coordinate of the VecN
kk coordinate of the VecN
Returns
boolean

return true if the VecN (i,j,k) belongs to the domain, false otherwise

template<int Dim, typename PixelType>
bool pop::MatN< Dim, PixelType >::load ( const char *  file)
Parameters
fileinput file
Returns
true in case of success

The loader attempts to read the matrix using the specified format. Natively, this library support the pgm, png, jpg, bmp formats. However thanks to the CImg library, this library can read various matrix formats http://cimg.sourceforge.net/reference/group__cimg__files__io.html if you install Image Magick http://www.imagemagick.org/script/binary-releases.php.

template<int Dim, typename PixelType >
bool pop::MatN< Dim, PixelType >::load ( const std::string  file)
Parameters
fileinput file
Returns
true in case of success
See also
MatN::load(const char * file)
template<int Dim, typename PixelType>
void pop::MatN< Dim, PixelType >::loadFromDirectory ( const char *  pathdir,
const char *  basefilename = "",
const char *  extension = "" 
)
Parameters
pathdirdirectory path
basefilenamefilename base by default "toto"
extensionby default ".pgm"

The loadFromDirectory attempts to load all files as 2d slices of the 3D matrix in the directory pathdir. If the extension is set, we filter all filter all files with the extension. It is the same for basename.
For instance, this code produces:

Mat3UI8 img;
img.loadFromDirectory("/home/vincent/Desktop/WorkSegmentation/lavoux/","in","tiff");
img.display();
img.save("lavoux3d.pgm");
template<int Dim, typename PixelType>
bool pop::MatN< Dim, PixelType >::loadRaw ( const char *  file,
const Domain d 
)
Parameters
fileinput file
ddomain of definition of the image
Returns
true in case of success

The loader attempts to read the 3d raw matrix. The voxel type of the matrix must be the same as in raw file and, in more, you need to give the domain (size) of the image in the raw file.
For instance, if the voxel is coded in 1 byte, you write the following code

Mat3UI8 menisque;
Vec3I32 d(1300,1500,401);//matriciel notation, so 1300 raw, 1500 columns and 401 depth
menisque.loadRaw("/home/vincent/Downloads/top_cap_1300_1500_401_1b.raw",d);//load the 3d raw matrix
template<int DIM, typename PixelType >
PixelType pop::MatN< DIM, PixelType >::minorDet ( unsigned int  i,
unsigned int  j 
) const
Parameters
irow entry
jcolumn entry

the minor of a matrix A is the determinant of the smaller square matrix, cut down from A by removing the i row and the j column.

template<int Dim, typename PixelType >
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::multTermByTerm ( const MatN< Dim, PixelType > &  f) const
Parameters
fmatrix
Returns
output matrix

multTermByTerm h(x)= (*this)(x)*f(x) (to avoid the the confusion with the matrix multiplication, we use this signature)

template<int Dim, typename PixelType>
bool pop::MatN< Dim, PixelType >::operator!= ( const MatN< Dim, PixelType > &  f) const
Parameters
finput matrix
Returns
boolean

Difference operator true for at least on x in E f(x)!=(*this)(x), false otherwise

template<int Dim, typename PixelType >
PixelType & pop::MatN< Dim, PixelType >::operator() ( const VecN< Dim, int > &  x)
inline
Parameters
xpixel/voxel position
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the given position

Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8::IteratorEDomain it(img.getIteratorEDomain());
Distribution d(0,20,"NORMAL");
FunctorF::FunctorAdditionF2<Mat2UI8::F,F32,Mat2UI8::F> op;
while(it.next()){
img(it.x())=op(img(it.x()),d.randomVariable());//access a VecN, add a random variable and set it
}
img.display();
See also
VecN
template<int Dim, typename PixelType >
const PixelType & pop::MatN< Dim, PixelType >::operator() ( const VecN< Dim, int > &  x) const
inline
Parameters
xpixel/voxel position
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the given position

Mat2UI8 img;
img.load((std::string(POP_PROJECT_SOURCE_DIR)+"/image/Lena.bmp").c_str());
Mat2UI8::IteratorEDomain it(img.getIteratorEDomain());
Distribution d(0,20,"NORMAL");
FunctorF::FunctorAdditionF2<Mat2UI8::F,F32,Mat2UI8::F> op;
while(it.next()){
img(it.x())=op(img(it.x()),d.randomVariable());//access a VecN, add a random variable and set it
}
img.display();
See also
VecN
template<int Dim, typename PixelType >
PixelType & pop::MatN< Dim, PixelType >::operator() ( unsigned int  i,
unsigned int  j 
)
inline
Parameters
ii coordinate (row)
jj coordinate (column)
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the position (i,j) for a 2D matrix

template<int Dim, typename PixelType >
const PixelType & pop::MatN< Dim, PixelType >::operator() ( unsigned int  i,
unsigned int  j 
) const
inline
Parameters
ii coordinate (row)
jj coordinate (column)
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the position (i,j) for a 2D matrix

template<int Dim, typename PixelType >
PixelType & pop::MatN< Dim, PixelType >::operator() ( unsigned int  i,
unsigned int  j,
unsigned int  k 
)
inline
Parameters
ii coordinate (row)
jj coordinate (column)
kk coordinate (depth)
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the given position (i,j,k) for a 3D matrix

template<int Dim, typename PixelType >
const PixelType & pop::MatN< Dim, PixelType >::operator() ( unsigned int  i,
unsigned int  j,
unsigned int  k 
) const
inline
Parameters
ii coordinate (row)
jj coordinate (column)
kk coordinate (depth)
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the given position (i,j,k) for a 3D matrix

template<int Dim, typename PixelType >
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator() ( const VecN< Dim, int > &  xmin,
const VecN< Dim, int > &  xmax 
) const
Parameters
xmininclusive lower bound
xmaxexclusive upper bound

extracts a rectangular sub-matrix

Mat2UI8 img;
img.load("/usr/share/doc/opencv-doc/examples/c/lena.jpg");
img = img(Vec2I32(100,100),Vec2I32(400,300));
img.display();
template<int Dim, typename PixelType >
PixelType & pop::MatN< Dim, PixelType >::operator() ( unsigned int  index)
Parameters
indexvector index
Returns
pixel/voxel value

access the reference of the pixel/voxel value at the vector index (Vec contains pixel values)

template<int Dim, typename PixelType >
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator* ( const MatN< Dim, PixelType > &  m) const
Parameters
mother matrix
Returns
output matrix

matrix multiplication see http://en.wikipedia.org/wiki/Matrix_multiplication

Mat2F32 m1(2,3);
m1(0,0)=1; m1(0,1)=2; m1(0,2)=0;
m1(1,0)=4; m1(1,1)=3; m1(1,2)=-1;
Mat2F32 m2(3,2);
m2(0,0)=5; m2(0,1)=1;
m2(1,0)=2; m2(1,1)=3;
m2(2,0)=3; m2(2,1)=4;
Mat2F32 m3 = m1*m2;
std::cout<<m3<<std::endl;
template<int Dim, typename PixelType>
Vec< PixelType > pop::MatN< Dim, PixelType >::operator* ( const Vec< PixelType > &  v) const
Parameters
vvector
Returns
output vector

matrix vector multiplication

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator* ( PixelType  value) const
Parameters
valueinput value
Returns
object

Multiplication h(x)= (*this)(x)*value

template<int Dim, typename PixelType >
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator*= ( const MatN< Dim, PixelType > &  m)
Parameters
mother matrix
Returns
output matrix

matrix multiplication see http://en.wikipedia.org/wiki/Matrix_multiplication

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator*= ( PixelType  value)
Parameters
valueinput value
Returns
object reference

Multiplication assignment h(x)*=value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator+ ( const MatN< Dim, PixelType > &  f) const
Parameters
finput matrix
Returns
object

Addition h(x)= (*this)(x)+f(x)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator+ ( PixelType  value) const
Parameters
valueinput value
Returns
object

Addition h(x)= (*this)(x)+value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator+= ( const MatN< Dim, PixelType > &  f)
Parameters
finput matrix
Returns
object reference

Addition assignment h(x)+=f(x)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator+= ( PixelType  value)
Parameters
valueinput value
Returns
object reference

Addition assignment h(x)+=value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator- ( const MatN< Dim, PixelType > &  f) const
Parameters
finput matrix
Returns
output matrix

Subtraction h(x)= (*this)(x)-f(x)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator- ( ) const
Returns
output matrix

opposite h(x)= -this(x)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator- ( PixelType  value) const
Parameters
valueinput value
Returns
output matrix

Subtraction h(x)= (*this)(x)-value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator-= ( const MatN< Dim, PixelType > &  f)
Parameters
finput matrix
Returns
object reference

Subtraction assignment h(x)-=f(x)

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator-= ( PixelType  value)
Parameters
valueinput value
Returns
object reference

Subtraction assignment h(x)-=value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::operator/ ( PixelType  value) const
Parameters
valueinput value
Returns
object

Division h(x)= (*this)(x)/value

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator/= ( PixelType  value)
Parameters
valueinput value
Returns
object reference

Division assignment h(x)/=value

template<int Dim, typename PixelType>
template<class T1 >
MatN& pop::MatN< Dim, PixelType >::operator= ( const MatN< Dim, T1 > &  img)
Parameters
imgother matrix
Returns
this matrix

Basic assignement of this matrix by other

template<int Dim, typename PixelType >
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator= ( const MatN< Dim, PixelType > &  img)
Parameters
imgother matrix
Returns
this matrix

Basic assignement of this matrix by other

template<int Dim, typename PixelType>
MatN< Dim, PixelType > & pop::MatN< Dim, PixelType >::operator= ( PixelType  value)
Parameters
valuevalue
Returns
this matrix

Basic assignement of all pixel/voxel values by value

template<int Dim, typename PixelType>
bool pop::MatN< Dim, PixelType >::operator== ( const MatN< Dim, PixelType > &  f) const
Parameters
finput matrix
Returns
boolean

Equal operator true for all x in E f(x)=(*this)(x), false otherwise

template<int Dim, typename PixelType >
MatN< Dim, PixelType > pop::MatN< Dim, PixelType >::opposite ( int  mode = 0) const
Parameters
modemode by default 0
Returns
opposite matrix

opposite of the matrix h(x)=max(f::F)-f(x) with max(f::F) is the maximum value of the range defined by the pixel/voxel type for mode =0,
or h(x)=max(f)-f(x) with max(f) is the maximum value of the field for mode =1

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resize ( unsigned int  sizei,
unsigned int  sizej 
)
Parameters
sizeirow size
sizejcoloumn size

resize the matrix in loosing the data information

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resize ( unsigned int  sizei,
unsigned int  sizej,
unsigned int  sizek 
)
Parameters
sizeirow size
sizejcol size
sizekdepth size

resize the matrix in loosing the data information

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resize ( const VecN< Dim, int > &  d)
Parameters
ddomain =Vec2(i,j) in 2d and domain =Vec3(i,j,k) in 3d

resize the matrix in loosing the data information

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resizeInformation ( unsigned int  sizei,
unsigned int  sizej 
)
Parameters
sizeirow size
sizejcoloumn size

resize the matrix in keeping the data information

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resizeInformation ( unsigned int  sizei,
unsigned int  sizej,
unsigned int  sizek 
)
Parameters
sizeirow size
sizejcolo size
sizekdepth size

resize the matrix in keeping the data information

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::resizeInformation ( const VecN< Dim, int > &  d)
Parameters
ddomain =Vec2(i,j) in 2d and domain =Vec3(i,j,k) in 3d

resize the matrix in keeping the data information

template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::rows ( ) const
Returns
number of rows

return the number of rows

template<int Dim, typename PixelType>
void pop::MatN< Dim, PixelType >::save ( const char *  file) const
Parameters
fileinput file

The saver attempts to write the matrix using the specified format. Natively, this library support the pgm, png, jpg, bmp format. However thanks to the CImg library, this library can save various matrix formats http://cimg.sourceforge.net/reference/group__cimg__files__io.html .

template<int Dim, typename PixelType >
void pop::MatN< Dim, PixelType >::save ( const std::string  file) const
Parameters
fileinput file
See also
MatN::save(const char * file)
template<int Dim, typename PixelType>
void pop::MatN< Dim, PixelType >::saveAscii ( const char *  file,
std::string  header = "" 
) const
Parameters
fileinput file
headerheader of the file

save the data in ascii format without header

template<int Dim, typename PixelType>
void pop::MatN< Dim, PixelType >::saveFromDirectory ( const char *  pathdir,
const char *  basefilename = "toto",
const char *  extension = ".pgm" 
) const
Parameters
pathdirdirectory path
basefilenamefilename base by default "toto"
extensionby default ".pgm"

The saveFromdirectory attempts to save Save all slices of the 3D matrix f in the directory pathdir with the given basefilename and the extenion,
for instance pathdir="/home/vincent/Project/ENPC/ROCK/Seg/" basefilename="seg" and extension=".bmp", will save the slices as follows
"/home/vincent/Project/ENPC/ROCK/Seg/seg0000.bmp",
"/home/vincent/Project/ENPC/ROCK/Seg/seg0001.bmp",
"/home/vincent/Project/ENPC/ROCK/Seg/seg0002.bmp"
"and so one.

template<int Dim, typename PixelType>
void pop::MatN< Dim, PixelType >::saveRaw ( const char *  file) const
Parameters
fileinput file

save the data in raw format without header

template<int DIM, typename PixelType >
void pop::MatN< DIM, PixelType >::setCol ( unsigned int  j,
const Vec< F > &  v 
)
Parameters
jcolumn entry
vVec

set the column at the given column entry with the given Vec of size equal to number of row

See also
Vec
template<int DIM, typename PixelType >
void pop::MatN< DIM, PixelType >::setRow ( unsigned int  i,
const Vec< F > &  v 
)
Parameters
irow entry
vVec

set the row at the given row entry with the given Vec of size equal to number of column

See also
Vec
template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::sizeI ( ) const
Returns
number of rows

return the number of rows

template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::sizeJ ( ) const
Returns
number of columns

return the number of columns

template<int Dim, typename PixelType >
unsigned int pop::MatN< Dim, PixelType >::sizeK ( ) const
Returns
int sizek

return the number of depths

template<int DIM, typename PixelType >
void pop::MatN< DIM, PixelType >::swapCol ( unsigned int  j_0,
unsigned int  j_1 
)
Parameters
j_0column entry
j_1column entry

swap the columns

template<int DIM, typename PixelType >
void pop::MatN< DIM, PixelType >::swapRow ( unsigned int  i_0,
unsigned int  i_1 
)
Parameters
i_0row entry
i_1row entry

swap the rows

template<int DIM, typename PixelType >
PixelType pop::MatN< DIM, PixelType >::trace ( ) const
Returns
trace

the trace of an n-by-n square matrix A is defined to be the sum of the elements on the main diagonal

Mat2F32 m(3,3);
m(0,0)=1;m(0,1)=1;m(0,2)=2;
m(1,0)=2;m(1,1)=1;m(1,2)=2;
m(2,0)=1;m(2,1)=3;m(2,2)=3;
std::cout<<m.trace()<<std::endl;
template<int DIM, typename PixelType >
MatN< DIM, PixelType > pop::MatN< DIM, PixelType >::transpose ( ) const

the ith row, jth column element of transpose matrix is the jth row, ith column element of matrix:


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