File: per_element_operations.rst

package info (click to toggle)
opencv 2.4.9.1%2Bdfsg-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 126,800 kB
  • ctags: 62,729
  • sloc: xml: 509,055; cpp: 490,794; lisp: 23,208; python: 21,174; java: 19,317; ansic: 1,038; sh: 128; makefile: 72
file content (445 lines) | stat: -rw-r--r-- 14,763 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
Per-element Operations
=======================

.. highlight:: cpp



gpu::add
------------
Computes a matrix-matrix or matrix-scalar sum.

.. ocv:function:: void gpu::add( const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask=GpuMat(), int dtype=-1, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::add( const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask=GpuMat(), int dtype=-1, Stream& stream=Stream::Null() )

    :param a: First source matrix.

    :param b: Second source matrix to be added to ``a`` . Matrix should have the same size and type as ``a`` .

    :param sc: A scalar to be added to ``a`` .

    :param c: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``a`` depth.

    :param mask: Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed.

    :param dtype: Optional depth of the output array.

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`add`



gpu::subtract
-----------------
Computes a matrix-matrix or matrix-scalar difference.

.. ocv:function:: void gpu::subtract( const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask=GpuMat(), int dtype=-1, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::subtract( const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask=GpuMat(), int dtype=-1, Stream& stream=Stream::Null() )

    :param a: First source matrix.

    :param b: Second source matrix to be added to ``a`` . Matrix should have the same size and type as ``a`` .

    :param sc: A scalar to be added to ``a`` .

    :param c: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``a`` depth.

    :param mask: Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed.

    :param dtype: Optional depth of the output array.

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`subtract`



gpu::multiply
-----------------
Computes a matrix-matrix or matrix-scalar per-element product.

.. ocv:function:: void gpu::multiply( const GpuMat& a, const GpuMat& b, GpuMat& c, double scale=1, int dtype=-1, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::multiply( const GpuMat& a, const Scalar& sc, GpuMat& c, double scale=1, int dtype=-1, Stream& stream=Stream::Null() )

    :param a: First source matrix.

    :param b: Second source matrix to be multiplied by ``a`` elements.

    :param sc: A scalar to be multiplied by ``a`` elements.

    :param c: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``a`` depth.

    :param scale: Optional scale factor.

    :param dtype: Optional depth of the output array.

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`multiply`



gpu::divide
-----------
Computes a matrix-matrix or matrix-scalar division.

.. ocv:function:: void gpu::divide( const GpuMat& a, const GpuMat& b, GpuMat& c, double scale=1, int dtype=-1, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::divide(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null())

.. ocv:function:: void gpu::divide( double scale, const GpuMat& b, GpuMat& c, int dtype=-1, Stream& stream=Stream::Null() )

    :param a: First source matrix or a scalar.

    :param b: Second source matrix. The ``a`` elements are divided by it.

    :param sc: A scalar to be divided by the elements of ``a`` matrix.

    :param c: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``a`` depth.

    :param scale: Optional scale factor.

    :param dtype: Optional depth of the output array.

    :param stream: Stream for the asynchronous version.

This function, in contrast to :ocv:func:`divide`, uses a round-down rounding mode.

.. seealso:: :ocv:func:`divide`


gpu::addWeighted
----------------
Computes the weighted sum of two arrays.

.. ocv:function:: void gpu::addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, int dtype = -1, Stream& stream = Stream::Null())

    :param src1: First source array.

    :param alpha: Weight for the first array elements.

    :param src2: Second source array of the same size and channel number as  ``src1`` .

    :param beta: Weight for the second array elements.

    :param dst: Destination array that has the same size and number of channels as the input arrays.

    :param gamma: Scalar added to each sum.

    :param dtype: Optional depth of the destination array. When both input arrays have the same depth, ``dtype`` can be set to ``-1``, which will be equivalent to ``src1.depth()``.

    :param stream: Stream for the asynchronous version.

The function ``addWeighted`` calculates the weighted sum of two arrays as follows:

.. math::

    \texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )

where ``I`` is a multi-dimensional index of array elements. In case of multi-channel arrays, each channel is processed independently.

.. seealso:: :ocv:func:`addWeighted`



gpu::abs
------------
Computes an absolute value of each matrix element.

.. ocv:function:: void gpu::abs(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null())

    :param src: Source matrix. Supports ``CV_16S`` and ``CV_32F`` depth.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`abs`



gpu::sqr
------------
Computes a square value of each matrix element.

.. ocv:function:: void gpu::sqr(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null())

    :param src: Source matrix. Supports ``CV_8U`` , ``CV_16U`` , ``CV_16S`` and ``CV_32F`` depth.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.



gpu::sqrt
------------
Computes a square root of each matrix element.

.. ocv:function:: void gpu::sqrt(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null())

    :param src: Source matrix. Supports ``CV_8U`` , ``CV_16U`` , ``CV_16S`` and ``CV_32F`` depth.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`sqrt`



gpu::exp
------------
Computes an exponent of each matrix element.

.. ocv:function:: void gpu::exp( const GpuMat& a, GpuMat& b, Stream& stream=Stream::Null() )

    :param a: Source matrix. Supports ``CV_8U`` , ``CV_16U`` , ``CV_16S`` and ``CV_32F`` depth.

    :param b: Destination matrix with the same size and type as ``a`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`exp`



gpu::log
------------
Computes a natural logarithm of absolute value of each matrix element.

.. ocv:function:: void gpu::log( const GpuMat& a, GpuMat& b, Stream& stream=Stream::Null() )

    :param a: Source matrix. Supports ``CV_8U`` , ``CV_16U`` , ``CV_16S`` and ``CV_32F`` depth.

    :param b: Destination matrix with the same size and type as ``a`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`log`



gpu::pow
------------
Raises every matrix element to a power.

.. ocv:function:: void gpu::pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream = Stream::Null())

    :param src: Source matrix. Supports all type, except ``CV_64F`` depth.

    :param power: Exponent of power.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.

The function ``pow`` raises every element of the input matrix to ``p`` :

.. math::

    \texttt{dst} (I) =  \fork{\texttt{src}(I)^p}{if \texttt{p} is integer}{|\texttt{src}(I)|^p}{otherwise}

.. seealso:: :ocv:func:`pow`



gpu::absdiff
----------------
Computes per-element absolute difference of two matrices (or of a matrix and scalar).

.. ocv:function:: void gpu::absdiff( const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::absdiff( const GpuMat& a, const Scalar& s, GpuMat& c, Stream& stream=Stream::Null() )

    :param a: First source matrix.

    :param b: Second source matrix to be added to ``a`` .

    :param s: A scalar to be added to ``a`` .

    :param c: Destination matrix with the same size and type as ``a`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`absdiff`



gpu::compare
----------------
Compares elements of two matrices.

.. ocv:function:: void gpu::compare( const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream=Stream::Null() )

.. ocv:function:: void gpu::compare(const GpuMat& a, Scalar sc, GpuMat& c, int cmpop, Stream& stream = Stream::Null())

    :param a: First source matrix.

    :param b: Second source matrix with the same size and type as ``a`` .

    :param sc: A scalar to be compared with ``a`` .

    :param c: Destination matrix with the same size as ``a`` and the ``CV_8UC1`` type.

    :param cmpop: Flag specifying the relation between the elements to be checked:

            * **CMP_EQ:** ``a(.) == b(.)``
            * **CMP_GT:** ``a(.) < b(.)``
            * **CMP_GE:** ``a(.) <= b(.)``
            * **CMP_LT:** ``a(.) < b(.)``
            * **CMP_LE:** ``a(.) <= b(.)``
            * **CMP_NE:** ``a(.) != b(.)``

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`compare`



gpu::bitwise_not
--------------------
Performs a per-element bitwise inversion.

.. ocv:function:: void gpu::bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null())

    :param src: Source matrix.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param mask: Optional operation mask. 8-bit single channel image.

    :param stream: Stream for the asynchronous version.



gpu::bitwise_or
-------------------
Performs a per-element bitwise disjunction of two matrices or of matrix and scalar.

.. ocv:function:: void gpu::bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null())
.. ocv:function:: void gpu::bitwise_or(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null())

    :param src1: First source matrix.

    :param src2: Second source matrix with the same size and type as ``src1`` .

    :param dst: Destination matrix with the same size and type as ``src1`` .

    :param mask: Optional operation mask. 8-bit single channel image.

    :param stream: Stream for the asynchronous version.



gpu::bitwise_and
--------------------
Performs a per-element bitwise conjunction of two matrices or of matrix and scalar.

.. ocv:function:: void gpu::bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null())
.. ocv:function:: void gpu::bitwise_and(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null())

    :param src1: First source matrix.

    :param src2: Second source matrix with the same size and type as ``src1`` .

    :param dst: Destination matrix with the same size and type as ``src1`` .

    :param mask: Optional operation mask. 8-bit single channel image.

    :param stream: Stream for the asynchronous version.



gpu::bitwise_xor
--------------------
Performs a per-element bitwise ``exclusive or`` operation of two matrices of matrix and scalar.

.. ocv:function:: void gpu::bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null())
.. ocv:function:: void gpu::bitwise_xor(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null())

    :param src1: First source matrix.

    :param src2: Second source matrix with the same size and type as ``src1`` .

    :param dst: Destination matrix with the same size and type as ``src1`` .

    :param mask: Optional operation mask. 8-bit single channel image.

    :param stream: Stream for the asynchronous version.



gpu::rshift
--------------------
Performs pixel by pixel right shift of an image by a constant value.

.. ocv:function:: void gpu::rshift( const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream=Stream::Null() )

    :param src: Source matrix. Supports 1, 3 and 4 channels images with integers elements.

    :param sc: Constant values, one per channel.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.



gpu::lshift
--------------------
Performs pixel by pixel right left of an image by a constant value.

.. ocv:function:: void gpu::lshift( const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream=Stream::Null() )

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

    :param sc: Constant values, one per channel.

    :param dst: Destination matrix with the same size and type as ``src`` .

    :param stream: Stream for the asynchronous version.



gpu::min
------------
Computes the per-element minimum of two matrices (or a matrix and a scalar).

.. ocv:function:: void gpu::min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())

.. ocv:function:: void gpu::min(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null())

    :param src1: First source matrix.

    :param src2: Second source matrix or a scalar to compare ``src1`` elements with.

    :param dst: Destination matrix with the same size and type as ``src1`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`min`



gpu::max
------------
Computes the per-element maximum of two matrices (or a matrix and a scalar).

.. ocv:function:: void gpu::max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())

.. ocv:function:: void gpu::max(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null())

    :param src1: First source matrix.

    :param src2: Second source matrix or a scalar to compare ``src1`` elements with.

    :param dst: Destination matrix with the same size and type as ``src1`` .

    :param stream: Stream for the asynchronous version.

.. seealso:: :ocv:func:`max`