|
latest version v1.9 - last update 24 Nov 2005 |
|
#include <ltiMatrix.h>
Inheritance diagram for lti::matrix< T >:


Public Types | |
| typedef T | value_type |
| typedef ipoint | size_type |
Public Member Functions | |
| matrix () | |
| matrix (const int rows, const int cols, const T &iniValue=T()) | |
| matrix (const int rows, const int cols, const T data[]) | |
| matrix (const ipoint &size, const T &iniValue=T()) | |
| matrix (const matrix< T > &other, const int fromRow=0, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32) | |
| matrix (const bool copyData, matrix< T > &other, const int fromRow=0, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32) | |
| matrix (const bool init, const int rows, const int cols) | |
| matrix (const bool init, const ipoint &size) | |
| matrix (const matrix< T > &other, const genericVector< int > &rows) | |
| virtual | ~matrix () |
| virtual const char * | getTypeName () const |
| vector< T > & | getRow (const int row) |
| const vector< T > & | getRow (const int row) const |
| vector< T > & | operator[] (const int row) |
| const vector< T > & | operator[] (const int row) const |
| vector< T > | getRowCopy (const int row) const |
| void | getRowCopy (const int row, vector< T > &theRow) const |
| vector< T > | getColumnCopy (const int col) const |
| void | getColumnCopy (const int col, vector< T > &theCol) const |
| vector< T > | getDiagonal () const |
| void | getDiagonal (vector< T > &diag) const |
| matrix< T > & | copy (const matrix< T > &other) |
| matrix< T > & | copy (const matrix< T > &other, const int fromRow, const int toRow=MaxInt32, const int fromCol=0, const int toCol=MaxInt32) |
| matrix< T > & | copy (const matrix< T > &other, const irectangle &window) |
| matrix< T > & | copy (const matrix< T > &other, const vector< int > &idx, bool rows=true) |
| template<class U> | |
| matrix< T > & | castFrom (const matrix< U > &other) |
| virtual mathObject * | clone () const |
| bool | prettyCloseTo (const matrix< T > &other, const T &tolerance) const |
| matrix< T > & | operator= (const matrix< T > &other) |
Apply Methods | |
Following methods are used to apply simple functions to each element of the vector. | |
| matrix< T > & | apply (T(*function)(T)) |
| matrix< T > & | apply (const matrix< T > &other, T(*function)(T)) |
| matrix< T > & | apply (T(*function)(const T &)) |
| matrix< T > & | apply (const matrix< T > &other, T(*function)(const T &)) |
| matrix< T > & | apply (const matrix< T > &other, T(*function)(const T &, const T &)) |
| matrix< T > & | apply (const matrix< T > &other, T(*function)(T, T)) |
| matrix< T > & | apply (const matrix< T > &a, const matrix< T > &b, T(*function)(const T &, const T &)) |
| matrix< T > & | apply (const matrix< T > &a, const matrix< T > &b, T(*function)(T, T)) |
Arithmetical Operations | |
| matrix< T > & | add (const matrix< T > &other) |
| matrix< T > & | add (const matrix< T > &a, const matrix< T > &b) |
| matrix< T > & | add (const T value) |
| matrix< T > & | add (const matrix< T > &other, const T value) |
| matrix< T > & | operator+= (const T value) |
| matrix< T > & | operator+= (const matrix< T > &other) |
| matrix< T > | operator+ (const matrix< T > &other) const |
| matrix< T > | operator+ (const T value) const |
| matrix< T > & | addScaled (const T b, const matrix< T > &other) |
| matrix< T > & | addScaled (const matrix< T > &matA, const T b, const matrix< T > &matB) |
| matrix< T > & | addScaled (const T a, const matrix< T > &first, const T b, const matrix< T > &second) |
| matrix< T > & | subtract (const matrix< T > &other) |
| matrix< T > & | subtract (const matrix< T > &a, const matrix< T > &b) |
| matrix< T > & | subtract (const T value) |
| matrix< T > & | subtract (const matrix< T > &other, const T value) |
| matrix< T > & | operator-= (const T value) |
| matrix< T > & | operator-= (const matrix< T > &other) |
| matrix< T > & | multiply (const matrix< T > &other) |
| matrix< T > & | multiply (const matrix< T > &first, const matrix< T > &second) |
| vector< T > & | multiply (const vector< T > &other, vector< T > &result) const |
| vector< T > & | multiply (vector< T > &srcdest) const |
| matrix< T > & | multiply (const T value) |
| matrix< T > & | multiply (const matrix< T > &other, const T value) |
| matrix< T > & | operator *= (const matrix< T > &other) |
| matrix< T > & | operator *= (const T value) |
| vector< T > & | leftMultiply (const vector< T > &vct, vector< T > &result) const |
| vector< T > & | leftMultiply (vector< T > &srcDest) const |
| matrix< T > & | leftMultiply (const matrix< T > &mat) |
| matrix< T > & | divide (const T value) |
| matrix< T > & | divide (const matrix< T > &other, const T value) |
| matrix< T > & | operator/= (const T value) |
| matrix< T > & | emultiply (const matrix< T > &other) |
| matrix< T > & | emultiply (const matrix< T > &a, const matrix< T > &b) |
| matrix< T > & | edivide (const matrix< T > &other) |
| matrix< T > & | edivide (const matrix< T > &a, const matrix< T > &b) |
| matrix< T > & | outerProduct (const vector< T > &a, const vector< T > &b) |
| matrix< T > & | transpose () |
| matrix< T > & | transpose (const matrix< T > &other) |
| T | sumOfElements () const |
| T | minimum () const |
| ipoint | getIndexOfMinimum () const |
| T | maximum () const |
| ipoint | getIndexOfMaximum () const |
| void | getExtremes (T &theMinimum, T &theMaximum) const |
| void | getIndexOfExtremes (point &theIdxMinimum, ipoint &theIdxMaximum) const |
| void | setIdentity (const T scale=T(1)) |
| T | trace () const |
Protected Member Functions | |
| virtual genericVector< T > * | allocRows (const int n) |
The lti::matrix class allows the representation of n x m matrices. The rows will be indexed between 0 and n-1, and the columns between 0 and m-1.
All types defined in ltiTypes.h use static members and can be contained by the lti::vector and lti::matrix classes.
The matrix class is a container class implemented as template.
If you need to create a matrix of floats with 20 rows and 15 columns, all elements initialized with an initial value of 4.27 just create it:
lti::matrix<float> myMat(20,15,4.27f) // creates matrix with 300 elements // all initialized with 4.27f
To access the matrix elements use the access operators. There are many possibilities. With at(const int row, const int col) is possible to access an element directly. With at(const int row) you can get the row vector. You cannot for instance resize nor change the memory referenced in this vector (see lti::vector::resize). For example:
float accu = 0; // initialize accumulator lti::matrix<float> myMat(20,15,4.27f) lti::vector<float> myVct; for (int j = 0; j < myMat.rows(); j++) { for (int i = 0; i < myMat.columns(); i++) { tmp += myMat.at(j,i); // access each element of the matrix: // j is the row and i the column } } myMat.getRowCopy(5,myVct); // copy the sixth row in myVct! myVct.resize(6); // Valid, the vector has its own memory! myMat.at(5).resize(6) // ERROR!! the vector is not resizable!
The image representation in the LTI-Lib is based on the lti::matrix class. It is quite confusing to use first the y-coordinate and then the x-coordinate to access the image elements. To avoid confusion use the lti::point class to access the elements of the matrix:
lti::channel8 aChannel(20,15); // creates an 8bit image lti::channel8::value_type tmp; // tmp is of the element type of the // channel8! lti::point p; for (p.y = 0; p.y < aChannel.rows(); p.y++) { for (p.x = 0; p.x < aChannel.columns(); p.x++) { tmp += aChannel.at(p); // access each element of the matrix: // equivalent to: tmp += aChannel.at(p.y,p.x)! } }
The matrix has following methods:
|
|||||
|
return type of the size() member
Reimplemented from lti::genericMatrix< T >. |
|
|||||
|
type of the contained data
Reimplemented from lti::genericMatrix< T >. |
|
|||||||||
|
default constructor creates an empty matrix
|
|
||||||||||||||||||||
|
this constructor creates a connected
|
|
||||||||||||||||||||
|
this constructor creates a connected
The first
|
|
||||||||||||||||
|
this constructor creates a connected
|
|
||||||||||||||||||||||||||||
|
copy constructor. create this matrix as a connected copy of another matrix for this const version, the data will be always copied! It is also possible to create a copy of a submatrix of another matrix.
lti::matrix<int> m(4,6,0); // integer matrix with 25 elements // ... // initialize Matrix with: // 0 1 2 3 4 5 // 2 1 5 4 0 3 // 1 2 1 2 3 2 // 3 3 2 1 2 3 lti::matrix<int> sm(m,0,2,1,3) // last line will lead to // following contents in sm: // 1 2 3 // 1 5 4 // 2 1 2 |
|
||||||||||||||||||||||||||||||||
|
copy constructor (reference to a submatrix). creates submatrix of another matrix.
if
if Those algorithms which use direct access to the matrix memory block should check first if the memory lies in a consecutive block! (see getMode())
|
|
||||||||||||||||||||
|
If init is true this constructor is equivalent to calling matrix(const int rows, const int cols), and thus initializing all elements with T(). However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large matrices, the unnecessary constructor initialization is very time consuming. If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent: matrix<int> a(false,100,100); matrix<int> a; a.resize(100,100,0,false,false);
|
|
||||||||||||||||
|
If init is true this constructor is equivalent to calling matrix(const int rows, const int cols), and thus initializing all elements with T(). However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large matrices, the unnecessary constructor initialization is very time consuming. If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent: matrix<int> a(false,100,100); matrix<int> a; a.resize(100,100,0,false,false);
|
|
||||||||||||||||
|
copy constructor.
create this matrix as a connected copy of another matrix taking only the rows indicated by the vector. for this const version, the data will be always copied! Multiple occurence of one row index in
lti::vector<int> rows(2); // initialize with // 1 3 lti::matrix<int> m(4,6,0); // integer matrix with 25 elements // ... // initialize Matrix with: // 0 1 2 3 4 5 // 2 1 5 4 0 3 // 1 2 1 2 3 2 // 3 3 2 1 2 3 lti::matrix<int> sm(m,rows) // last line will lead to // following contents in sm: // 2 1 5 4 0 3 // 3 3 2 1 2 3 |
|
|||||||||
|
destructor
|
|
||||||||||||||||
|
add constant value to the other matrix and leave result here.
|
|
||||||||||
|
add constant value to this matrix, and leave result here
|
|
||||||||||||||||
|
add matrices
|
|
||||||||||
|
add
|
|
||||||||||||||||||||||||
|
Leave the scaled sum of two matrices in this matrix.
The matrices must be of the same types and dimensions. Let
|
|
||||||||||||||||||||
|
Add a matrix A with a matrix B scaled by The matrices must be of the same types and dimensions. This method performs:
|
|
||||||||||||||||
|
Add another matrix scaled by
The matrices must be of the same types and dimensions. Let
|
|
||||||||||
|
Allocate n number of rows or the appropriate type.
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||||||||
|
a two-parameter C-function receives the i-th elements of both given matrices and leaves the result here. Note that both matrices must have the same size!
|
|
||||||||||||||||||||
|
a two-parameter C-function receives the i-th elements of both given matrices and leaves the result here. Note that both matrices must have the same size!
|
|
||||||||||||||||
|
a two-parameter C-function receives the i-th elements of this and the given matrix and the result will be left in this matrix. Note that both matrices must have the same size!
|
|
||||||||||||||||
|
a two-parameter C-function receives the i-th elements of this and the given matrix and the result will be left in this matrix. Note that both matrices must have the same size!
|
|
||||||||||||||||
|
applies a C-function to each element of the other matrix
|
|
||||||||||
|
applies a C-function to each element of the matrix.
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||||
|
applies a C-function to each element of the other matrix
|
|
||||||||||
|
applies a C-function to each element of the matrix.
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||
|
copy the
Reimplemented in lti::channel, lti::channel8, and lti::channel32. |
|
|||||||||
|
create a clone of this matrix
Reimplemented from lti::genericMatrix< T >. Reimplemented in lti::image, lti::channel, lti::channel8, lti::channel32, lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >. |
|
||||||||||||||||||||
|
assigment operator.
copy the contents of the specified rows/columns of The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
|
|
||||||||||||||||
|
assigment operator.
copy the contents of The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
|
|
||||||||||||||||||||||||||||
|
assigment operator.
copy the contents of The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
|
|
||||||||||
|
assigment operator.
copy the contents of The result of the copy is always a connected matrix. I.e. you cannot copy the sub-matrix property of another matrix.
|
|
||||||||||||||||
|
divide the elements of the other matrix by a constant value and leave the result here.
|
|
||||||||||
|
divide the elements of the matrix by a constant value, and leave the result here
|
|
||||||||||||||||
|
element-wise division of
|
|
||||||||||
|
element-wise division with other matrix
|
|
||||||||||||||||
|
element-wise multiplication of
|
|
||||||||||
|
element-wise multiplication with other matrix
|
|
||||||||||||||||
|
return genericMatrix-column as a vector. This method copies the data of the genericMatrix, therefore is not as fast as getRow()
|
|
||||||||||
|
return matrix-column as a vector. This method copies the data of the matrix, therefore is not as fast as getRow()
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||
|
Return the diagonal elements of the genericMatrix as vector. This method copies the diagonal elements of the genericMatrix into the vector. If the genericMatrix is non-symmetrical, the vector will be of dimension min(rows(),columns()).
|
|
|||||||||
|
Return the diagonal elements of the matrix as vector. This method copies the diagonal elements of the matrix into the vector. If the matrix is non-symmetrical, the vector will be of dimension min(rows(),columns()).
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||||
|
get the extremes of the matrix (smallest and biggest elements)
|
|
||||||||||||||||
|
get the indices of the extremes of the matrix (smallest and biggest elements)
|
|
|||||||||
|
get the index of the biggest element of the matrix
|
|
|||||||||
|
get the index of the smallest element of the matrix
|
|
||||||||||
|
return matrix-row as a const vector. This method works fast, since it returns a reference to the row vector. The data will NOT be copied.
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||
|
return matrix-row as a vector. This method works fast, since it returns a reference to the row vector. The data will NOT be copied.
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||||
|
Copy a row vector in the given parameter. This method copies the data of a given row of the genericMatrix in the given vector.
|
|
||||||||||
|
return matrix-row as a vector. This method copies the data of the matrix, therefore is not as fast as getRow()
Reimplemented from lti::genericMatrix< T >. |
|
|||||||||
|
returns the name of this class: "matrix"
Reimplemented from lti::genericMatrix< T >. Reimplemented in lti::image, lti::channel, lti::channel8, lti::channel32, lti::kernel2D< T >, lti::kernel2D< float >, and lti::kernel2D< ubyte >. |
|
||||||||||
|
multiply the matrix mat with this matrix, and leave the result in this matrix.
|
|
||||||||||
|
multiply the given vector The given vector will be interpreted as a row-vector (or a transposed column vector).
|
|
||||||||||||||||
|
multiply the vector The given vector will be interpreted as a row-vector (or a transposed column vector).
|
|
|||||||||
|
get the biggest element of the matrix
|
|
|||||||||
|
get the smallest element of the matrix
|
|
||||||||||||||||
|
multiply constant value with the other matrix and leave result here.
|
|
||||||||||
|
multiply constant value with this matrix, and leave result here
|
|
||||||||||
|
multiply this matrix with a vector and leave the result in same vector (In-Place Method) A reference to the vector is returned.
|
|
||||||||||||||||
|
multiply this matrix with a vector and leave the result in
A reference to
|
|
||||||||||||||||
|
multiply
|
|
||||||||||
|
multiply this matrix with The dimensions of this matrix will change if needed!
|
|
||||||||||
|
alias for multiply(const T& value)
|
|
||||||||||
|
alias for multiply(const matrix)
|
|
||||||||||
|
add constant value to this matrix, and leave result in a new matrix. This object is not changed.
|
|
||||||||||
|
add This object is not changed.
|
|
||||||||||
|
alias for add(const matrix)
|
|
||||||||||
|
alias for add(const T value)
|
|
||||||||||
|
alias for subtract(const matrix)
|
|
||||||||||
|
alias for subtract(const T value)
|
|
||||||||||
|
alias for divide(const T& value)
|
|
||||||||||
|
assigment operator (alias for copy(other)).
|
|
||||||||||
|
alias for getRow()
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||
|
alias for getRow()
Reimplemented from lti::genericMatrix< T >. |
|
||||||||||||||||
|
outer-product of two vectors.
The result will be left in this matrix. The dimensions of this matrix will change if needed. The outer product of two column vectors is defined as
|
|
||||||||||||||||
|
compare this matrix with other, and use the given tolerance to determine if the value of each element of the other matrix approximately equals the values of the actual matrix elements. An element x is approximately equal to another element y with a tolerance t, if following equation holds: x-t < y < x+t
|
|
||||||||||
|
Set the diagonal of this matrix to scale (default: 1), and all other elements to 0. If the matrix is square (which it need not be), this results in a scaled identity matrix. |
|
||||||||||||||||
|
subtract constant value from the other matrix and leave result here.
|
|
||||||||||
|
subtract constant value from this matrix, and leave result here
|
|
||||||||||||||||
|
subtract matrices
|
|
||||||||||
|
subtract
|
|
|||||||||
|
calculate the sum of all elements of the matrix. This member can be used with classes which define the operator '+=' Reimplemented in lti::channel8. |
|
|||||||||
|
returns the trace (i.e. the sum of the diagonal elements) of this matrix. If the matrix is not symmetrical, it will return the sum of all elements (i,i) with i from 0 to n-1; n being min(rows(),columns()) |
|
||||||||||
|
transpose the other matrix and leave the result here.
|
|
|||||||||
|
transpose matrix and leave the result here.
|