operations_on_matrices.rst 8.78 KB
Newer Older
1 2 3 4 5
Operations on Matrices
======================

.. highlight:: cpp

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
6

7

8 9 10 11
gpu::gemm
------------------
Performs generalized matrix multiplication.

12
.. ocv:function:: void gpu::gemm(const GpuMat& src1, const GpuMat& src2, double alpha, const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null())
13 14 15 16

    :param src1: First multiplied input matrix that should have  ``CV_32FC1`` , ``CV_64FC1`` , ``CV_32FC2`` , or  ``CV_64FC2``  type.

    :param src2: Second multiplied input matrix of the same type as  ``src1`` .
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
17

18 19 20
    :param alpha: Weight of the matrix product.

    :param src3: Third optional delta matrix added to the matrix product. It should have the same type as  ``src1``  and  ``src2`` .
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
21

22
    :param beta: Weight of  ``src3`` .
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
23

24 25 26 27 28 29 30 31 32
    :param dst: Destination matrix. It has the proper size and the same type as input matrices.

    :param flags: Operation flags:

            * **GEMM_1_T** transpose  ``src1``
            * **GEMM_2_T** transpose  ``src2``
            * **GEMM_3_T** transpose  ``src3``

    :param stream: Stream for the asynchronous version.
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
33

34 35 36 37 38 39
The function performs generalized matrix multiplication similar to the ``gemm`` functions in BLAS level 3. For example, ``gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`` corresponds to

.. math::

    \texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
40 41
.. note:: Transposition operation doesn't support  ``CV_64FC2``  input type.

42 43 44 45
.. seealso:: :ocv:func:`gemm`



Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
46
gpu::transpose
47
------------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
48
Transposes a matrix.
49

50
.. ocv:function:: void gpu::transpose( const GpuMat& src1, GpuMat& dst, Stream& stream=Stream::Null() )
51

52
    :param src1: Source matrix. 1-, 4-, 8-byte element sizes are supported for now (CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, etc).
53

54
    :param dst: Destination matrix.
55

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
56 57 58 59
    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`transpose`

60 61


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
62
gpu::flip
63
-------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
64
Flips a 2D matrix around vertical, horizontal, or both axes.
65

66
.. ocv:function:: void gpu::flip( const GpuMat& a, GpuMat& b, int flipCode, Stream& stream=Stream::Null() )
67

68
    :param a: Source matrix. Supports 1, 3 and 4 channels images with ``CV_8U``, ``CV_16U``, ``CV_32S`` or ``CV_32F`` depth.
69

70
    :param b: Destination matrix.
71

72
    :param flipCode: Flip mode for the source:
73

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
74 75 76 77 78 79 80 81 82 83
        * ``0`` Flips around x-axis.

        * ``>0`` Flips around y-axis.

        * ``<0`` Flips around both axes.

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`flip`

84 85


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
86
gpu::LUT
87
------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
88
Transforms the source matrix into the destination matrix using the given look-up table: ``dst(I) = lut(src(I))``
89

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
90
.. ocv:function:: void gpu::LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stream = Stream::Null())
91

92
    :param src: Source matrix.  ``CV_8UC1``  and  ``CV_8UC3``  matrices are supported for now.
93

94
    :param lut: Look-up table of 256 elements. It is a continuous ``CV_8U`` matrix.
95

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
96
    :param dst: Destination matrix with the same depth as  ``lut``  and the same number of channels as  ``src`` .
97

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
98
    :param stream: Stream for the asynchronous version.
99

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
100
.. seealso:: :ocv:func:`LUT`
101 102 103



Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
104 105 106
gpu::merge
--------------
Makes a multi-channel matrix out of several single-channel matrices.
107

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
108
.. ocv:function:: void gpu::merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null())
109

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
110
.. ocv:function:: void gpu::merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = Stream::Null())
111

112
    :param src: Array/vector of source matrices.
113

114
    :param n: Number of source matrices.
115

116
    :param dst: Destination matrix.
117

118
    :param stream: Stream for the asynchronous version.
119

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
120 121
.. seealso:: :ocv:func:`merge`

122 123


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
124
gpu::split
125
--------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
126
Copies each plane of a multi-channel matrix into an array.
127

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
128
.. ocv:function:: void gpu::split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null())
129

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
130
.. ocv:function:: void gpu::split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = Stream::Null())
131

132
    :param src: Source matrix.
133

134
    :param dst: Destination array/vector of single-channel matrices.
135

136
    :param stream: Stream for the asynchronous version.
137

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
138 139
.. seealso:: :ocv:func:`split`

140 141


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
142
gpu::magnitude
143
------------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
144
Computes magnitudes of complex matrix elements.
145

