OpenCV: cv::MatExpr Class Reference

| OpenCV 3.4.2 Open Source Computer Vision

Public Member Functions | Public Attributes | List of all members
cv::MatExpr Class Reference
Core functionality » Basic structures

Matrix expression representation. More...

`#include "mat.hpp"`

## Public Member Functions
| MatExpr ()
| MatExpr (const Mat &m)
| MatExpr (const MatOp *_op, int _flags, const Mat &_a=Mat(), const Mat &_b=Mat(), const Mat &_c=Mat(), double _alpha=1, double _beta=1, const Scalar &_s=Scalar())
MatExpr | col (int x) const
Mat | cross (const Mat &m) const
MatExpr | diag (int d=0) const
double | dot (const Mat &m) const
MatExpr | inv (int method=DECOMP_LU) const
MatExpr | mul (const MatExpr &e, double scale=1) const
MatExpr | mul (const Mat &m, double scale=1) const
| operator Mat () const
template<typename _Tp >
| operator Mat_< _Tp > () const
MatExpr | operator() (const Range &rowRange, const Range &colRange) const
MatExpr | operator() (const Rect &roi) const
MatExpr | row (int y) const
Size | size () const
MatExpr | t () const
int | type () const

## Public Attributes
Mat | a
double | alpha
Mat | b
double | beta
Mat | c
int | flags
const MatOp * | op
Scalar | s

## Related Functions
(Note that these are not member functions.)
MatExpr | operator+ (const Mat &a, const Mat &b)
MatExpr | operator+ (const Mat &a, const Scalar &s)
MatExpr | operator+ (const Scalar &s, const Mat &a)
MatExpr | operator+ (const MatExpr &e, const Mat &m)
MatExpr | operator+ (const Mat &m, const MatExpr &e)
MatExpr | operator+ (const MatExpr &e, const Scalar &s)
MatExpr | operator+ (const Scalar &s, const MatExpr &e)
MatExpr | operator+ (const MatExpr &e1, const MatExpr &e2)
MatExpr | operator- (const Mat &a, const Mat &b)
MatExpr | operator- (const Mat &a, const Scalar &s)
MatExpr | operator- (const Scalar &s, const Mat &a)
MatExpr | operator- (const MatExpr &e, const Mat &m)
MatExpr | operator- (const Mat &m, const MatExpr &e)
MatExpr | operator- (const MatExpr &e, const Scalar &s)
MatExpr | operator- (const Scalar &s, const MatExpr &e)
MatExpr | operator- (const MatExpr &e1, const MatExpr &e2)
MatExpr | operator- (const Mat &m)
MatExpr | operator- (const MatExpr &e)
MatExpr | operator* (const Mat &a, const Mat &b)
MatExpr | operator* (const Mat &a, double s)
MatExpr | operator* (double s, const Mat &a)
MatExpr | operator* (const MatExpr &e, const Mat &m)
MatExpr | operator* (const Mat &m, const MatExpr &e)
MatExpr | operator* (const MatExpr &e, double s)
MatExpr | operator* (double s, const MatExpr &e)
MatExpr | operator* (const MatExpr &e1, const MatExpr &e2)
MatExpr | operator/ (const Mat &a, const Mat &b)
MatExpr | operator/ (const Mat &a, double s)
MatExpr | operator/ (double s, const Mat &a)
MatExpr | operator/ (const MatExpr &e, const Mat &m)
MatExpr | operator/ (const Mat &m, const MatExpr &e)
MatExpr | operator/ (const MatExpr &e, double s)
MatExpr | operator/ (double s, const MatExpr &e)
MatExpr | operator/ (const MatExpr &e1, const MatExpr &e2)
MatExpr | operator< (const Mat &a, const Mat &b)
MatExpr | operator< (const Mat &a, double s)
MatExpr | operator< (double s, const Mat &a)
MatExpr | operator<= (const Mat &a, const Mat &b)
MatExpr | operator<= (const Mat &a, double s)
MatExpr | operator<= (double s, const Mat &a)
MatExpr | operator== (const Mat &a, const Mat &b)
MatExpr | operator== (const Mat &a, double s)
MatExpr | operator== (double s, const Mat &a)
MatExpr | operator!= (const Mat &a, const Mat &b)
MatExpr | operator!= (const Mat &a, double s)
MatExpr | operator!= (double s, const Mat &a)
MatExpr | operator>= (const Mat &a, const Mat &b)
MatExpr | operator>= (const Mat &a, double s)
MatExpr | operator>= (double s, const Mat &a)
MatExpr | operator> (const Mat &a, const Mat &b)
MatExpr | operator> (const Mat &a, double s)
MatExpr | operator> (double s, const Mat &a)
MatExpr | operator & (const Mat &a, const Mat &b)
MatExpr | operator & (const Mat &a, const Scalar &s)
MatExpr | operator & (const Scalar &s, const Mat &a)
MatExpr | operator| (const Mat &a, const Mat &b)
MatExpr | operator| (const Mat &a, const Scalar &s)
MatExpr | operator| (const Scalar &s, const Mat &a)
MatExpr | operator^ (const Mat &a, const Mat &b)
MatExpr | operator^ (const Mat &a, const Scalar &s)
MatExpr | operator^ (const Scalar &s, const Mat &a)
MatExpr | operator~ (const Mat &m)
MatExpr | min (const Mat &a, const Mat &b)
MatExpr | min (const Mat &a, double s)
MatExpr | min (double s, const Mat &a)
MatExpr | max (const Mat &a, const Mat &b)
MatExpr | max (const Mat &a, double s)
MatExpr | max (double s, const Mat &a)
MatExpr | abs (const Mat &m)
| Calculates an absolute value of each matrix element. More...
MatExpr | abs (const MatExpr &e)

