1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef OPENCV_CUDAARITHM_HPP
44 #define OPENCV_CUDAARITHM_HPP
45 
46 #ifndef __cplusplus
47 #  error cudaarithm.hpp header must be compiled as C++
48 #endif
49 
50 #include "opencv2/core/cuda.hpp"
51 
52 /**
53   @addtogroup cuda
54   @{
55     @defgroup cudaarithm Operations on Matrices
56     @{
57         @defgroup cudaarithm_core Core Operations on Matrices
58         @defgroup cudaarithm_elem Per-element Operations
59         @defgroup cudaarithm_reduce Matrix Reductions
60         @defgroup cudaarithm_arithm Arithm Operations on Matrices
61     @}
62   @}
63  */
64 
65 namespace cv { namespace cuda {
66 
67 //! @addtogroup cudaarithm
68 //! @{
69 
70 //! @addtogroup cudaarithm_elem
71 //! @{
72 
73 /** @brief Computes a matrix-matrix or matrix-scalar sum.
74 
75 @param src1 First source matrix or scalar.
76 @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
77 @param dst Destination matrix that has the same size and number of channels as the input array(s).
78 The depth is defined by dtype or src1 depth.
79 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
80 destination array to be changed. The mask can be used only with single channel images.
81 @param dtype Optional depth of the output array.
82 @param stream Stream for the asynchronous version.
83 
84 @sa add
85  */
86 CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
87 
88 /** @brief Computes a matrix-matrix or matrix-scalar difference.
89 
90 @param src1 First source matrix or scalar.
91 @param src2 Second source matrix or scalar. Matrix should have the same size and type as src1 .
92 @param dst Destination matrix that has the same size and number of channels as the input array(s).
93 The depth is defined by dtype or src1 depth.
94 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
95 destination array to be changed. The mask can be used only with single channel images.
96 @param dtype Optional depth of the output array.
97 @param stream Stream for the asynchronous version.
98 
99 @sa subtract
100  */
101 CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1, Stream& stream = Stream::Null());
102 
103 /** @brief Computes a matrix-matrix or matrix-scalar per-element product.
104 
105 @param src1 First source matrix or scalar.
106 @param src2 Second source matrix or scalar.
107 @param dst Destination matrix that has the same size and number of channels as the input array(s).
108 The depth is defined by dtype or src1 depth.
109 @param scale Optional scale factor.
110 @param dtype Optional depth of the output array.
111 @param stream Stream for the asynchronous version.
112 
113 @sa multiply
114  */
115 CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
116 
117 /** @brief Computes a matrix-matrix or matrix-scalar division.
118 
119 @param src1 First source matrix or a scalar.
120 @param src2 Second source matrix or scalar.
121 @param dst Destination matrix that has the same size and number of channels as the input array(s).
122 The depth is defined by dtype or src1 depth.
123 @param scale Optional scale factor.
124 @param dtype Optional depth of the output array.
125 @param stream Stream for the asynchronous version.
126 
127 This function, in contrast to divide, uses a round-down rounding mode.
128 
129 @sa divide
130  */
131 CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
132 
133 /** @brief Computes per-element absolute difference of two matrices (or of a matrix and scalar).
134 
135 @param src1 First source matrix or scalar.
136 @param src2 Second source matrix or scalar.
137 @param dst Destination matrix that has the same size and type as the input array(s).
138 @param stream Stream for the asynchronous version.
139 
140 @sa absdiff
141  */
142 CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
143 
144 /** @brief Computes an absolute value of each matrix element.
145 
146 @param src Source matrix.
147 @param dst Destination matrix with the same size and type as src .
148 @param stream Stream for the asynchronous version.
149 
150 @sa abs
151  */
152 CV_EXPORTS_W void abs(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
153 
154 /** @brief Computes a square value of each matrix element.
155 
156 @param src Source matrix.
157 @param dst Destination matrix with the same size and type as src .
158 @param stream Stream for the asynchronous version.
159  */
160 CV_EXPORTS_W void sqr(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
161 
162 /** @brief Computes a square root of each matrix element.
163 
164 @param src Source matrix.
165 @param dst Destination matrix with the same size and type as src .
166 @param stream Stream for the asynchronous version.
167 
168 @sa sqrt
169  */
170 CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
171 
172 /** @brief Computes an exponent of each matrix element.
173 
174 @param src Source matrix.
175 @param dst Destination matrix with the same size and type as src .
176 @param stream Stream for the asynchronous version.
177 
178 @sa exp
179  */
180 CV_EXPORTS_W void exp(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
181 
182 /** @brief Computes a natural logarithm of absolute value of each matrix element.
183 
184 @param src Source matrix.
185 @param dst Destination matrix with the same size and type as src .
186 @param stream Stream for the asynchronous version.
187 
188 @sa log
189  */
190 CV_EXPORTS_W void log(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
191 
192 /** @brief Raises every matrix element to a power.
193 
194 @param src Source matrix.
195 @param power Exponent of power.
196 @param dst Destination matrix with the same size and type as src .
197 @param stream Stream for the asynchronous version.
198 
199 The function pow raises every element of the input matrix to power :
200 
201 \f[\texttt{dst} (I) =  \fork{\texttt{src}(I)^power}{if \texttt{power} is integer}{|\texttt{src}(I)|^power}{otherwise}\f]
202 
203 @sa pow
204  */
205 CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst, Stream& stream = Stream::Null());
206 
207 /** @brief Compares elements of two matrices (or of a matrix and scalar).
208 
209 @param src1 First source matrix or scalar.
210 @param src2 Second source matrix or scalar.
211 @param dst Destination matrix that has the same size as the input array(s) and type CV_8U.
212 @param cmpop Flag specifying the relation between the elements to be checked:
213 -   **CMP_EQ:** a(.) == b(.)
214 -   **CMP_GT:** a(.) \> b(.)
215 -   **CMP_GE:** a(.) \>= b(.)
216 -   **CMP_LT:** a(.) \< b(.)
217 -   **CMP_LE:** a(.) \<= b(.)
218 -   **CMP_NE:** a(.) != b(.)
219 @param stream Stream for the asynchronous version.
220 
221 @sa compare
222  */
223 CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream = Stream::Null());
224 
225 /** @brief Performs a per-element bitwise inversion.
226 
227 @param src Source matrix.
228 @param dst Destination matrix with the same size and type as src .
229 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
230 destination array to be changed. The mask can be used only with single channel images.
231 @param stream Stream for the asynchronous version.
232  */
233 CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
234 
235 /** @brief Performs a per-element bitwise disjunction of two matrices (or of matrix and scalar).
236 
237 @param src1 First source matrix or scalar.
238 @param src2 Second source matrix or scalar.
239 @param dst Destination matrix that has the same size and type as the input array(s).
240 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
241 destination array to be changed. The mask can be used only with single channel images.
242 @param stream Stream for the asynchronous version.
243  */
244 CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
245 
246 /** @brief Performs a per-element bitwise conjunction of two matrices (or of matrix and scalar).
247 
248 @param src1 First source matrix or scalar.
249 @param src2 Second source matrix or scalar.
250 @param dst Destination matrix that has the same size and type as the input array(s).
251 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
252 destination array to be changed. The mask can be used only with single channel images.
253 @param stream Stream for the asynchronous version.
254  */
255 CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
256 
257 /** @brief Performs a per-element bitwise exclusive or operation of two matrices (or of matrix and scalar).
258 
259 @param src1 First source matrix or scalar.
260 @param src2 Second source matrix or scalar.
261 @param dst Destination matrix that has the same size and type as the input array(s).
262 @param mask Optional operation mask, 8-bit single channel array, that specifies elements of the
263 destination array to be changed. The mask can be used only with single channel images.
264 @param stream Stream for the asynchronous version.
265  */
266 CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
267 
268 /** @brief Performs pixel by pixel right shift of an image by a constant value.
269 
270 @param src Source matrix. Supports 1, 3 and 4 channels images with integers elements.
271 @param val Constant values, one per channel.
272 @param dst Destination matrix with the same size and type as src .
273 @param stream Stream for the asynchronous version.
274  */
275 CV_EXPORTS void rshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());
276 
rshift(InputArray src,Scalar val,OutputArray dst,Stream & stream=Stream::Null ())277 CV_WRAP inline void rshift(InputArray src, Scalar val, OutputArray dst, Stream& stream = Stream::Null()) {
278     rshift(src, Scalar_<int>(val), dst, stream);
279 }
280 
281 /** @brief Performs pixel by pixel right left of an image by a constant value.
282 
283 @param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U , CV_16U or CV_32S
284 depth.
285 @param val Constant values, one per channel.
286 @param dst Destination matrix with the same size and type as src .
287 @param stream Stream for the asynchronous version.
288  */
289 CV_EXPORTS void lshift(InputArray src, Scalar_<int> val, OutputArray dst, Stream& stream = Stream::Null());
290 
lshift(InputArray src,Scalar val,OutputArray dst,Stream & stream=Stream::Null ())291 CV_WRAP inline void lshift(InputArray src, Scalar val, OutputArray dst, Stream& stream = Stream::Null()) {
292     lshift(src, Scalar_<int>(val), dst, stream);
293 }
294 
295 /** @brief Computes the per-element minimum of two matrices (or a matrix and a scalar).
296 
297 @param src1 First source matrix or scalar.
298 @param src2 Second source matrix or scalar.
299 @param dst Destination matrix that has the same size and type as the input array(s).
300 @param stream Stream for the asynchronous version.
301 
302 @sa min
303  */
304 CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
305 
306 /** @brief Computes the per-element maximum of two matrices (or a matrix and a scalar).
307 
308 @param src1 First source matrix or scalar.
309 @param src2 Second source matrix or scalar.
310 @param dst Destination matrix that has the same size and type as the input array(s).
311 @param stream Stream for the asynchronous version.
312 
313 @sa max
314  */
315 CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst, Stream& stream = Stream::Null());
316 
317 /** @brief Computes the weighted sum of two arrays.
318 
319 @param src1 First source array.
320 @param alpha Weight for the first array elements.
321 @param src2 Second source array of the same size and channel number as src1 .
322 @param beta Weight for the second array elements.
323 @param dst Destination array that has the same size and number of channels as the input arrays.
324 @param gamma Scalar added to each sum.
325 @param dtype Optional depth of the destination array. When both input arrays have the same depth,
326 dtype can be set to -1, which will be equivalent to src1.depth().
327 @param stream Stream for the asynchronous version.
328 
329 The function addWeighted calculates the weighted sum of two arrays as follows:
330 
331 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )\f]
332 
333 where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each
334 channel is processed independently.
335 
336 @sa addWeighted
337  */
338 CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst,
339                             int dtype = -1, Stream& stream = Stream::Null());
340 
341 //! adds scaled array to another one (dst = alpha*src1 + src2)
scaleAdd(InputArray src1,double alpha,InputArray src2,OutputArray dst,Stream & stream=Stream::Null ())342 static inline void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst, Stream& stream = Stream::Null())
343 {
344     addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
345 }
346 
347 /** @brief Applies a fixed-level threshold to each array element.
348 
349 @param src Source array (single-channel).
350 @param dst Destination array with the same size and type as src .
351 @param thresh Threshold value.
352 @param maxval Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
353 @param type Threshold type. For details, see threshold . The THRESH_OTSU and THRESH_TRIANGLE
354 threshold types are not supported.
355 @param stream Stream for the asynchronous version.
356 
357 @sa threshold
358  */
359 CV_EXPORTS_W double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());
360 
361 /** @brief  Checks if array elements lie between two scalars.
362 
363 The function checks the range as follows:
364 -   For every element of a single-channel input array:
365     \f[\texttt{dst} (I)= \texttt{lowerb}_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb}_0\f]
366 -   For two-channel arrays:
367     \f[\texttt{dst} (I)= \texttt{lowerb}_0  \leq \texttt{src} (I)_0 \leq  \texttt{upperb}_0  \land \texttt{lowerb}_1  \leq \texttt{src} (I)_1 \leq  \texttt{upperb}_1\f]
368 -   and so forth.
369 
370 That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the
371 specified 1D, 2D, 3D, ... box and 0 otherwise.
372 
373 Note that unlike the CPU inRange, this does NOT accept an array for lowerb or
374 upperb, only a cv::Scalar.
375 
376 @param src first input array.
377 @param lowerb inclusive lower boundary cv::Scalar.
378 @param upperb inclusive upper boundary cv::Scalar.
379 @param dst output array of the same size as src and CV_8U type.
380 @param stream Stream for the asynchronous version.
381 
382 @sa cv::inRange
383  */
384 CV_EXPORTS_W void inRange(InputArray src, const Scalar& lowerb, const Scalar& upperb, OutputArray dst, Stream& stream = Stream::Null());
385 
386 /** @brief Computes magnitudes of complex matrix elements.
387 
388 @param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
389 @param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
390 @param stream Stream for the asynchronous version.
391 
392 @sa magnitude
393  */
394 CV_EXPORTS_W void magnitude(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
395 
396 /** @brief Computes squared magnitudes of complex matrix elements.
397 
398 @param xy Source complex matrix in the interleaved format ( CV_32FC2 ).
399 @param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
400 @param stream Stream for the asynchronous version.
401  */
402 CV_EXPORTS_W void magnitudeSqr(InputArray xy, OutputArray magnitude, Stream& stream = Stream::Null());
403 
404 /** @overload
405  computes magnitude of each (x(i), y(i)) vector
406  supports only floating-point source
407 @param x Source matrix containing real components ( CV_32FC1 ).
408 @param y Source matrix containing imaginary components ( CV_32FC1 ).
409 @param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
410 @param stream Stream for the asynchronous version.
411  */
412 CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
413 
414 /** @overload
415  computes squared magnitude of each (x(i), y(i)) vector
416  supports only floating-point source
417 @param x Source matrix containing real components ( CV_32FC1 ).
418 @param y Source matrix containing imaginary components ( CV_32FC1 ).
419 @param magnitude Destination matrix of float magnitude squares ( CV_32FC1 ).
420 @param stream Stream for the asynchronous version.
421 */
422 CV_EXPORTS_W void magnitudeSqr(InputArray x, InputArray y, OutputArray magnitude, Stream& stream = Stream::Null());
423 
424 /** @brief Computes polar angles of complex matrix elements.
425 
426 @param x Source matrix containing real components ( CV_32FC1 ).
427 @param y Source matrix containing imaginary components ( CV_32FC1 ).
428 @param angle Destination matrix of angles ( CV_32FC1 ).
429 @param angleInDegrees Flag for angles that must be evaluated in degrees.
430 @param stream Stream for the asynchronous version.
431 
432 @sa phase
433  */
434 CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
435 
436 /** @brief Converts Cartesian coordinates into polar.
437 
438 @param x Source matrix containing real components ( CV_32FC1 ).
439 @param y Source matrix containing imaginary components ( CV_32FC1 ).
440 @param magnitude Destination matrix of float magnitudes ( CV_32FC1 ).
441 @param angle Destination matrix of angles ( CV_32FC1 ).
442 @param angleInDegrees Flag for angles that must be evaluated in degrees.
443 @param stream Stream for the asynchronous version.
444 
445 @sa cartToPolar
446  */
447 CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y, OutputArray magnitude, OutputArray angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
448 
449 /** @brief Converts polar coordinates into Cartesian.
450 
451 @param magnitude Source matrix containing magnitudes ( CV_32FC1 or CV_64FC1 ).
452 @param angle Source matrix containing angles ( same type as magnitude ).
453 @param x Destination matrix of real components ( same type as magnitude ).
454 @param y Destination matrix of imaginary components ( same type as magnitude ).
455 @param angleInDegrees Flag that indicates angles in degrees.
456 @param stream Stream for the asynchronous version.
457  */
458 CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle, OutputArray x, OutputArray y, bool angleInDegrees = false, Stream& stream = Stream::Null());
459 
460 //! @} cudaarithm_elem
461 
462 //! @addtogroup cudaarithm_core
463 //! @{
464 
465 /** @brief Makes a multi-channel matrix out of several single-channel matrices.
466 
467 @param src Array/vector of source matrices.
468 @param n Number of source matrices.
469 @param dst Destination matrix.
470 @param stream Stream for the asynchronous version.
471 
472 @sa merge
473  */
474 CV_EXPORTS void merge(const GpuMat* src, size_t n, OutputArray dst, Stream& stream = Stream::Null());
475 /** @overload */
476 CV_EXPORTS_W void merge(const std::vector<GpuMat>& src, OutputArray dst, Stream& stream = Stream::Null());
477 
478 /** @brief Copies each plane of a multi-channel matrix into an array.
479 
480 @param src Source matrix.
481 @param dst Destination array/vector of single-channel matrices.
482 @param stream Stream for the asynchronous version.
483 
484 @sa split
485  */
486 CV_EXPORTS void split(InputArray src, GpuMat* dst, Stream& stream = Stream::Null());
487 /** @overload */
488 CV_EXPORTS_W void split(InputArray src, CV_OUT std::vector<GpuMat>& dst, Stream& stream = Stream::Null());
489 
490 /** @brief Transposes a matrix.
491 
492 @param src1 Source matrix. 1-, 4-, 8-byte element sizes are supported for now.
493 @param dst Destination matrix.
494 @param stream Stream for the asynchronous version.
495 
496 @sa transpose
497  */
498 CV_EXPORTS_W void transpose(InputArray src1, OutputArray dst, Stream& stream = Stream::Null());
499 
500 /** @brief Flips a 2D matrix around vertical, horizontal, or both axes.
501 
502 @param src Source matrix. Supports 1, 3 and 4 channels images with CV_8U, CV_16U, CV_32S or
503 CV_32F depth.
504 @param dst Destination matrix.
505 @param flipCode Flip mode for the source:
506 -   0 Flips around x-axis.
507 -   \> 0 Flips around y-axis.
508 -   \< 0 Flips around both axes.
509 @param stream Stream for the asynchronous version.
510 
511 @sa flip
512  */
513 CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode, Stream& stream = Stream::Null());
514 
515 /** @brief Base class for transform using lookup table.
516  */
517 class CV_EXPORTS_W LookUpTable : public Algorithm
518 {
519 public:
520     /** @brief Transforms the source matrix into the destination matrix using the given look-up table:
521     dst(I) = lut(src(I)) .
522 
523     @param src Source matrix. CV_8UC1 and CV_8UC3 matrices are supported for now.
524     @param dst Destination matrix.
525     @param stream Stream for the asynchronous version.
526      */
527     CV_WRAP virtual void transform(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
528 };
529 
530 /** @brief Creates implementation for cuda::LookUpTable .
531 
532 @param lut Look-up table of 256 elements. It is a continuous CV_8U matrix.
533  */
534 CV_EXPORTS_W Ptr<LookUpTable> createLookUpTable(InputArray lut);
535 
536 /** @brief Forms a border around an image.
537 
538 @param src Source image. CV_8UC1 , CV_8UC4 , CV_32SC1 , and CV_32FC1 types are supported.
539 @param dst Destination image with the same type as src. The size is
540 Size(src.cols+left+right, src.rows+top+bottom) .
541 @param top Number of top pixels
542 @param bottom Number of bottom pixels
543 @param left Number of left pixels
544 @param right Number of pixels in each direction from the source image rectangle to extrapolate.
545 For example: top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
546 @param borderType Border type. See borderInterpolate for details. BORDER_REFLECT101 ,
547 BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
548 @param value Border value.
549 @param stream Stream for the asynchronous version.
550  */
551 CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType,
552                                Scalar value = Scalar(), Stream& stream = Stream::Null());
553 
554 //! @} cudaarithm_core
555 
556 //! @addtogroup cudaarithm_reduce
557 //! @{
558 
559 /** @brief Returns the norm of a matrix (or difference of two matrices).
560 
561 @param src1 Source matrix. Any matrices except 64F are supported.
562 @param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
563 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
564 
565 @sa norm
566  */
567 CV_EXPORTS_W double norm(InputArray src1, int normType, InputArray mask = noArray());
568 /** @overload */
569 CV_EXPORTS_W void calcNorm(InputArray src, OutputArray dst, int normType, InputArray mask = noArray(), Stream& stream = Stream::Null());
570 
571 /** @brief Returns the difference of two matrices.
572 
573 @param src1 Source matrix. Any matrices except 64F are supported.
574 @param src2 Second source matrix (if any) with the same size and type as src1.
575 @param normType Norm type. NORM_L1 , NORM_L2 , and NORM_INF are supported for now.
576 
577 @sa norm
578  */
579 CV_EXPORTS_W double norm(InputArray src1, InputArray src2, int normType=NORM_L2);
580 /** @overload */
581 CV_EXPORTS_W void calcNormDiff(InputArray src1, InputArray src2, OutputArray dst, int normType=NORM_L2, Stream& stream = Stream::Null());
582 
583 /** @brief Returns the sum of matrix elements.
584 
585 @param src Source image of any depth except for CV_64F .
586 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
587 
588 @sa sum
589  */
590 CV_EXPORTS_W Scalar sum(InputArray src, InputArray mask = noArray());
591 /** @overload */
592 CV_EXPORTS_W void calcSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
593 
594 /** @brief Returns the sum of absolute values for matrix elements.
595 
596 @param src Source image of any depth except for CV_64F .
597 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
598  */
599 CV_EXPORTS_W Scalar absSum(InputArray src, InputArray mask = noArray());
600 /** @overload */
601 CV_EXPORTS_W void calcAbsSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
602 
603 /** @brief Returns the squared sum of matrix elements.
604 
605 @param src Source image of any depth except for CV_64F .
606 @param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
607  */
608 CV_EXPORTS_W Scalar sqrSum(InputArray src, InputArray mask = noArray());
609 /** @overload */
610 CV_EXPORTS_W void calcSqrSum(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
611 
612 /** @brief Finds global minimum and maximum matrix elements and returns their values.
613 
614 @param src Single-channel source image.
615 @param minVal Pointer to the returned minimum value. Use NULL if not required.
616 @param maxVal Pointer to the returned maximum value. Use NULL if not required.
617 @param mask Optional mask to select a sub-matrix.
618 
619 The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
620 
621 @sa minMaxLoc
622  */
623 CV_EXPORTS_W void minMax(InputArray src, double* minVal, double* maxVal, InputArray mask = noArray());
624 /** @overload */
625 CV_EXPORTS_W void findMinMax(InputArray src, OutputArray dst, InputArray mask = noArray(), Stream& stream = Stream::Null());
626 
627 /** @brief Finds global minimum and maximum matrix elements and returns their values with locations.
628 
629 @param src Single-channel source image.
630 @param minVal Pointer to the returned minimum value. Use NULL if not required.
631 @param maxVal Pointer to the returned maximum value. Use NULL if not required.
632 @param minLoc Pointer to the returned minimum location. Use NULL if not required.
633 @param maxLoc Pointer to the returned maximum location. Use NULL if not required.
634 @param mask Optional mask to select a sub-matrix.
635 
636 The function does not work with CV_64F images on GPU with the compute capability \< 1.3.
637 
638 @sa minMaxLoc
639  */
640 CV_EXPORTS_W void minMaxLoc(InputArray src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
641                           InputArray mask = noArray());
642 /** @overload */
643 CV_EXPORTS_W void findMinMaxLoc(InputArray src, OutputArray minMaxVals, OutputArray loc,
644                               InputArray mask = noArray(), Stream& stream = Stream::Null());
645 
646 /** @brief Counts non-zero matrix elements.
647 
648 @param src Single-channel source image.
649 
650 The function does not work with CV_64F images on GPUs with the compute capability \< 1.3.
651 
652 @sa countNonZero
653  */
654 CV_EXPORTS_W int countNonZero(InputArray src);
655 /** @overload */
656 CV_EXPORTS_W void countNonZero(InputArray src, OutputArray dst, Stream& stream = Stream::Null());
657 
658 /** @brief Reduces a matrix to a vector.
659 
660 @param mtx Source 2D matrix.
661 @param vec Destination vector. Its size and type is defined by dim and dtype parameters.
662 @param dim Dimension index along which the matrix is reduced. 0 means that the matrix is reduced
663 to a single row. 1 means that the matrix is reduced to a single column.
664 @param reduceOp Reduction operation that could be one of the following:
665 -   **CV_REDUCE_SUM** The output is the sum of all rows/columns of the matrix.
666 -   **CV_REDUCE_AVG** The output is the mean vector of all rows/columns of the matrix.
667 -   **CV_REDUCE_MAX** The output is the maximum (column/row-wise) of all rows/columns of the
668 matrix.
669 -   **CV_REDUCE_MIN** The output is the minimum (column/row-wise) of all rows/columns of the
670 matrix.
671 @param dtype When it is negative, the destination vector will have the same type as the source
672 matrix. Otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels()) .
673 @param stream Stream for the asynchronous version.
674 
675 The function reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of
676 1D vectors and performing the specified operation on the vectors until a single row/column is
677 obtained. For example, the function can be used to compute horizontal and vertical projections of a
678 raster image. In case of CV_REDUCE_SUM and CV_REDUCE_AVG , the output may have a larger element
679 bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction
680 modes.
681 
682 @sa reduce
683  */
684 CV_EXPORTS_W void reduce(InputArray mtx, OutputArray vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
685 
686 /** @brief Computes a mean value and a standard deviation of matrix elements.
687 
688 @param mtx Source matrix. CV_8UC1 matrices are supported for now.
689 @param mean Mean value.
690 @param stddev Standard deviation value.
691 
692 @sa meanStdDev
693  */
694 CV_EXPORTS_W void meanStdDev(InputArray mtx, Scalar& mean, Scalar& stddev);
695 /** @overload */
696 CV_EXPORTS_W void meanStdDev(InputArray mtx, OutputArray dst, Stream& stream = Stream::Null());
697 
698 /** @brief Computes a standard deviation of integral images.
699 
700 @param src Source image. Only the CV_32SC1 type is supported.
701 @param sqr Squared source image. Only the CV_32FC1 type is supported.
702 @param dst Destination image with the same type and size as src .
703 @param rect Rectangular window.
704 @param stream Stream for the asynchronous version.
705  */
706 CV_EXPORTS_W void rectStdDev(InputArray src, InputArray sqr, OutputArray dst, Rect rect, Stream& stream = Stream::Null());
707 
708 /** @brief Normalizes the norm or value range of an array.
709 
710 @param src Input array.
711 @param dst Output array of the same size as src .
712 @param alpha Norm value to normalize to or the lower range boundary in case of the range
713 normalization.
714 @param beta Upper range boundary in case of the range normalization; it is not used for the norm
715 normalization.
716 @param norm_type Normalization type ( NORM_MINMAX , NORM_L2 , NORM_L1 or NORM_INF ).
717 @param dtype When negative, the output array has the same type as src; otherwise, it has the same
718 number of channels as src and the depth =CV_MAT_DEPTH(dtype).
719 @param mask Optional operation mask.
720 @param stream Stream for the asynchronous version.
721 
722 @sa normalize
723  */
724 CV_EXPORTS_W void normalize(InputArray src, OutputArray dst, double alpha, double beta,
725                           int norm_type, int dtype, InputArray mask = noArray(),
726                           Stream& stream = Stream::Null());
727 
728 /** @brief Computes an integral image.
729 
730 @param src Source image. Only CV_8UC1 images are supported for now.
731 @param sum Integral image containing 32-bit unsigned integer values packed into CV_32SC1 .
732 @param stream Stream for the asynchronous version.
733 
734 @sa integral
735  */
736 CV_EXPORTS_W void integral(InputArray src, OutputArray sum, Stream& stream = Stream::Null());
737 
738 /** @brief Computes a squared integral image.
739 
740 @param src Source image. Only CV_8UC1 images are supported for now.
741 @param sqsum Squared integral image containing 64-bit unsigned integer values packed into
742 CV_64FC1 .
743 @param stream Stream for the asynchronous version.
744  */
745 CV_EXPORTS_W void sqrIntegral(InputArray src, OutputArray sqsum, Stream& stream = Stream::Null());
746 
747 //! @} cudaarithm_reduce
748 
749 //! @addtogroup cudaarithm_arithm
750 //! @{
751 
752 /** @brief Performs generalized matrix multiplication.
753 
754 @param src1 First multiplied input matrix that should have CV_32FC1 , CV_64FC1 , CV_32FC2 , or
755 CV_64FC2 type.
756 @param src2 Second multiplied input matrix of the same type as src1 .
757 @param alpha Weight of the matrix product.
758 @param src3 Third optional delta matrix added to the matrix product. It should have the same type
759 as src1 and src2 .
760 @param beta Weight of src3 .
761 @param dst Destination matrix. It has the proper size and the same type as input matrices.
762 @param flags Operation flags:
763 -   **GEMM_1_T** transpose src1
764 -   **GEMM_2_T** transpose src2
765 -   **GEMM_3_T** transpose src3
766 @param stream Stream for the asynchronous version.
767 
768 The function performs generalized matrix multiplication similar to the gemm functions in BLAS level
769 3. For example, gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T) corresponds to
770 
771 \f[\texttt{dst} =  \texttt{alpha} \cdot \texttt{src1} ^T  \cdot \texttt{src2} +  \texttt{beta} \cdot \texttt{src3} ^T\f]
772 
773 @note Transposition operation doesn't support CV_64FC2 input type.
774 
775 @sa gemm
776  */
777 CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
778                      InputArray src3, double beta, OutputArray dst, int flags = 0, Stream& stream = Stream::Null());
779 
780 /** @brief Performs a per-element multiplication of two Fourier spectrums.
781 
782 @param src1 First spectrum.
783 @param src2 Second spectrum with the same size and type as a .
784 @param dst Destination spectrum.
785 @param flags Mock parameter used for CPU/CUDA interfaces similarity.
786 @param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
787 multiplication.
788 @param stream Stream for the asynchronous version.
789 
790 Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
791 
792 @sa mulSpectrums
793  */
794 CV_EXPORTS_W void mulSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, bool conjB=false, Stream& stream = Stream::Null());
795 
796 /** @brief Performs a per-element multiplication of two Fourier spectrums and scales the result.
797 
798 @param src1 First spectrum.
799 @param src2 Second spectrum with the same size and type as a .
800 @param dst Destination spectrum.
801 @param flags Mock parameter used for CPU/CUDA interfaces similarity, simply add a `0` value.
802 @param scale Scale constant.
803 @param conjB Optional flag to specify if the second spectrum needs to be conjugated before the
804 multiplication.
805 @param stream Stream for the asynchronous version.
806 
807 Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.
808 
809 @sa mulSpectrums
810  */
811 CV_EXPORTS_W void mulAndScaleSpectrums(InputArray src1, InputArray src2, OutputArray dst, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null());
812 
813 /** @brief Performs a forward or inverse discrete Fourier transform (1D or 2D) of the floating point matrix.
814 
815 @param src Source matrix (real or complex).
816 @param dst Destination matrix (real or complex).
817 @param dft_size Size of a discrete Fourier transform.
818 @param flags Optional flags:
819 -   **DFT_ROWS** transforms each individual row of the source matrix.
820 -   **DFT_SCALE** scales the result: divide it by the number of elements in the transform
821 (obtained from dft_size ).
822 -   **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real
823 cases are always forward and inverse, respectively).
824 -   **DFT_COMPLEX_INPUT** Specifies that input is complex input with 2 channels.
825 -   **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of
826 real-complex transform, so the destination matrix must be real.
827 @param stream Stream for the asynchronous version.
828 
829 Use to handle real matrices ( CV32FC1 ) and complex matrices in the interleaved format ( CV32FC2 ).
830 
831 The source matrix should be continuous, otherwise reallocation and data copying is performed. The
832 function chooses an operation mode depending on the flags, size, and channel count of the source
833 matrix:
834 
835 -   If the source matrix is complex and the output is not specified as real, the destination
836 matrix is complex and has the dft_size size and CV_32FC2 type. The destination matrix
837 contains a full result of the DFT (forward or inverse).
838 -   If the source matrix is complex and the output is specified as real, the function assumes that
839 its input is the result of the forward transform (see the next item). The destination matrix
840 has the dft_size size and CV_32FC1 type. It contains the result of the inverse DFT.
841 -   If the source matrix is real (its type is CV_32FC1 ), forward DFT is performed. The result of
842 the DFT is packed into complex ( CV_32FC2 ) matrix. So, the width of the destination matrix
843 is dft_size.width / 2 + 1 . But if the source is a single column, the height is reduced
844 instead of the width.
845 
846 @sa dft
847  */
848 CV_EXPORTS_W void dft(InputArray src, OutputArray dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
849 
850 /** @brief Base class for DFT operator as a cv::Algorithm. :
851  */
852 class CV_EXPORTS_W DFT : public Algorithm
853 {
854 public:
855     /** @brief Computes an FFT of a given image.
856 
857     @param image Source image. Only CV_32FC1 images are supported for now.
858     @param result Result image.
859     @param stream Stream for the asynchronous version.
860      */
861     CV_WRAP virtual void compute(InputArray image, OutputArray result, Stream& stream = Stream::Null()) = 0;
862 };
863 
864 /** @brief Creates implementation for cuda::DFT.
865 
866 @param dft_size The image size.
867 @param flags Optional flags:
868 -   **DFT_ROWS** transforms each individual row of the source matrix.
869 -   **DFT_SCALE** scales the result: divide it by the number of elements in the transform
870 (obtained from dft_size ).
871 -   **DFT_INVERSE** inverts DFT. Use for complex-complex cases (real-complex and complex-real
872 cases are always forward and inverse, respectively).
873 -   **DFT_COMPLEX_INPUT** Specifies that inputs will be complex with 2 channels.
874 -   **DFT_REAL_OUTPUT** specifies the output as real. The source matrix is the result of
875 real-complex transform, so the destination matrix must be real.
876  */
877 CV_EXPORTS_W Ptr<DFT> createDFT(Size dft_size, int flags);
878 
879 /** @brief Base class for convolution (or cross-correlation) operator. :
880  */
881 class CV_EXPORTS_W Convolution : public Algorithm
882 {
883 public:
884     /** @brief Computes a convolution (or cross-correlation) of two images.
885 
886     @param image Source image. Only CV_32FC1 images are supported for now.
887     @param templ Template image. The size is not greater than the image size. The type is the same as
888     image .
889     @param result Result image. If image is *W x H* and templ is *w x h*, then result must be *W-w+1 x
890     H-h+1*.
891     @param ccorr Flags to evaluate cross-correlation instead of convolution.
892     @param stream Stream for the asynchronous version.
893      */
894     CV_WRAP virtual void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null()) = 0;
895 };
896 
897 /** @brief Creates implementation for cuda::Convolution .
898 
899 @param user_block_size Block size. If you leave default value Size(0,0) then automatic
900 estimation of block size will be used (which is optimized for speed). By varying user_block_size
901 you can reduce memory requirements at the cost of speed.
902  */
903 CV_EXPORTS_W Ptr<Convolution> createConvolution(Size user_block_size = Size());
904 
905 //! @} cudaarithm_arithm
906 
907 //! @} cudaarithm
908 
909 }} // namespace cv { namespace cuda {
910 
911 #endif /* OPENCV_CUDAARITHM_HPP */
912