146
.. ocv:function:: void gpu::magnitude( const GpuMat& xy, GpuMat& magnitude, Stream& stream=Stream::Null() )
147

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
148
.. ocv:function:: void gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null())
149

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
150
    :param xy: Source complex matrix in the interleaved format ( ``CV_32FC2`` ).
151

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
152
    :param x: Source matrix containing real components ( ``CV_32FC1`` ).
153

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
154
    :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ).
155

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
156
    :param magnitude: Destination matrix of float magnitudes ( ``CV_32FC1`` ).
157 158

    :param stream: Stream for the asynchronous version.
159

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
160 161
.. seealso:: :ocv:func:`magnitude`

162 163


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
164
gpu::magnitudeSqr
165
---------------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
166
Computes squared magnitudes of complex matrix elements.
167

168
.. ocv:function:: void gpu::magnitudeSqr( const GpuMat& xy, GpuMat& magnitude, Stream& stream=Stream::Null() )
169

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
170
.. ocv:function:: void gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null())
171

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
172
    :param xy: Source complex matrix in the interleaved format ( ``CV_32FC2`` ).
173

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
174
    :param x: Source matrix containing real components ( ``CV_32FC1`` ).
175

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
176
    :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ).
177

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
178
    :param magnitude: Destination matrix of float magnitude squares ( ``CV_32FC1`` ).
179 180

    :param stream: Stream for the asynchronous version.
181

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
182

183

Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
184
gpu::phase
185
--------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
186
Computes polar angles of complex matrix elements.
187

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
188
.. ocv:function:: void gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees=false, Stream& stream = Stream::Null())
189

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
190
    :param x: Source matrix containing real components ( ``CV_32FC1`` ).
191

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
192
    :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ).
193

194
    :param angle: Destination matrix of angles ( ``CV_32FC1`` ).
195

196
    :param angleInDegrees: Flag for angles that must be evaluated in degrees.
197

198
    :param stream: Stream for the asynchronous version.
199

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
200 201
.. seealso:: :ocv:func:`phase`

202 203


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
204
gpu::cartToPolar
205
--------------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
206
Converts Cartesian coordinates into polar.
207

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
208
.. ocv:function:: void gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees=false, Stream& stream = Stream::Null())
209

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
210
    :param x: Source matrix containing real components ( ``CV_32FC1`` ).
211

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
212
    :param y: Source matrix containing imaginary components ( ``CV_32FC1`` ).
213

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
214
    :param magnitude: Destination matrix of float magnitudes ( ``CV_32FC1`` ).
215

216
    :param angle: Destination matrix of angles ( ``CV_32FC1`` ).
217

218
    :param angleInDegrees: Flag for angles that must be evaluated in degrees.
219

220
    :param stream: Stream for the asynchronous version.
221

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
222 223
.. seealso:: :ocv:func:`cartToPolar`

224 225


Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
226
gpu::polarToCart
227
--------------------
Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
228
Converts polar coordinates into Cartesian.
229

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
230
.. ocv:function:: void gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees=false, Stream& stream = Stream::Null())
231

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
232
    :param magnitude: Source matrix containing magnitudes ( ``CV_32FC1`` ).
233

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
234
    :param angle: Source matrix containing angles ( ``CV_32FC1`` ).
235

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
236
    :param x: Destination matrix of real components ( ``CV_32FC1`` ).
237

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
238
    :param y: Destination matrix of imaginary components ( ``CV_32FC1`` ).
239

240
    :param angleInDegrees: Flag that indicates angles in degrees.
241

242
    :param stream: Stream for the asynchronous version.
243

Vladislav Vinogradov's avatar
Vladislav Vinogradov committed
244
.. seealso:: :ocv:func:`polarToCart`
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274



gpu::normalize
--------------
Normalizes the norm or value range of an array.

.. ocv:function:: void gpu::normalize(const GpuMat& src, GpuMat& dst, double alpha = 1, double beta = 0, int norm_type = NORM_L2, int dtype = -1, const GpuMat& mask = GpuMat())

.. ocv:function:: void gpu::normalize(const GpuMat& src, GpuMat& dst, double a, double b, int norm_type, int dtype, const GpuMat& mask, GpuMat& norm_buf, GpuMat& cvt_buf)

    :param src: input array.

    :param dst: output array of the same size as  ``src`` .

    :param alpha: norm value to normalize to or the lower range boundary in case of the range normalization.

    :param beta: upper range boundary in case of the range normalization; it is not used for the norm normalization.

    :param normType: normalization type (see the details below).

    :param dtype: when negative, the output array has the same type as ``src``; otherwise, it has the same number of channels as  ``src`` and the depth ``=CV_MAT_DEPTH(dtype)``.

    :param mask: optional operation mask.

    :param norm_buf: Optional buffer to avoid extra memory allocations. It is resized automatically.

    :param cvt_buf: Optional buffer to avoid extra memory allocations. It is resized automatically.

.. seealso:: :ocv:func:`normalize`