## Detailed Description

Matrix expression representation.

This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a real-valued scalar ( double )):

- Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`, `-A`
- Scaling: `A*alpha`
- Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A`
- Matrix multiplication: `A*B`
- Transposition: `A.t()` (means AT)
- Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems: `A.inv([method]) (~ A<sup>-1</sup>)`, `A.inv([method])*B (~ X: AX=B)`
- Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where cmpop is one of `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0.
- Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`, `~A`, where logicop is one of `&`, `|`, `^`.
- Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`, `max(A, alpha)`
- Element-wise absolute value: `abs(A)`
- Cross-product, dot-product: `A.cross(B)`, `A.dot(B)`
- Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, mean, sum, countNonZero, trace, determinant, repeat, and others.
- Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated initializers, matrix constructors and operators that extract sub-matrices (see Mat description).
- Mat_<destination_type>() constructors to cast the result to the proper type.
  Note
    Comma-separated initializers and probably some other operations may require additional explicit Mat() or Mat_<T>() constructor calls to resolve a possible ambiguity.
  Here are examples of matrix expressions:
  // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD)
  SVD svd(A);
  Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t();
  // compute the new vector of parameters in the Levenberg-Marquardt algorithm
  x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err);
  // sharpen image using "unsharp mask" algorithm
  Mat blurred; double sigma = 1, threshold = 5, amount = 1;
  GaussianBlur(img, blurred, Size(), sigma, sigma);
  Mat lowContrastMask = abs(img - blurred) < threshold;
  Mat sharpened = img*(1+amount) + blurred*(-amount);
  img.copyTo(sharpened, lowContrastMask);

## Constructor & Destructor Documentation

## ◆ MatExpr() [1/3]

cv::MatExpr::MatExpr | ( |  | ) |

## ◆ MatExpr() [2/3]

cv::MatExpr::MatExpr | ( | const Mat & | m | ) |
| explicit

## ◆ MatExpr() [3/3]

cv::MatExpr::MatExpr | ( | const MatOp * | _op,
|  | int | _flags,
|  | const Mat & | _a = `Mat()`,
|  | const Mat & | _b = `Mat()`,
|  | const Mat & | _c = `Mat()`,
|  | double | _alpha = `1`,
|  | double | _beta = `1`,
|  | const Scalar & | _s = `Scalar()`
| ) |  |

## Member Function Documentation

## ◆ col()

MatExpr cv::MatExpr::col | ( | int | x | ) | const

## ◆ cross()

Mat cv::MatExpr::cross | ( | const Mat & | m | ) | const

## ◆ diag()

MatExpr cv::MatExpr::diag | ( | int | d = `0` | ) | const

## ◆ dot()

double cv::MatExpr::dot | ( | const Mat & | m | ) | const

## ◆ inv()

MatExpr cv::MatExpr::inv | ( | int | method = `DECOMP_LU` | ) | const

## ◆ mul() [1/2]

MatExpr cv::MatExpr::mul | ( | const MatExpr & | e,
|  | double | scale = `1`
| ) |  | const

## ◆ mul() [2/2]

MatExpr cv::MatExpr::mul | ( | const Mat & | m,
|  | double | scale = `1`
| ) |  | const

## ◆ operator Mat()

cv::MatExpr::operator Mat | ( |  | ) | const

## ◆ operator Mat_< _Tp >()

template<typename _Tp >

cv::MatExpr::operator Mat_< _Tp > | ( |  | ) | const

## ◆ operator()() [1/2]

MatExpr cv::MatExpr::operator() | ( | const Range & | rowRange,
|  | const Range & | colRange
| ) |  | const

## ◆ operator()() [2/2]

MatExpr cv::MatExpr::operator() | ( | const Rect & | roi | ) | const

## ◆ row()

MatExpr cv::MatExpr::row | ( | int | y | ) | const

## ◆ size()

Size cv::MatExpr::size | ( |  | ) | const

## ◆ t()

MatExpr cv::MatExpr::t | ( |  | ) | const

Examples:
  decompose_homography.cpp.

## ◆ type()

int cv::MatExpr::type | ( |  | ) | const

## Friends And Related Function Documentation

## ◆ abs() [1/2]

MatExpr abs | ( | const Mat & | m | ) |
| related

Calculates an absolute value of each matrix element.

abs is a meta-function that is expanded to one of absdiff or convertScaleAbs forms:

- C = abs(A-B) is equivalent to `absdiff(A, B, C)`
- C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)`
- C = `Mat_<Vec<uchar,n> >(abs(A*alpha + beta))` is equivalent to `convertScaleAbs(A, C, alpha, beta)`

The output matrix has the same size and the same type as the input one except for the last case, where C is depth=CV_8U .

Parameters

  m | matrix.

See also
  MatrixExpressions, absdiff, convertScaleAbs

## ◆ abs() [2/2]

MatExpr abs | ( | const MatExpr & | e | ) |
| related

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

Parameters

  e | matrix expression.

## ◆ max() [1/3]

MatExpr max | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ max() [2/3]

MatExpr max | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ max() [3/3]

MatExpr max | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ min() [1/3]

MatExpr min | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ min() [2/3]

MatExpr min | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ min() [3/3]

MatExpr min | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator &() [1/3]

MatExpr operator& | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator &() [2/3]

MatExpr operator& | ( | const Mat & | a,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator &() [3/3]

MatExpr operator& | ( | const Scalar & | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator!=() [1/3]

MatExpr operator!= | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator!=() [2/3]

MatExpr operator!= | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator!=() [3/3]

MatExpr operator!= | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator*() [1/8]

MatExpr operator* | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator*() [2/8]

MatExpr operator* | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator*() [3/8]

MatExpr operator* | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator*() [4/8]

MatExpr operator* | ( | const MatExpr & | e,
|  | const Mat & | m
| ) |  |
| related

## ◆ operator*() [5/8]

MatExpr operator* | ( | const Mat & | m,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator*() [6/8]

MatExpr operator* | ( | const MatExpr & | e,
|  | double | s
| ) |  |
| related

## ◆ operator*() [7/8]

MatExpr operator* | ( | double | s,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator*() [8/8]

MatExpr operator* | ( | const MatExpr & | e1,
|  | const MatExpr & | e2
| ) |  |
| related

## ◆ operator+() [1/8]

MatExpr operator+ | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator+() [2/8]

MatExpr operator+ | ( | const Mat & | a,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator+() [3/8]

MatExpr operator+ | ( | const Scalar & | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator+() [4/8]

MatExpr operator+ | ( | const MatExpr & | e,
|  | const Mat & | m
| ) |  |
| related

## ◆ operator+() [5/8]

MatExpr operator+ | ( | const Mat & | m,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator+() [6/8]

MatExpr operator+ | ( | const MatExpr & | e,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator+() [7/8]

MatExpr operator+ | ( | const Scalar & | s,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator+() [8/8]

MatExpr operator+ | ( | const MatExpr & | e1,
|  | const MatExpr & | e2
| ) |  |
| related

## ◆ operator-() [1/10]

MatExpr operator- | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator-() [2/10]

MatExpr operator- | ( | const Mat & | a,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator-() [3/10]

MatExpr operator- | ( | const Scalar & | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator-() [4/10]

MatExpr operator- | ( | const MatExpr & | e,
|  | const Mat & | m
| ) |  |
| related

## ◆ operator-() [5/10]

MatExpr operator- | ( | const Mat & | m,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator-() [6/10]

MatExpr operator- | ( | const MatExpr & | e,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator-() [7/10]

MatExpr operator- | ( | const Scalar & | s,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator-() [8/10]

MatExpr operator- | ( | const MatExpr & | e1,
|  | const MatExpr & | e2
| ) |  |
| related

## ◆ operator-() [9/10]

MatExpr operator- | ( | const Mat & | m | ) |
| related

## ◆ operator-() [10/10]

MatExpr operator- | ( | const MatExpr & | e | ) |
| related

## ◆ operator/() [1/8]

MatExpr operator/ | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator/() [2/8]

MatExpr operator/ | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator/() [3/8]

MatExpr operator/ | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator/() [4/8]

MatExpr operator/ | ( | const MatExpr & | e,
|  | const Mat & | m
| ) |  |
| related

## ◆ operator/() [5/8]

MatExpr operator/ | ( | const Mat & | m,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator/() [6/8]

MatExpr operator/ | ( | const MatExpr & | e,
|  | double | s
| ) |  |
| related

## ◆ operator/() [7/8]

MatExpr operator/ | ( | double | s,
|  | const MatExpr & | e
| ) |  |
| related

## ◆ operator/() [8/8]

MatExpr operator/ | ( | const MatExpr & | e1,
|  | const MatExpr & | e2
| ) |  |
| related

## ◆ operator<() [1/3]

MatExpr operator< | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator<() [2/3]

MatExpr operator< | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator<() [3/3]

MatExpr operator< | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator<=() [1/3]

MatExpr operator<= | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator<=() [2/3]

MatExpr operator<= | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator<=() [3/3]

MatExpr operator<= | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator==() [1/3]

MatExpr operator== | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator==() [2/3]

MatExpr operator== | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator==() [3/3]

MatExpr operator== | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator>() [1/3]

MatExpr operator> | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator>() [2/3]

MatExpr operator> | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator>() [3/3]

MatExpr operator> | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator>=() [1/3]

MatExpr operator>= | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator>=() [2/3]

MatExpr operator>= | ( | const Mat & | a,
|  | double | s
| ) |  |
| related

## ◆ operator>=() [3/3]

MatExpr operator>= | ( | double | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator^() [1/3]

MatExpr operator^ | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator^() [2/3]

MatExpr operator^ | ( | const Mat & | a,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator^() [3/3]

MatExpr operator^ | ( | const Scalar & | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator|() [1/3]

MatExpr operator| | ( | const Mat & | a,
|  | const Mat & | b
| ) |  |
| related

## ◆ operator|() [2/3]

MatExpr operator| | ( | const Mat & | a,
|  | const Scalar & | s
| ) |  |
| related

## ◆ operator|() [3/3]

MatExpr operator| | ( | const Scalar & | s,
|  | const Mat & | a
| ) |  |
| related

## ◆ operator~()

MatExpr operator~ | ( | const Mat & | m | ) |
| related

## Member Data Documentation

## ◆ a

Mat cv::MatExpr::a

## ◆ alpha

double cv::MatExpr::alpha

## ◆ b

Mat cv::MatExpr::b

## ◆ beta

double cv::MatExpr::beta

## ◆ c

Mat cv::MatExpr::c

## ◆ flags

int cv::MatExpr::flags

## ◆ op

const MatOp* cv::MatExpr::op

## ◆ s

Scalar cv::MatExpr::s

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

- core/include/opencv2/core/mat.hpp