CLAHE Python bindings
[profile/ivi/opencv.git] / modules / imgproc / doc / filtering.rst
1 Image Filtering
2 ===============
3
4 .. highlight:: cpp
5
6 Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images (represented as
7 :ocv:func:`Mat`'s). It means that for each pixel location
8 :math:`(x,y)` in the source image (normally, rectangular), its neighborhood is considered and used to compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of morphological operations, it is the minimum or maximum values, and so on. The computed response is stored in the destination image at the same location
9 :math:`(x,y)` . It means that the output image will be of the same size as the input image. Normally, the functions support multi-channel arrays, in which case every channel is processed independently. Therefore, the output image will also have the same number of channels as the input one.
10
11 Another common feature of the functions and classes described in this section is that, unlike simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For example, if you want to smooth an image using a Gaussian
12 :math:`3 \times 3` filter, then, when processing the left-most pixels in each row, you need pixels to the left of them, that is, outside of the image. You can let these pixels be the same as the left-most image pixels ("replicated border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant border" extrapolation method), and so on.
13 OpenCV enables you to specify the extrapolation method. For details, see the function  :ocv:func:`borderInterpolate`  and discussion of the  ``borderType``  parameter in the section and various functions below. ::
14
15    /*
16     Various border types, image boundaries are denoted with '|'
17
18     * BORDER_REPLICATE:     aaaaaa|abcdefgh|hhhhhhh
19     * BORDER_REFLECT:       fedcba|abcdefgh|hgfedcb
20     * BORDER_REFLECT_101:   gfedcb|abcdefgh|gfedcba
21     * BORDER_WRAP:          cdefgh|abcdefgh|abcdefg
22     * BORDER_CONSTANT:      iiiiii|abcdefgh|iiiiiii  with some specified 'i'
23     */
24
25 BaseColumnFilter
26 ----------------
27 .. ocv:class:: BaseColumnFilter
28
29 Base class for filters with single-column kernels. ::
30
31     class BaseColumnFilter
32     {
33     public:
34         virtual ~BaseColumnFilter();
35
36         // To be overriden by the user.
37         //
38         // runs a filtering operation on the set of rows,
39         // "dstcount + ksize - 1" rows on input,
40         // "dstcount" rows on output,
41         // each input and output row has "width" elements
42         // the filtered rows are written into "dst" buffer.
43         virtual void operator()(const uchar** src, uchar* dst, int dststep,
44                                 int dstcount, int width) = 0;
45         // resets the filter state (may be needed for IIR filters)
46         virtual void reset();
47
48         int ksize; // the aperture size
49         int anchor; // position of the anchor point,
50                     // normally not used during the processing
51     };
52
53
54 The class ``BaseColumnFilter`` is a base class for filtering data using single-column kernels. Filtering does not have to be a linear operation. In general, it could be written as follows:
55
56 .. math::
57
58     \texttt{dst} (x,y) = F( \texttt{src} [y](x), \; \texttt{src} [y+1](x), \; ..., \; \texttt{src} [y+ \texttt{ksize} -1](x)
59
60 where
61 :math:`F` is a filtering function but, as it is represented as a class, it can produce any side effects, memorize previously processed data, and so on. The class only defines an interface and is not used directly. Instead, there are several functions in OpenCV (and you can add more) that return pointers to the derived classes that implement specific filtering operations. Those pointers are then passed to the
62 :ocv:class:`FilterEngine` constructor. While the filtering operation interface uses the ``uchar`` type, a particular implementation is not limited to 8-bit data.
63
64 .. seealso::
65
66    :ocv:class:`BaseRowFilter`,
67    :ocv:class:`BaseFilter`,
68    :ocv:class:`FilterEngine`,
69    :ocv:func:`getColumnSumFilter`,
70    :ocv:func:`getLinearColumnFilter`,
71    :ocv:func:`getMorphologyColumnFilter`
72
73
74 BaseFilter
75 ----------
76 .. ocv:class:: BaseFilter
77
78 Base class for 2D image filters. ::
79
80     class BaseFilter
81     {
82     public:
83         virtual ~BaseFilter();
84
85         // To be overriden by the user.
86         //
87         // runs a filtering operation on the set of rows,
88         // "dstcount + ksize.height - 1" rows on input,
89         // "dstcount" rows on output,
90         // each input row has "(width + ksize.width-1)*cn" elements
91         // each output row has "width*cn" elements.
92         // the filtered rows are written into "dst" buffer.
93         virtual void operator()(const uchar** src, uchar* dst, int dststep,
94                                 int dstcount, int width, int cn) = 0;
95         // resets the filter state (may be needed for IIR filters)
96         virtual void reset();
97         Size ksize;
98         Point anchor;
99     };
100
101
102 The class ``BaseFilter`` is a base class for filtering data using 2D kernels. Filtering does not have to be a linear operation. In general, it could be written as follows:
103
104 .. math::
105
106     \begin{array}{l} \texttt{dst} (x,y) = F(  \texttt{src} [y](x), \; \texttt{src} [y](x+1), \; ..., \; \texttt{src} [y](x+ \texttt{ksize.width} -1),  \\ \texttt{src} [y+1](x), \; \texttt{src} [y+1](x+1), \; ..., \; \texttt{src} [y+1](x+ \texttt{ksize.width} -1),  \\ .........................................................................................  \\ \texttt{src} [y+ \texttt{ksize.height-1} ](x), \\ \texttt{src} [y+ \texttt{ksize.height-1} ](x+1), \\ ...
107        \texttt{src} [y+ \texttt{ksize.height-1} ](x+ \texttt{ksize.width} -1))
108        \end{array}
109
110 where
111 :math:`F` is a filtering function. The class only defines an interface and is not used directly. Instead, there are several functions in OpenCV (and you can add more) that return pointers to the derived classes that implement specific filtering operations. Those pointers are then passed to the
112 :ocv:class:`FilterEngine` constructor. While the filtering operation interface uses the ``uchar`` type, a particular implementation is not limited to 8-bit data.
113
114 .. seealso::
115
116     :ocv:class:`BaseColumnFilter`,
117     :ocv:class:`BaseRowFilter`,
118     :ocv:class:`FilterEngine`,
119     :ocv:func:`getLinearFilter`,
120     :ocv:func:`getMorphologyFilter`
121
122
123
124 BaseRowFilter
125 -------------
126 .. ocv:class:: BaseRowFilter
127
128 Base class for filters with single-row kernels. ::
129
130     class BaseRowFilter
131     {
132     public:
133         virtual ~BaseRowFilter();
134
135         // To be overriden by the user.
136         //
137         // runs filtering operation on the single input row
138         // of "width" element, each element is has "cn" channels.
139         // the filtered row is written into "dst" buffer.
140         virtual void operator()(const uchar* src, uchar* dst,
141                                 int width, int cn) = 0;
142         int ksize, anchor;
143     };
144
145
146 The class ``BaseRowFilter`` is a base class for filtering data using single-row kernels. Filtering does not have to be a linear operation. In general, it could be written as follows:
147
148 .. math::
149
150     \texttt{dst} (x,y) = F( \texttt{src} [y](x), \; \texttt{src} [y](x+1), \; ..., \; \texttt{src} [y](x+ \texttt{ksize.width} -1))
151
152 where
153 :math:`F` is a filtering function. The class only defines an interface and is not used directly. Instead, there are several functions in OpenCV (and you can add more) that return pointers to the derived classes that implement specific filtering operations. Those pointers are then passed to the
154 :ocv:class:`FilterEngine` constructor. While the filtering operation interface uses the ``uchar`` type, a particular implementation is not limited to 8-bit data.
155
156 .. seealso::
157
158     :ocv:class:`BaseColumnFilter`,
159     :ocv:class:`BaseFilter`,
160     :ocv:class:`FilterEngine`,
161     :ocv:func:`getLinearRowFilter`,
162     :ocv:func:`getMorphologyRowFilter`,
163     :ocv:func:`getRowSumFilter`
164
165
166
167 FilterEngine
168 ------------
169 .. ocv:class:: FilterEngine
170
171 Generic image filtering class. ::
172
173     class FilterEngine
174     {
175     public:
176         // empty constructor
177         FilterEngine();
178         // builds a 2D non-separable filter (!_filter2D.empty()) or
179         // a separable filter (!_rowFilter.empty() && !_columnFilter.empty())
180         // the input data type will be "srcType", the output data type will be "dstType",
181         // the intermediate data type is "bufType".
182         // _rowBorderType and _columnBorderType determine how the image
183         // will be extrapolated beyond the image boundaries.
184         // _borderValue is only used when _rowBorderType and/or _columnBorderType
185         // == BORDER_CONSTANT
186         FilterEngine(const Ptr<BaseFilter>& _filter2D,
187                      const Ptr<BaseRowFilter>& _rowFilter,
188                      const Ptr<BaseColumnFilter>& _columnFilter,
189                      int srcType, int dstType, int bufType,
190                      int _rowBorderType=BORDER_REPLICATE,
191                      int _columnBorderType=-1, // use _rowBorderType by default
192                      const Scalar& _borderValue=Scalar());
193         virtual ~FilterEngine();
194         // separate function for the engine initialization
195         void init(const Ptr<BaseFilter>& _filter2D,
196                   const Ptr<BaseRowFilter>& _rowFilter,
197                   const Ptr<BaseColumnFilter>& _columnFilter,
198                   int srcType, int dstType, int bufType,
199                   int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1,
200                   const Scalar& _borderValue=Scalar());
201         // starts filtering of the ROI in an image of size "wholeSize".
202         // returns the starting y-position in the source image.
203         virtual int start(Size wholeSize, Rect roi, int maxBufRows=-1);
204         // alternative form of start that takes the image
205         // itself instead of "wholeSize". Set isolated to true to pretend that
206         // there are no real pixels outside of the ROI
207         // (so that the pixels are extrapolated using the specified border modes)
208         virtual int start(const Mat& src, const Rect& srcRoi=Rect(0,0,-1,-1),
209                           bool isolated=false, int maxBufRows=-1);
210         // processes the next portion of the source image,
211         // "srcCount" rows starting from "src" and
212         // stores the results in "dst".
213         // returns the number of produced rows
214         virtual int proceed(const uchar* src, int srcStep, int srcCount,
215                             uchar* dst, int dstStep);
216         // higher-level function that processes the whole
217         // ROI or the whole image with a single call
218         virtual void apply( const Mat& src, Mat& dst,
219                             const Rect& srcRoi=Rect(0,0,-1,-1),
220                             Point dstOfs=Point(0,0),
221                             bool isolated=false);
222         bool isSeparable() const { return filter2D.empty(); }
223         // how many rows from the input image are not yet processed
224         int remainingInputRows() const;
225         // how many output rows are not yet produced
226         int remainingOutputRows() const;
227         ...
228         // the starting and the ending rows in the source image
229         int startY, endY;
230
231         // pointers to the filters
232         Ptr<BaseFilter> filter2D;
233         Ptr<BaseRowFilter> rowFilter;
234         Ptr<BaseColumnFilter> columnFilter;
235     };
236
237
238 The class ``FilterEngine`` can be used to apply an arbitrary filtering operation to an image.
239 It contains all the necessary intermediate buffers, computes extrapolated values
240 of the "virtual" pixels outside of the image, and so on. Pointers to the initialized ``FilterEngine`` instances
241 are returned by various ``create*Filter`` functions (see below) and they are used inside high-level functions such as
242 :ocv:func:`filter2D`,
243 :ocv:func:`erode`,
244 :ocv:func:`dilate`, and others. Thus, the class plays a key role in many of OpenCV filtering functions.
245
246 This class makes it easier to combine filtering operations with other operations, such as color space conversions, thresholding, arithmetic operations, and others. By combining several operations together you can get much better performance because your data will stay in cache. For example, see below the implementation of the Laplace operator for floating-point images, which is a simplified implementation of
247 :ocv:func:`Laplacian` : ::
248
249     void laplace_f(const Mat& src, Mat& dst)
250     {
251         CV_Assert( src.type() == CV_32F );
252         dst.create(src.size(), src.type());
253
254         // get the derivative and smooth kernels for d2I/dx2.
255         // for d2I/dy2 consider using the same kernels, just swapped
256         Mat kd, ks;
257         getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
258
259         // process 10 source rows at once
260         int DELTA = std::min(10, src.rows);
261         Ptr<FilterEngine> Fxx = createSeparableLinearFilter(src.type(),
262             dst.type(), kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
263         Ptr<FilterEngine> Fyy = createSeparableLinearFilter(src.type(),
264             dst.type(), ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
265
266         int y = Fxx->start(src), dsty = 0, dy = 0;
267         Fyy->start(src);
268         const uchar* sptr = src.data + y*src.step;
269
270         // allocate the buffers for the spatial image derivatives;
271         // the buffers need to have more than DELTA rows, because at the
272         // last iteration the output may take max(kd.rows-1,ks.rows-1)
273         // rows more than the input.
274         Mat Ixx( DELTA + kd.rows - 1, src.cols, dst.type() );
275         Mat Iyy( DELTA + kd.rows - 1, src.cols, dst.type() );
276
277         // inside the loop always pass DELTA rows to the filter
278         // (note that the "proceed" method takes care of possibe overflow, since
279         // it was given the actual image height in the "start" method)
280         // on output you can get:
281         //  * < DELTA rows (initial buffer accumulation stage)
282         //  * = DELTA rows (settled state in the middle)
283         //  * > DELTA rows (when the input image is over, generate
284         //                  "virtual" rows using the border mode and filter them)
285         // this variable number of output rows is dy.
286         // dsty is the current output row.
287         // sptr is the pointer to the first input row in the portion to process
288         for( ; dsty < dst.rows; sptr += DELTA*src.step, dsty += dy )
289         {
290             Fxx->proceed( sptr, (int)src.step, DELTA, Ixx.data, (int)Ixx.step );
291             dy = Fyy->proceed( sptr, (int)src.step, DELTA, d2y.data, (int)Iyy.step );
292             if( dy > 0 )
293             {
294                 Mat dstripe = dst.rowRange(dsty, dsty + dy);
295                 add(Ixx.rowRange(0, dy), Iyy.rowRange(0, dy), dstripe);
296             }
297         }
298     }
299
300
301 If you do not need that much control of the filtering process, you can simply use the ``FilterEngine::apply`` method. The method is implemented as follows: ::
302
303     void FilterEngine::apply(const Mat& src, Mat& dst,
304         const Rect& srcRoi, Point dstOfs, bool isolated)
305     {
306         // check matrix types
307         CV_Assert( src.type() == srcType && dst.type() == dstType );
308
309         // handle the "whole image" case
310         Rect _srcRoi = srcRoi;
311         if( _srcRoi == Rect(0,0,-1,-1) )
312             _srcRoi = Rect(0,0,src.cols,src.rows);
313
314         // check if the destination ROI is inside dst.
315         // and FilterEngine::start will check if the source ROI is inside src.
316         CV_Assert( dstOfs.x >= 0 && dstOfs.y >= 0 &&
317             dstOfs.x + _srcRoi.width <= dst.cols &&
318             dstOfs.y + _srcRoi.height <= dst.rows );
319
320         // start filtering
321         int y = start(src, _srcRoi, isolated);
322
323         // process the whole ROI. Note that "endY - startY" is the total number
324         // of the source rows to process
325         // (including the possible rows outside of srcRoi but inside the source image)
326         proceed( src.data + y*src.step,
327                  (int)src.step, endY - startY,
328                  dst.data + dstOfs.y*dst.step +
329                  dstOfs.x*dst.elemSize(), (int)dst.step );
330     }
331
332
333 Unlike the earlier versions of OpenCV, now the filtering operations fully support the notion of image ROI, that is, pixels outside of the ROI but inside the image can be used in the filtering operations. For example, you can take a ROI of a single pixel and filter it. This will be a filter response at that particular pixel. However, it is possible to emulate the old behavior by passing ``isolated=false`` to ``FilterEngine::start`` or ``FilterEngine::apply`` . You can pass the ROI explicitly to ``FilterEngine::apply``  or construct new matrix headers: ::
334
335     // compute dI/dx derivative at src(x,y)
336
337     // method 1:
338     // form a matrix header for a single value
339     float val1 = 0;
340     Mat dst1(1,1,CV_32F,&val1);
341
342     Ptr<FilterEngine> Fx = createDerivFilter(CV_32F, CV_32F,
343                             1, 0, 3, BORDER_REFLECT_101);
344     Fx->apply(src, Rect(x,y,1,1), Point(), dst1);
345
346     // method 2:
347     // form a matrix header for a single value
348     float val2 = 0;
349     Mat dst2(1,1,CV_32F,&val2);
350
351     Mat pix_roi(src, Rect(x,y,1,1));
352     Sobel(pix_roi, dst2, dst2.type(), 1, 0, 3, 1, 0, BORDER_REFLECT_101);
353
354     printf("method1 =
355
356
357 Explore the data types. As it was mentioned in the
358 :ocv:class:`BaseFilter` description, the specific filters can process data of any type, despite that ``Base*Filter::operator()`` only takes ``uchar`` pointers and no information about the actual types. To make it all work, the following rules are used:
359
360 *
361     In case of separable filtering, ``FilterEngine::rowFilter``   is  applied first. It transforms the input image data (of type ``srcType``  ) to the intermediate results stored in the internal buffers (of type ``bufType``   ). Then, these intermediate results are processed as
362     *single-channel data*
363     with ``FilterEngine::columnFilter``     and stored in the output image (of type ``dstType``     ). Thus, the input type for ``rowFilter``     is ``srcType``     and the output type is ``bufType``  . The input type for ``columnFilter``     is ``CV_MAT_DEPTH(bufType)``     and the output type is ``CV_MAT_DEPTH(dstType)``     .
364
365 *
366     In case of non-separable filtering, ``bufType``     must be the same as ``srcType``     . The source data is copied to the temporary buffer, if needed, and then just passed to ``FilterEngine::filter2D``     . That is, the input type for ``filter2D``     is ``srcType``     (= ``bufType``     ) and the output type is ``dstType``     .
367
368 .. seealso::
369
370    :ocv:class:`BaseColumnFilter`,
371    :ocv:class:`BaseFilter`,
372    :ocv:class:`BaseRowFilter`,
373    :ocv:func:`createBoxFilter`,
374    :ocv:func:`createDerivFilter`,
375    :ocv:func:`createGaussianFilter`,
376    :ocv:func:`createLinearFilter`,
377    :ocv:func:`createMorphologyFilter`,
378    :ocv:func:`createSeparableLinearFilter`
379
380
381
382 bilateralFilter
383 -------------------
384 Applies the bilateral filter to an image.
385
386 .. ocv:function:: void bilateralFilter( InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT )
387
388 .. ocv:pyfunction:: cv2.bilateralFilter(src, d, sigmaColor, sigmaSpace[, dst[, borderType]]) -> dst
389
390     :param src: Source 8-bit or floating-point, 1-channel or 3-channel image.
391
392     :param dst: Destination image of the same size and type as  ``src`` .
393
394     :param d: Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from  ``sigmaSpace`` .
395
396     :param sigmaColor: Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see  ``sigmaSpace`` ) will be mixed together, resulting in larger areas of semi-equal color.
397
398     :param sigmaSpace: Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see  ``sigmaColor`` ). When  ``d>0`` , it specifies the neighborhood size regardless of  ``sigmaSpace`` . Otherwise,  ``d``  is proportional to  ``sigmaSpace`` .
399
400 The function applies bilateral filtering to the input image, as described in
401 http://www.dai.ed.ac.uk/CVonline/LOCAL\_COPIES/MANDUCHI1/Bilateral\_Filtering.html
402 ``bilateralFilter`` can reduce unwanted noise very well while keeping edges fairly sharp. However, it is very slow compared to most filters.
403
404 *Sigma values*: For simplicity, you can set the 2 sigma values to be the same. If they are small (< 10), the filter will not have much effect, whereas if they are large (> 150), they will have a very strong effect, making the image look "cartoonish".
405
406 *Filter size*: Large filters (d > 5) are very slow, so it is recommended to use d=5 for real-time applications, and perhaps d=9 for offline applications that need heavy noise filtering.
407
408 This filter does not work inplace.
409
410
411
412
413 blur
414 ----
415 Blurs an image using the normalized box filter.
416
417 .. ocv:function:: void blur( InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1),           int borderType=BORDER_DEFAULT )
418
419 .. ocv:pyfunction:: cv2.blur(src, ksize[, dst[, anchor[, borderType]]]) -> dst
420
421     :param src: input image; it can have any number of channels, which are processed independently, but the depth should be ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32F`` or ``CV_64F``.
422
423     :param dst: output image of the same size and type as ``src``.
424
425     :param ksize: blurring kernel size.
426
427     :param anchor: anchor point; default value ``Point(-1,-1)`` means that the anchor is at the kernel center.
428
429     :param borderType: border mode used to extrapolate pixels outside of the image.
430
431 The function smoothes an image using the kernel:
432
433 .. math::
434
435     \texttt{K} =  \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \end{bmatrix}
436
437 The call ``blur(src, dst, ksize, anchor, borderType)`` is equivalent to ``boxFilter(src, dst, src.type(), anchor, true, borderType)`` .
438
439 .. seealso::
440
441    :ocv:func:`boxFilter`,
442    :ocv:func:`bilateralFilter`,
443    :ocv:func:`GaussianBlur`,
444    :ocv:func:`medianBlur`
445
446
447 borderInterpolate
448 -----------------
449 Computes the source location of an extrapolated pixel.
450
451 .. ocv:function:: int borderInterpolate( int p, int len, int borderType )
452
453 .. ocv:pyfunction:: cv2.borderInterpolate(p, len, borderType) -> retval
454
455     :param p: 0-based coordinate of the extrapolated pixel along one of the axes, likely <0 or >= ``len`` .
456
457     :param len: Length of the array along the corresponding axis.
458
459     :param borderType: Border type, one of the  ``BORDER_*`` , except for  ``BORDER_TRANSPARENT``  and  ``BORDER_ISOLATED`` . When  ``borderType==BORDER_CONSTANT`` , the function always returns -1, regardless of  ``p``  and  ``len`` .
460
461 The function computes and returns the coordinate of a donor pixel corresponding to the specified extrapolated pixel when using the specified extrapolation border mode. For example, if you use ``BORDER_WRAP`` mode in the horizontal direction, ``BORDER_REFLECT_101`` in the vertical direction and want to compute value of the "virtual" pixel ``Point(-5, 100)`` in a floating-point image ``img`` , it looks like: ::
462
463     float val = img.at<float>(borderInterpolate(100, img.rows, BORDER_REFLECT_101),
464                               borderInterpolate(-5, img.cols, BORDER_WRAP));
465
466
467 Normally, the function is not called directly. It is used inside
468 :ocv:class:`FilterEngine` and
469 :ocv:func:`copyMakeBorder` to compute tables for quick extrapolation.
470
471 .. seealso::
472
473     :ocv:class:`FilterEngine`,
474     :ocv:func:`copyMakeBorder`
475
476
477
478 boxFilter
479 ---------
480 Blurs an image using the box filter.
481
482 .. ocv:function:: void boxFilter( InputArray src, OutputArray dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), bool normalize=true, int borderType=BORDER_DEFAULT )
483
484 .. ocv:pyfunction:: cv2.boxFilter(src, ddepth, ksize[, dst[, anchor[, normalize[, borderType]]]]) -> dst
485
486     :param src: input image.
487
488     :param dst: output image of the same size and type as ``src``.
489
490     :param ddepth: the output image depth (-1 to use ``src.depth()``).
491
492     :param ksize: blurring kernel size.
493
494     :param anchor: anchor point; default value ``Point(-1,-1)`` means that the anchor is at the kernel center.
495
496     :param normalize: flag, specifying whether the kernel is normalized by its area or not.
497
498     :param borderType: border mode used to extrapolate pixels outside of the image.
499
500 The function smoothes an image using the kernel:
501
502 .. math::
503
504     \texttt{K} =  \alpha \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1 \end{bmatrix}
505
506 where
507
508 .. math::
509
510     \alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}
511
512 Unnormalized box filter is useful for computing various integral characteristics over each pixel neighborhood, such as covariance matrices of image derivatives (used in dense optical flow algorithms, and so on). If you need to compute pixel sums over variable-size windows, use :ocv:func:`integral` .
513
514 .. seealso::
515
516     :ocv:func:`blur`,
517     :ocv:func:`bilateralFilter`,
518     :ocv:func:`GaussianBlur`,
519     :ocv:func:`medianBlur`,
520     :ocv:func:`integral`
521
522
523
524 buildPyramid
525 ------------
526 Constructs the Gaussian pyramid for an image.
527
528 .. ocv:function:: void buildPyramid( InputArray src, OutputArrayOfArrays dst, int maxlevel, int borderType=BORDER_DEFAULT )
529
530     :param src: Source image. Check  :ocv:func:`pyrDown`  for the list of supported types.
531
532     :param dst: Destination vector of  ``maxlevel+1``  images of the same type as  ``src`` . ``dst[0]``  will be the same as  ``src`` .  ``dst[1]``  is the next pyramid layer, a smoothed and down-sized  ``src``  , and so on.
533
534     :param maxlevel: 0-based index of the last (the smallest) pyramid layer. It must be non-negative.
535
536 The function constructs a vector of images and builds the Gaussian pyramid by recursively applying
537 :ocv:func:`pyrDown` to the previously built pyramid layers, starting from ``dst[0]==src`` .
538
539
540
541 copyMakeBorder
542 --------------
543 Forms a border around an image.
544
545 .. ocv:function:: void copyMakeBorder( InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() )
546
547 .. ocv:pyfunction:: cv2.copyMakeBorder(src, top, bottom, left, right, borderType[, dst[, value]]) -> dst
548
549 .. ocv:cfunction:: void cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, int bordertype, CvScalar value=cvScalarAll(0) )
550 .. ocv:pyoldfunction:: cv.CopyMakeBorder(src, dst, offset, bordertype, value=(0, 0, 0, 0))-> None
551
552     :param src: Source image.
553
554     :param dst: Destination image of the same type as  ``src``  and the size  ``Size(src.cols+left+right, src.rows+top+bottom)`` .
555
556     :param top:
557
558     :param bottom:
559
560     :param left:
561
562     :param right: Parameter specifying how many pixels in each direction from the source image rectangle to extrapolate. For example,  ``top=1, bottom=1, left=1, right=1``  mean that 1 pixel-wide border needs to be built.
563
564     :param borderType: Border type. See  :ocv:func:`borderInterpolate` for details.
565
566     :param value: Border value if  ``borderType==BORDER_CONSTANT`` .
567
568 The function copies the source image into the middle of the destination image. The areas to the left, to the right, above and below the copied source image will be filled with extrapolated pixels. This is not what
569 :ocv:class:`FilterEngine` or filtering functions based on it do (they extrapolate pixels on-fly), but what other more complex functions, including your own, may do to simplify image boundary handling.
570
571 The function supports the mode when ``src`` is already in the middle of ``dst`` . In this case, the function does not copy ``src`` itself but simply constructs the border, for example: ::
572
573     // let border be the same in all directions
574     int border=2;
575     // constructs a larger image to fit both the image and the border
576     Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth());
577     // select the middle part of it w/o copying data
578     Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows));
579     // convert image from RGB to grayscale
580     cvtColor(rgb, gray, CV_RGB2GRAY);
581     // form a border in-place
582     copyMakeBorder(gray, gray_buf, border, border,
583                    border, border, BORDER_REPLICATE);
584     // now do some custom filtering ...
585     ...
586
587
588 .. note::
589
590     When the source image is a part (ROI) of a bigger image, the function will try to use the pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as if ``src`` was not a ROI, use ``borderType | BORDER_ISOLATED``.
591
592 .. seealso::
593
594     :ocv:func:`borderInterpolate`
595
596
597 createBoxFilter
598 -------------------
599 Returns a box filter engine.
600
601 .. ocv:function:: Ptr<FilterEngine> createBoxFilter( int srcType, int dstType,                                 Size ksize, Point anchor=Point(-1,-1), bool normalize=true, int borderType=BORDER_DEFAULT)
602
603 .. ocv:function:: Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType,                                   int ksize, int anchor=-1)
604
605 .. ocv:function:: Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType,                                   int ksize, int anchor=-1, double scale=1)
606
607     :param srcType: Source image type.
608
609     :param sumType: Intermediate horizontal sum type that must have as many channels as  ``srcType`` .
610
611     :param dstType: Destination image type that must have as many channels as  ``srcType`` .
612
613     :param ksize: Aperture size.
614
615     :param anchor: Anchor position with the kernel. Negative values mean that the anchor is at the kernel center.
616
617     :param normalize: Flag specifying whether the sums are normalized or not. See  :ocv:func:`boxFilter` for details.
618
619     :param scale: Another way to specify normalization in lower-level  ``getColumnSumFilter`` .
620
621     :param borderType: Border type to use. See  :ocv:func:`borderInterpolate` .
622
623 The function is a convenience function that retrieves the horizontal sum primitive filter with
624 :ocv:func:`getRowSumFilter` , vertical sum filter with
625 :ocv:func:`getColumnSumFilter` , constructs new
626 :ocv:class:`FilterEngine` , and passes both of the primitive filters there. The constructed filter engine can be used for image filtering with normalized or unnormalized box filter.
627
628 The function itself is used by
629 :ocv:func:`blur` and
630 :ocv:func:`boxFilter` .
631
632 .. seealso::
633
634     :ocv:class:`FilterEngine`,
635     :ocv:func:`blur`,
636     :ocv:func:`boxFilter`
637
638
639
640 createDerivFilter
641 ---------------------
642 Returns an engine for computing image derivatives.
643
644 .. ocv:function:: Ptr<FilterEngine> createDerivFilter( int srcType, int dstType,                                     int dx, int dy, int ksize, int borderType=BORDER_DEFAULT )
645
646     :param srcType: Source image type.
647
648     :param dstType: Destination image type that must have as many channels as  ``srcType`` .
649
650     :param dx: Derivative order in respect of x.
651
652     :param dy: Derivative order in respect of y.
653
654     :param ksize: Aperture size See  :ocv:func:`getDerivKernels` .
655
656     :param borderType: Border type to use. See  :ocv:func:`borderInterpolate` .
657
658 The function :ocv:func:`createDerivFilter` is a small convenience function that retrieves linear filter coefficients for computing image derivatives using
659 :ocv:func:`getDerivKernels` and then creates a separable linear filter with
660 :ocv:func:`createSeparableLinearFilter` . The function is used by
661 :ocv:func:`Sobel` and
662 :ocv:func:`Scharr` .
663
664 .. seealso::
665
666     :ocv:func:`createSeparableLinearFilter`,
667     :ocv:func:`getDerivKernels`,
668     :ocv:func:`Scharr`,
669     :ocv:func:`Sobel`
670
671
672
673 createGaussianFilter
674 ------------------------
675 Returns an engine for smoothing images with the Gaussian filter.
676
677 .. ocv:function:: Ptr<FilterEngine> createGaussianFilter( int type, Size ksize, double sigma1, double sigma2=0, int borderType=BORDER_DEFAULT )
678
679     :param type: Source and destination image type.
680
681     :param ksize: Aperture size. See  :ocv:func:`getGaussianKernel` .
682
683     :param sigma1: Gaussian sigma in the horizontal direction. See  :ocv:func:`getGaussianKernel` .
684
685     :param sigma2: Gaussian sigma in the vertical direction. If 0, then  :math:`\texttt{sigma2}\leftarrow\texttt{sigma1}` .
686
687     :param borderType: Border type to use. See  :ocv:func:`borderInterpolate` .
688
689 The function :ocv:func:`createGaussianFilter` computes Gaussian kernel coefficients and then returns a separable linear filter for that kernel. The function is used by
690 :ocv:func:`GaussianBlur` . Note that while the function takes just one data type, both for input and output, you can pass this limitation by calling
691 :ocv:func:`getGaussianKernel` and then
692 :ocv:func:`createSeparableLinearFilter` directly.
693
694 .. seealso::
695
696     :ocv:func:`createSeparableLinearFilter`,
697     :ocv:func:`getGaussianKernel`,
698     :ocv:func:`GaussianBlur`
699
700
701
702 createLinearFilter
703 ----------------------
704 Creates a non-separable linear filter engine.
705
706 .. ocv:function:: Ptr<FilterEngine> createLinearFilter( int srcType, int dstType, InputArray kernel, Point _anchor=Point(-1,-1), double delta=0, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, const Scalar& borderValue=Scalar() )
707
708 .. ocv:function:: Ptr<BaseFilter> getLinearFilter(int srcType, int dstType, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int bits=0)
709
710     :param srcType: Source image type.
711
712     :param dstType: Destination image type that must have as many channels as  ``srcType`` .
713
714     :param kernel: 2D array of filter coefficients.
715
716     :param anchor: Anchor point within the kernel. Special value  ``Point(-1,-1)``  means that the anchor is at the kernel center.
717
718     :param delta: Value added to the filtered results before storing them.
719
720     :param bits: Number of the fractional bits. The parameter is used when the kernel is an integer matrix representing fixed-point filter coefficients.
721
722     :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see  :ocv:func:`borderInterpolate`.
723
724     :param columnBorderType: Pixel extrapolation method in the horizontal direction.
725
726     :param borderValue: Border value used in case of a constant border.
727
728 The function returns a pointer to a 2D linear filter for the specified kernel, the source array type, and the destination array type. The function is a higher-level function that calls ``getLinearFilter`` and passes the retrieved 2D filter to the
729 :ocv:class:`FilterEngine` constructor.
730
731 .. seealso::
732
733     :ocv:func:`createSeparableLinearFilter`,
734     :ocv:class:`FilterEngine`,
735     :ocv:func:`filter2D`
736
737
738 createMorphologyFilter
739 --------------------------
740 Creates an engine for non-separable morphological operations.
741
742 .. ocv:function:: Ptr<FilterEngine> createMorphologyFilter( int op, int type, InputArray kernel, Point anchor=Point(-1,-1), int rowBorderType=BORDER_CONSTANT, int columnBorderType=-1, const Scalar& borderValue=morphologyDefaultBorderValue() )
743
744 .. ocv:function:: Ptr<BaseFilter> getMorphologyFilter( int op, int type, InputArray kernel, Point anchor=Point(-1,-1) )
745
746 .. ocv:function:: Ptr<BaseRowFilter> getMorphologyRowFilter( int op, int type, int ksize, int anchor=-1 )
747
748 .. ocv:function:: Ptr<BaseColumnFilter> getMorphologyColumnFilter( int op, int type, int ksize, int anchor=-1 )
749
750 .. ocv:function:: Scalar morphologyDefaultBorderValue()
751
752     :param op: Morphology operation ID,  ``MORPH_ERODE``  or  ``MORPH_DILATE`` .
753
754     :param type: Input/output image type. The number of channels can be arbitrary. The depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``,  ``CV_32F` or ``CV_64F``.
755
756     :param kernel: 2D 8-bit structuring element for a morphological operation. Non-zero elements indicate the pixels that belong to the element.
757
758     :param ksize: Horizontal or vertical structuring element size for separable morphological operations.
759
760     :param anchor: Anchor position within the structuring element. Negative values mean that the anchor is at the kernel center.
761
762     :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see  :ocv:func:`borderInterpolate`.
763
764     :param columnBorderType: Pixel extrapolation method in the horizontal direction.
765
766     :param borderValue: Border value in case of a constant border. The default value, \   ``morphologyDefaultBorderValue`` , has a special meaning. It is transformed  :math:`+\inf`  for the erosion and to  :math:`-\inf`  for the dilation, which means that the minimum (maximum) is effectively computed only over the pixels that are inside the image.
767
768 The functions construct primitive morphological filtering operations or a filter engine based on them. Normally it is enough to use
769 :ocv:func:`createMorphologyFilter` or even higher-level
770 :ocv:func:`erode`,
771 :ocv:func:`dilate` , or
772 :ocv:func:`morphologyEx` .
773 Note that
774 :ocv:func:`createMorphologyFilter` analyzes the structuring element shape and builds a separable morphological filter engine when the structuring element is square.
775
776 .. seealso::
777
778     :ocv:func:`erode`,
779     :ocv:func:`dilate`,
780     :ocv:func:`morphologyEx`,
781     :ocv:class:`FilterEngine`
782
783
784 createSeparableLinearFilter
785 -------------------------------
786 Creates an engine for a separable linear filter.
787
788 .. ocv:function:: Ptr<FilterEngine> createSeparableLinearFilter( int srcType, int dstType, InputArray rowKernel, InputArray columnKernel, Point anchor=Point(-1,-1), double delta=0, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, const Scalar& borderValue=Scalar() )
789
790 .. ocv:function:: Ptr<BaseColumnFilter> getLinearColumnFilter( int bufType, int dstType, InputArray kernel, int anchor, int symmetryType, double delta=0, int bits=0 )
791
792 .. ocv:function:: Ptr<BaseRowFilter> getLinearRowFilter( int srcType, int bufType, InputArray kernel, int anchor, int symmetryType )
793
794     :param srcType: Source array type.
795
796     :param dstType: Destination image type that must have as many channels as  ``srcType`` .
797
798     :param bufType: Intermediate buffer type that must have as many channels as  ``srcType`` .
799
800     :param rowKernel: Coefficients for filtering each row.
801
802     :param columnKernel: Coefficients for filtering each column.
803
804     :param anchor: Anchor position within the kernel. Negative values mean that anchor is positioned at the aperture center.
805
806     :param delta: Value added to the filtered results before storing them.
807
808     :param bits: Number of the fractional bits. The parameter is used when the kernel is an integer matrix representing fixed-point filter coefficients.
809
810     :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see  :ocv:func:`borderInterpolate`.
811
812     :param columnBorderType: Pixel extrapolation method in the horizontal direction.
813
814     :param borderValue: Border value used in case of a constant border.
815
816     :param symmetryType: Type of each row and column kernel. See  :ocv:func:`getKernelType` .
817
818 The functions construct primitive separable linear filtering operations or a filter engine based on them. Normally it is enough to use
819 :ocv:func:`createSeparableLinearFilter` or even higher-level
820 :ocv:func:`sepFilter2D` . The function
821 :ocv:func:`createMorphologyFilter` is smart enough to figure out the ``symmetryType`` for each of the two kernels, the intermediate ``bufType``  and, if filtering can be done in integer arithmetics, the number of ``bits`` to encode the filter coefficients. If it does not work for you, it is possible to call ``getLinearColumnFilter``,``getLinearRowFilter`` directly and then pass them to the
822 :ocv:class:`FilterEngine` constructor.
823
824 .. seealso::
825
826     :ocv:func:`sepFilter2D`,
827     :ocv:func:`createLinearFilter`,
828     :ocv:class:`FilterEngine`,
829     :ocv:func:`getKernelType`
830
831
832 dilate
833 ------
834 Dilates an image by using a specific structuring element.
835
836 .. ocv:function:: void dilate( InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )
837
838 .. ocv:pyfunction:: cv2.dilate(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
839
840 .. ocv:cfunction:: void cvDilate( const CvArr* src, CvArr* dst, IplConvKernel* element=NULL, int iterations=1 )
841 .. ocv:pyoldfunction:: cv.Dilate(src, dst, element=None, iterations=1)-> None
842
843     :param src: input image; the number of channels can be arbitrary, but the depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``,  ``CV_32F` or ``CV_64F``.
844
845     :param dst: output image of the same size and type as ``src``.
846
847     :param element: structuring element used for dilation; if  ``element=Mat()`` , a  ``3 x 3`` rectangular structuring element is used.
848
849     :param anchor: position of the anchor within the element; default value ``(-1, -1)`` means that the anchor is at the element center.
850
851     :param iterations: number of times dilation is applied.
852
853     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
854
855     :param borderValue: border value in case of a constant border (see  :ocv:func:`createMorphologyFilter` for details).
856
857 The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:
858
859 .. math::
860
861     \texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')
862
863 The function supports the in-place mode. Dilation can be applied several ( ``iterations`` ) times. In case of multi-channel images, each channel is processed independently.
864
865 .. seealso::
866
867     :ocv:func:`erode`,
868     :ocv:func:`morphologyEx`,
869     :ocv:func:`createMorphologyFilter`
870
871
872 erode
873 -----
874 Erodes an image by using a specific structuring element.
875
876 .. ocv:function:: void erode( InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )
877
878 .. ocv:pyfunction:: cv2.erode(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
879
880 .. ocv:cfunction:: void cvErode( const CvArr* src, CvArr* dst, IplConvKernel* element=NULL, int iterations=1)
881 .. ocv:pyoldfunction:: cv.Erode(src, dst, element=None, iterations=1)-> None
882
883     :param src: input image; the number of channels can be arbitrary, but the depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``,  ``CV_32F` or ``CV_64F``.
884
885     :param dst: output image of the same size and type as ``src``.
886
887     :param element: structuring element used for erosion; if  ``element=Mat()`` , a  ``3 x 3``  rectangular structuring element is used.
888
889     :param anchor: position of the anchor within the element; default value  ``(-1, -1)``  means that the anchor is at the element center.
890
891     :param iterations: number of times erosion is applied.
892
893     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
894
895     :param borderValue: border value in case of a constant border (see :ocv:func:`createMorphologyFilter` for details).
896
897 The function erodes the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the minimum is taken:
898
899 .. math::
900
901     \texttt{dst} (x,y) =  \min _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')
902
903 The function supports the in-place mode. Erosion can be applied several ( ``iterations`` ) times. In case of multi-channel images, each channel is processed independently.
904
905 .. seealso::
906
907     :ocv:func:`dilate`,
908     :ocv:func:`morphologyEx`,
909     :ocv:func:`createMorphologyFilter`
910
911
912
913 filter2D
914 --------
915 Convolves an image with the kernel.
916
917 .. ocv:function:: void filter2D( InputArray src, OutputArray dst, int ddepth, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT )
918
919 .. ocv:pyfunction:: cv2.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) -> dst
920
921 .. ocv:cfunction:: void cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel, CvPoint anchor=cvPoint(-1,-1) )
922
923 .. ocv:pyoldfunction:: cv.Filter2D(src, dst, kernel, anchor=(-1, -1))-> None
924
925     :param src: input image.
926
927     :param dst: output image of the same size and the same number of channels as ``src``.
928
929
930     :param ddepth: desired depth of the destination image; if it is negative, it will be the same as ``src.depth()``; the following combinations of ``src.depth()`` and ``ddepth`` are supported:
931          * ``src.depth()`` = ``CV_8U``, ``ddepth`` = -1/``CV_16S``/``CV_32F``/``CV_64F``
932          * ``src.depth()`` = ``CV_16U``/``CV_16S``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
933          * ``src.depth()`` = ``CV_32F``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
934          * ``src.depth()`` = ``CV_64F``, ``ddepth`` = -1/``CV_64F``
935
936         when ``ddepth=-1``, the output image will have the same depth as the source.
937
938     :param kernel: convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using  :ocv:func:`split`  and process them individually.
939
940     :param anchor: anchor of the kernel that indicates the relative position of a filtered point within the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor is at the kernel center.
941
942     :param delta: optional value added to the filtered pixels before storing them in ``dst``.
943
944     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
945
946 The function applies an arbitrary linear filter to an image. In-place operation is supported. When the aperture is partially outside the image, the function interpolates outlier pixel values according to the specified border mode.
947
948 The function does actually compute correlation, not the convolution:
949
950 .. math::
951
952     \texttt{dst} (x,y) =  \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} }  \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )
953
954 That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip the kernel using
955 :ocv:func:`flip` and set the new anchor to ``(kernel.cols - anchor.x - 1, kernel.rows - anchor.y - 1)`` .
956
957 The function uses the DFT-based algorithm in case of sufficiently large kernels (~``11 x 11`` or larger) and the direct algorithm (that uses the engine retrieved by :ocv:func:`createLinearFilter` ) for small kernels.
958
959 .. seealso::
960
961     :ocv:func:`sepFilter2D`,
962     :ocv:func:`createLinearFilter`,
963     :ocv:func:`dft`,
964     :ocv:func:`matchTemplate`
965
966
967
968 GaussianBlur
969 ------------
970 Blurs an image using a Gaussian filter.
971
972 .. ocv:function:: void GaussianBlur( InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
973
974 .. ocv:pyfunction:: cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]]) -> dst
975
976     :param src: input image; the image can have any number of channels, which are processed independently, but the depth should be ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32F`` or ``CV_64F``.
977
978     :param dst: output image of the same size and type as ``src``.
979
980     :param ksize: Gaussian kernel size.  ``ksize.width``  and  ``ksize.height``  can differ but they both must be positive and odd. Or, they can be zero's and then they are computed from  ``sigma*`` .
981
982     :param sigmaX: Gaussian kernel standard deviation in X direction.
983
984     :param sigmaY: Gaussian kernel standard deviation in Y direction; if  ``sigmaY``  is zero, it is set to be equal to  ``sigmaX``, if both sigmas are zeros, they are computed from  ``ksize.width``  and  ``ksize.height`` , respectively (see  :ocv:func:`getGaussianKernel` for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ``ksize``, ``sigmaX``, and ``sigmaY``.
985
986     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
987
988 The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported.
989
990 .. seealso::
991
992    :ocv:func:`sepFilter2D`,
993    :ocv:func:`filter2D`,
994    :ocv:func:`blur`,
995    :ocv:func:`boxFilter`,
996    :ocv:func:`bilateralFilter`,
997    :ocv:func:`medianBlur`
998
999
1000 getDerivKernels
1001 ---------------
1002 Returns filter coefficients for computing spatial image derivatives.
1003
1004 .. ocv:function:: void getDerivKernels( OutputArray kx, OutputArray ky, int dx, int dy, int ksize,                      bool normalize=false, int ktype=CV_32F )
1005
1006 .. ocv:pyfunction:: cv2.getDerivKernels(dx, dy, ksize[, kx[, ky[, normalize[, ktype]]]]) -> kx, ky
1007
1008     :param kx: Output matrix of row filter coefficients. It has the type  ``ktype`` .
1009
1010     :param ky: Output matrix of column filter coefficients. It has the type  ``ktype`` .
1011
1012     :param dx: Derivative order in respect of x.
1013
1014     :param dy: Derivative order in respect of y.
1015
1016     :param ksize: Aperture size. It can be  ``CV_SCHARR`` , 1, 3, 5, or 7.
1017
1018     :param normalize: Flag indicating whether to normalize (scale down) the filter coefficients or not. Theoretically, the coefficients should have the denominator  :math:`=2^{ksize*2-dx-dy-2}` . If you are going to filter floating-point images, you are likely to use the normalized kernels. But if you compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve all the fractional bits, you may want to set  ``normalize=false`` .
1019
1020     :param ktype: Type of filter coefficients. It can be  ``CV_32f``  or  ``CV_64F`` .
1021
1022 The function computes and returns the filter coefficients for spatial image derivatives. When ``ksize=CV_SCHARR`` , the Scharr
1023 :math:`3 \times 3` kernels are generated (see
1024 :ocv:func:`Scharr` ). Otherwise, Sobel kernels are generated (see
1025 :ocv:func:`Sobel` ). The filters are normally passed to
1026 :ocv:func:`sepFilter2D` or to
1027 :ocv:func:`createSeparableLinearFilter` .
1028
1029
1030
1031 getGaussianKernel
1032 -----------------
1033 Returns Gaussian filter coefficients.
1034
1035 .. ocv:function:: Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F )
1036
1037 .. ocv:pyfunction:: cv2.getGaussianKernel(ksize, sigma[, ktype]) -> retval
1038
1039     :param ksize: Aperture size. It should be odd ( :math:`\texttt{ksize} \mod 2 = 1` ) and positive.
1040
1041     :param sigma: Gaussian standard deviation. If it is non-positive, it is computed from  ``ksize``  as  \ ``sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`` .
1042     :param ktype: Type of filter coefficients. It can be  ``CV_32f``  or  ``CV_64F`` .
1043
1044 The function computes and returns the
1045 :math:`\texttt{ksize} \times 1` matrix of Gaussian filter coefficients:
1046
1047 .. math::
1048
1049     G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma} )^2},
1050
1051 where
1052 :math:`i=0..\texttt{ksize}-1` and
1053 :math:`\alpha` is the scale factor chosen so that
1054 :math:`\sum_i G_i=1`.
1055
1056 Two of such generated kernels can be passed to
1057 :ocv:func:`sepFilter2D` or to
1058 :ocv:func:`createSeparableLinearFilter`. Those functions automatically recognize smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly. You may also use the higher-level
1059 :ocv:func:`GaussianBlur`.
1060
1061 .. seealso::
1062
1063    :ocv:func:`sepFilter2D`,
1064    :ocv:func:`createSeparableLinearFilter`,
1065    :ocv:func:`getDerivKernels`,
1066    :ocv:func:`getStructuringElement`,
1067    :ocv:func:`GaussianBlur`
1068
1069
1070
1071 getKernelType
1072 -------------
1073 Returns the kernel type.
1074
1075 .. ocv:function:: int getKernelType(InputArray kernel, Point anchor)
1076
1077     :param kernel: 1D array of the kernel coefficients to analyze.
1078
1079     :param anchor: Anchor position within the kernel.
1080
1081 The function analyzes the kernel coefficients and returns the corresponding kernel type:
1082
1083     * **KERNEL_GENERAL** The kernel is generic. It is used when there is no any type of symmetry or other properties.
1084
1085     * **KERNEL_SYMMETRICAL** The kernel is symmetrical:  :math:`\texttt{kernel}_i == \texttt{kernel}_{ksize-i-1}` , and the anchor is at the center.
1086
1087     * **KERNEL_ASYMMETRICAL** The kernel is asymmetrical:  :math:`\texttt{kernel}_i == -\texttt{kernel}_{ksize-i-1}` , and the anchor is at the center.
1088
1089     * **KERNEL_SMOOTH** All the kernel elements are non-negative and summed to 1. For example, the Gaussian kernel is both smooth kernel and symmetrical, so the function returns  ``KERNEL_SMOOTH | KERNEL_SYMMETRICAL`` .
1090     * **KERNEL_INTEGER** All the kernel coefficients are integer numbers. This flag can be combined with  ``KERNEL_SYMMETRICAL``  or  ``KERNEL_ASYMMETRICAL`` .
1091
1092
1093
1094 getStructuringElement
1095 ---------------------
1096 Returns a structuring element of the specified size and shape for morphological operations.
1097
1098 .. ocv:function:: Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1))
1099
1100 .. ocv:pyfunction:: cv2.getStructuringElement(shape, ksize[, anchor]) -> retval
1101
1102 .. ocv:cfunction:: IplConvKernel* cvCreateStructuringElementEx( int cols, int rows, int anchor_x, int anchor_y, int shape, int* values=NULL )
1103
1104 .. ocv:pyoldfunction:: cv.CreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values=None)-> kernel
1105
1106     :param shape: Element shape that could be one of the following:
1107
1108       * **MORPH_RECT**         - a rectangular structuring element:
1109
1110         .. math::
1111
1112             E_{ij}=1
1113
1114       * **MORPH_ELLIPSE**         - an elliptic structuring element, that is, a filled ellipse inscribed into the rectangle ``Rect(0, 0, esize.width, 0.esize.height)``
1115
1116       * **MORPH_CROSS**         - a cross-shaped structuring element:
1117
1118         .. math::
1119
1120             E_{ij} =  \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}
1121
1122       * **CV_SHAPE_CUSTOM**     - custom structuring element (OpenCV 1.x API)
1123
1124     :param ksize: Size of the structuring element.
1125
1126     :param cols: Width of the structuring element
1127
1128     :param rows: Height of the structuring element
1129
1130     :param anchor: Anchor position within the element. The default value  :math:`(-1, -1)`  means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.
1131
1132     :param anchor_x: x-coordinate of the anchor
1133
1134     :param anchor_y: y-coordinate of the anchor
1135
1136     :param values: integer array of ``cols``*``rows`` elements that specifies the custom shape of the structuring element, when ``shape=CV_SHAPE_CUSTOM``.
1137
1138 The function constructs and returns the structuring element that can be further passed to
1139 :ocv:func:`createMorphologyFilter`,
1140 :ocv:func:`erode`,
1141 :ocv:func:`dilate` or
1142 :ocv:func:`morphologyEx` . But you can also construct an arbitrary binary mask yourself and use it as the structuring element.
1143
1144 .. note:: When using OpenCV 1.x C API, the created structuring element ``IplConvKernel* element`` must be released in the end using ``cvReleaseStructuringElement(&element)``.
1145
1146
1147 medianBlur
1148 ----------
1149 Blurs an image using the median filter.
1150
1151 .. ocv:function:: void medianBlur( InputArray src, OutputArray dst, int ksize )
1152
1153 .. ocv:pyfunction:: cv2.medianBlur(src, ksize[, dst]) -> dst
1154
1155     :param src: input 1-, 3-, or 4-channel image; when  ``ksize``  is 3 or 5, the image depth should be ``CV_8U``, ``CV_16U``, or ``CV_32F``, for larger aperture sizes, it can only be ``CV_8U``.
1156
1157     :param dst: destination array of the same size and type as ``src``.
1158
1159     :param ksize: aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
1160
1161 The function smoothes an image using the median filter with the
1162 :math:`\texttt{ksize} \times \texttt{ksize}` aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.
1163
1164 .. seealso::
1165
1166     :ocv:func:`bilateralFilter`,
1167     :ocv:func:`blur`,
1168     :ocv:func:`boxFilter`,
1169     :ocv:func:`GaussianBlur`
1170
1171
1172
1173 morphologyEx
1174 ------------
1175 Performs advanced morphological transformations.
1176
1177 .. ocv:function:: void morphologyEx( InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )
1178
1179 .. ocv:pyfunction:: cv2.morphologyEx(src, op, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
1180
1181 .. ocv:cfunction:: void cvMorphologyEx( const CvArr* src, CvArr* dst, CvArr* temp, IplConvKernel* element, int operation, int iterations=1 )
1182 .. ocv:pyoldfunction:: cv.MorphologyEx(src, dst, temp, element, operation, iterations=1)-> None
1183
1184     :param src: Source image. The number of channels can be arbitrary. The depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``,  ``CV_32F` or ``CV_64F``.
1185
1186     :param dst: Destination image of the same size and type as  ``src`` .
1187
1188     :param element: Structuring element.
1189
1190     :param op: Type of a morphological operation that can be one of the following:
1191
1192             * **MORPH_OPEN** - an opening operation
1193
1194             * **MORPH_CLOSE** - a closing operation
1195
1196             * **MORPH_GRADIENT** - a morphological gradient
1197
1198             * **MORPH_TOPHAT** - "top hat"
1199
1200             * **MORPH_BLACKHAT** - "black hat"
1201
1202     :param iterations: Number of times erosion and dilation are applied.
1203
1204     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` for details.
1205
1206     :param borderValue: Border value in case of a constant border. The default value has a special meaning. See  :ocv:func:`createMorphologyFilter` for details.
1207
1208 The function can perform advanced morphological transformations using an erosion and dilation as basic operations.
1209
1210 Opening operation:
1211
1212 .. math::
1213
1214     \texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))
1215
1216 Closing operation:
1217
1218 .. math::
1219
1220     \texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))
1221
1222 Morphological gradient:
1223
1224 .. math::
1225
1226     \texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )
1227
1228 "Top hat":
1229
1230 .. math::
1231
1232     \texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )
1233
1234 "Black hat":
1235
1236 .. math::
1237
1238     \texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}
1239
1240 Any of the operations can be done in-place. In case of multi-channel images, each channel is processed independently.
1241
1242 .. seealso::
1243
1244     :ocv:func:`dilate`,
1245     :ocv:func:`erode`,
1246     :ocv:func:`createMorphologyFilter`
1247
1248
1249 Laplacian
1250 ---------
1251 Calculates the Laplacian of an image.
1252
1253 .. ocv:function:: void Laplacian( InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
1254
1255 .. ocv:pyfunction:: cv2.Laplacian(src, ddepth[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst
1256
1257 .. ocv:cfunction:: void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 )
1258
1259 .. ocv:pyoldfunction:: cv.Laplace(src, dst, apertureSize=3) -> None
1260
1261     :param src: Source image.
1262
1263     :param dst: Destination image of the same size and the same number of channels as  ``src`` .
1264
1265     :param ddepth: Desired depth of the destination image.
1266
1267     :param ksize: Aperture size used to compute the second-derivative filters. See  :ocv:func:`getDerivKernels` for details. The size must be positive and odd.
1268
1269     :param scale: Optional scale factor for the computed Laplacian values. By default, no scaling is applied. See  :ocv:func:`getDerivKernels` for details.
1270
1271     :param delta: Optional delta value that is added to the results prior to storing them in  ``dst`` .
1272
1273     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` for details.
1274
1275 The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator:
1276
1277 .. math::
1278
1279     \texttt{dst} =  \Delta \texttt{src} =  \frac{\partial^2 \texttt{src}}{\partial x^2} +  \frac{\partial^2 \texttt{src}}{\partial y^2}
1280
1281 This is done when ``ksize > 1`` . When ``ksize == 1`` , the Laplacian is computed by filtering the image with the following
1282 :math:`3 \times 3` aperture:
1283
1284 .. math::
1285
1286     \vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}
1287
1288 .. seealso::
1289
1290     :ocv:func:`Sobel`,
1291     :ocv:func:`Scharr`
1292
1293
1294
1295 pyrDown
1296 -------
1297 Blurs an image and downsamples it.
1298
1299 .. ocv:function:: void pyrDown( InputArray src, OutputArray dst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT )
1300
1301 .. ocv:pyfunction:: cv2.pyrDown(src[, dst[, dstsize[, borderType]]]) -> dst
1302
1303 .. ocv:cfunction:: void cvPyrDown( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 )
1304
1305 .. ocv:pyoldfunction:: cv.PyrDown(src, dst, filter=CV_GAUSSIAN_5X5) -> None
1306
1307     :param src: input image.
1308
1309     :param dst: output image; it has the specified size and the same type as ``src``.
1310
1311     :param dstsize: size of the output image; by default, it is computed as ``Size((src.cols+1)/2, (src.rows+1)/2)``, but in any case, the following conditions should be satisfied:
1312
1313         .. math::
1314
1315             \begin{array}{l}
1316             | \texttt{dstsize.width} *2-src.cols| \leq  2  \\ | \texttt{dstsize.height} *2-src.rows| \leq  2 \end{array}
1317
1318 The function performs the downsampling step of the Gaussian pyramid construction. First, it convolves the source image with the kernel:
1319
1320 .. math::
1321
1322     \frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1  \\ 4 & 16 & 24 & 16 & 4  \\ 6 & 24 & 36 & 24 & 6  \\ 4 & 16 & 24 & 16 & 4  \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}
1323
1324 Then, it downsamples the image by rejecting even rows and columns.
1325
1326
1327
1328 pyrUp
1329 -----
1330 Upsamples an image and then blurs it.
1331
1332 .. ocv:function:: void pyrUp( InputArray src, OutputArray dst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT )
1333
1334 .. ocv:pyfunction:: cv2.pyrUp(src[, dst[, dstsize[, borderType]]]) -> dst
1335
1336 .. ocv:cfunction:: cvPyrUp( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 )
1337
1338 .. ocv:pyoldfunction:: cv.PyrUp(src, dst, filter=CV_GAUSSIAN_5X5) -> None
1339
1340     :param src: input image.
1341
1342     :param dst: output image. It has the specified size and the same type as  ``src`` .
1343
1344     :param dstsize: size of the output image; by default, it is computed as ``Size(src.cols*2, (src.rows*2)``, but in any case, the following conditions should be satisfied:
1345
1346         .. math::
1347
1348             \begin{array}{l}
1349             | \texttt{dstsize.width} -src.cols*2| \leq  ( \texttt{dstsize.width}   \mod  2)  \\ | \texttt{dstsize.height} -src.rows*2| \leq  ( \texttt{dstsize.height}   \mod  2) \end{array}
1350
1351 The function performs the upsampling step of the Gaussian pyramid construction, though it can actually be used to construct the Laplacian pyramid. First, it upsamples the source image by injecting even zero rows and columns and then convolves the result with the same kernel as in
1352 :ocv:func:`pyrDown`  multiplied by 4.
1353
1354
1355 pyrMeanShiftFiltering
1356 ---------------------
1357 Performs initial step of meanshift segmentation of an image.
1358
1359 .. ocv:function:: void pyrMeanShiftFiltering( InputArray src, OutputArray dst, double sp, double sr, int maxLevel=1, TermCriteria termcrit=TermCriteria( TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) )
1360
1361 .. ocv:pyfunction:: cv2.pyrMeanShiftFiltering(src, sp, sr[, dst[, maxLevel[, termcrit]]]) -> dst
1362
1363 .. ocv:cfunction:: void cvPyrMeanShiftFiltering( const CvArr* src, CvArr* dst, double sp,  double sr,  int max_level=1, CvTermCriteria termcrit= cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,5,1))
1364
1365 .. ocv:pyoldfunction:: cv.PyrMeanShiftFiltering(src, dst, sp, sr, max_level=1, termcrit=(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 5, 1)) -> None
1366
1367     :param src: The source 8-bit, 3-channel image.
1368
1369     :param dst: The destination image of the same format and the same size as the source.
1370
1371     :param sp: The spatial window radius.
1372
1373     :param sr: The color window radius.
1374
1375     :param maxLevel: Maximum level of the pyramid for the segmentation.
1376
1377     :param termcrit: Termination criteria: when to stop meanshift iterations.
1378
1379
1380 The function implements the filtering stage of meanshift segmentation, that is, the output of the function is the filtered "posterized" image with color gradients and fine-grain texture flattened. At every pixel
1381 ``(X,Y)`` of the input image (or down-sized input image, see below) the function executes meanshift
1382 iterations, that is, the pixel ``(X,Y)`` neighborhood in the joint space-color hyperspace is considered:
1383
1384     .. math::
1385
1386         (x,y): X- \texttt{sp} \le x  \le X+ \texttt{sp} , Y- \texttt{sp} \le y  \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)||   \le \texttt{sr}
1387
1388
1389 where  ``(R,G,B)`` and  ``(r,g,b)`` are the vectors of color components at ``(X,Y)`` and  ``(x,y)``, respectively (though, the algorithm does not depend on the color space used, so any 3-component color space can be used instead). Over the neighborhood the average spatial value  ``(X',Y')`` and average color vector  ``(R',G',B')`` are found and they act as the neighborhood center on the next iteration:
1390
1391     .. math::
1392
1393         (X,Y)~(X',Y'), (R,G,B)~(R',G',B').
1394
1395 After the iterations over, the color components of the initial pixel (that is, the pixel from where the iterations started) are set to the final value (average color at the last iteration):
1396
1397     .. math::
1398
1399         I(X,Y) <- (R*,G*,B*)
1400
1401 When ``maxLevel > 0``, the gaussian pyramid of ``maxLevel+1`` levels is built, and the above procedure is run on the smallest layer first. After that, the results are propagated to the larger layer and the iterations are run again only on those pixels where the layer colors differ by more than ``sr`` from the lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the results will be actually different from the ones obtained by running the meanshift procedure on the whole original image (i.e. when ``maxLevel==0``).
1402
1403
1404 sepFilter2D
1405 -----------
1406 Applies a separable linear filter to an image.
1407
1408 .. ocv:function:: void sepFilter2D( InputArray src, OutputArray dst, int ddepth, InputArray kernelX, InputArray kernelY, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT )
1409
1410 .. ocv:pyfunction:: cv2.sepFilter2D(src, ddepth, kernelX, kernelY[, dst[, anchor[, delta[, borderType]]]]) -> dst
1411
1412     :param src: Source image.
1413
1414     :param dst: Destination image of the same size and the same number of channels as  ``src`` .
1415
1416     :param ddepth: Destination image depth. The following combination of ``src.depth()`` and ``ddepth`` are supported:
1417          * ``src.depth()`` = ``CV_8U``, ``ddepth`` = -1/``CV_16S``/``CV_32F``/``CV_64F``
1418          * ``src.depth()`` = ``CV_16U``/``CV_16S``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
1419          * ``src.depth()`` = ``CV_32F``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
1420          * ``src.depth()`` = ``CV_64F``, ``ddepth`` = -1/``CV_64F``
1421
1422         when ``ddepth=-1``, the destination image will have the same depth as the source.
1423
1424     :param kernelX: Coefficients for filtering each row.
1425
1426     :param kernelY: Coefficients for filtering each column.
1427
1428     :param anchor: Anchor position within the kernel. The default value  :math:`(-1, 1)`  means that the anchor is at the kernel center.
1429
1430     :param delta: Value added to the filtered results before storing them.
1431
1432     :param borderType: Pixel extrapolation method. See  :ocv:func:`borderInterpolate` for details.
1433
1434 The function applies a separable linear filter to the image. That is, first, every row of ``src`` is filtered with the 1D kernel ``kernelX`` . Then, every column of the result is filtered with the 1D kernel ``kernelY`` . The final result shifted by ``delta`` is stored in ``dst`` .
1435
1436 .. seealso::
1437
1438    :ocv:func:`createSeparableLinearFilter`,
1439    :ocv:func:`filter2D`,
1440    :ocv:func:`Sobel`,
1441    :ocv:func:`GaussianBlur`,
1442    :ocv:func:`boxFilter`,
1443    :ocv:func:`blur`
1444
1445
1446 Smooth
1447 ------
1448 Smooths the image in one of several ways.
1449
1450 .. ocv:cfunction:: void cvSmooth( const CvArr* src, CvArr* dst, int smoothtype=CV_GAUSSIAN, int size1=3, int size2=0, double sigma1=0, double sigma2=0 )
1451
1452 .. ocv:pyoldfunction:: cv.Smooth(src, dst, smoothtype=CV_GAUSSIAN, param1=3, param2=0, param3=0, param4=0)-> None
1453
1454     :param src: The source image
1455
1456     :param dst: The destination image
1457
1458     :param smoothtype: Type of the smoothing:
1459
1460             * **CV_BLUR_NO_SCALE** linear convolution with  :math:`\texttt{size1}\times\texttt{size2}`  box kernel (all 1's). If you want to smooth different pixels with different-size box kernels, you can use the integral image that is computed using  :ocv:func:`integral`
1461
1462
1463             * **CV_BLUR** linear convolution with  :math:`\texttt{size1}\times\texttt{size2}`  box kernel (all 1's) with subsequent scaling by  :math:`1/(\texttt{size1}\cdot\texttt{size2})`
1464
1465
1466             * **CV_GAUSSIAN** linear convolution with a  :math:`\texttt{size1}\times\texttt{size2}`  Gaussian kernel
1467
1468
1469             * **CV_MEDIAN** median filter with a  :math:`\texttt{size1}\times\texttt{size1}`  square aperture
1470
1471
1472             * **CV_BILATERAL** bilateral filter with a  :math:`\texttt{size1}\times\texttt{size1}`  square aperture, color sigma= ``sigma1``  and spatial sigma= ``sigma2`` . If  ``size1=0`` , the aperture square side is set to  ``cvRound(sigma2*1.5)*2+1`` . Information about bilateral filtering can be found at  http://www.dai.ed.ac.uk/CVonline/LOCAL\_COPIES/MANDUCHI1/Bilateral\_Filtering.html
1473
1474
1475     :param size1: The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
1476
1477     :param size2: The second parameter of the smoothing operation, the aperture height. Ignored by  ``CV_MEDIAN``  and  ``CV_BILATERAL``  methods. In the case of simple scaled/non-scaled and Gaussian blur if  ``size2``  is zero, it is set to  ``size1`` . Otherwise it must be a positive odd number.
1478
1479     :param sigma1: In the case of a Gaussian parameter this parameter may specify Gaussian  :math:`\sigma`  (standard deviation). If it is zero, it is calculated from the kernel size:
1480
1481         .. math::
1482
1483             \sigma  = 0.3 (n/2 - 1) + 0.8  \quad   \text{where}   \quad  n= \begin{array}{l l} \mbox{\texttt{size1} for horizontal kernel} \\ \mbox{\texttt{size2} for vertical kernel} \end{array}
1484
1485         Using standard sigma for small kernels ( :math:`3\times 3`  to  :math:`7\times 7` ) gives better speed. If  ``sigma1``  is not zero, while  ``size1``  and  ``size2``  are zeros, the kernel size is calculated from the sigma (to provide accurate enough operation).
1486
1487 The function smooths an image using one of several methods. Every of the methods has some features and restrictions listed below:
1488
1489  * Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format (similar to :ocv:func:`Sobel` and :ocv:func:`Laplacian`) and 32-bit floating point to 32-bit floating-point format.
1490
1491  * Simple blur and Gaussian blur support 1- or 3-channel, 8-bit and 32-bit floating point images. These two methods can process images in-place.
1492
1493  * Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.
1494
1495 .. note:: The function is now obsolete. Use :ocv:func:`GaussianBlur`, :ocv:func:`blur`, :ocv:func:`medianBlur` or :ocv:func:`bilateralFilter`.
1496
1497
1498 Sobel
1499 -----
1500 Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
1501
1502 .. ocv:function:: void Sobel( InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
1503
1504 .. ocv:pyfunction:: cv2.Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst
1505
1506 .. ocv:cfunction:: void cvSobel( const CvArr* src, CvArr* dst, int xorder, int yorder, int aperture_size=3 )
1507
1508 .. ocv:pyoldfunction:: cv.Sobel(src, dst, xorder, yorder, apertureSize=3)-> None
1509
1510     :param src: input image.
1511
1512     :param dst: output image of the same size and the same number of channels as  ``src`` .
1513
1514     :param ddepth: output image depth; the following combinations of ``src.depth()`` and ``ddepth`` are supported:
1515          * ``src.depth()`` = ``CV_8U``, ``ddepth`` = -1/``CV_16S``/``CV_32F``/``CV_64F``
1516          * ``src.depth()`` = ``CV_16U``/``CV_16S``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
1517          * ``src.depth()`` = ``CV_32F``, ``ddepth`` = -1/``CV_32F``/``CV_64F``
1518          * ``src.depth()`` = ``CV_64F``, ``ddepth`` = -1/``CV_64F``
1519
1520         when ``ddepth=-1``, the destination image will have the same depth as the source; in the case of 8-bit input images it will result in truncated derivatives.
1521
1522     :param xorder: order of the derivative x.
1523
1524     :param yorder: order of the derivative y.
1525
1526     :param ksize: size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
1527
1528     :param scale: optional scale factor for the computed derivative values; by default, no scaling is applied (see  :ocv:func:`getDerivKernels` for details).
1529
1530     :param delta: optional delta value that is added to the results prior to storing them in ``dst``.
1531
1532     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
1533
1534 In all cases except one, the
1535 :math:`\texttt{ksize} \times
1536 \texttt{ksize}` separable kernel is used to calculate the
1537 derivative. When
1538 :math:`\texttt{ksize = 1}` , the
1539 :math:`3 \times 1` or
1540 :math:`1 \times 3` kernel is used (that is, no Gaussian smoothing is done). ``ksize = 1`` can only be used for the first or the second x- or y- derivatives.
1541
1542 There is also the special value ``ksize = CV_SCHARR`` (-1) that corresponds to the
1543 :math:`3\times3` Scharr
1544 filter that may give more accurate results than the
1545 :math:`3\times3` Sobel. The Scharr aperture is
1546
1547 .. math::
1548
1549     \vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}
1550
1551 for the x-derivative, or transposed for the y-derivative.
1552
1553 The function calculates an image derivative by convolving the image with the appropriate kernel:
1554
1555 .. math::
1556
1557     \texttt{dst} =  \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}
1558
1559 The Sobel operators combine Gaussian smoothing and differentiation,
1560 so the result is more or less resistant to the noise. Most often,
1561 the function is called with ( ``xorder`` = 1, ``yorder`` = 0, ``ksize`` = 3) or ( ``xorder`` = 0, ``yorder`` = 1, ``ksize`` = 3) to calculate the first x- or y- image
1562 derivative. The first case corresponds to a kernel of:
1563
1564 .. math::
1565
1566     \vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}
1567
1568 The second case corresponds to a kernel of:
1569
1570 .. math::
1571
1572     \vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}
1573
1574 .. seealso::
1575
1576     :ocv:func:`Scharr`,
1577     :ocv:func:`Laplacian`,
1578     :ocv:func:`sepFilter2D`,
1579     :ocv:func:`filter2D`,
1580     :ocv:func:`GaussianBlur`,
1581     :ocv:func:`cartToPolar`
1582
1583
1584
1585 Scharr
1586 ------
1587 Calculates the first x- or y- image derivative using Scharr operator.
1588
1589 .. ocv:function:: void Scharr( InputArray src, OutputArray dst, int ddepth, int dx, int dy, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
1590
1591 .. ocv:pyfunction:: cv2.Scharr(src, ddepth, dx, dy[, dst[, scale[, delta[, borderType]]]]) -> dst
1592
1593     :param src: input image.
1594
1595     :param dst: output image of the same size and the same number of channels as ``src``.
1596
1597     :param ddepth: output image depth (see :ocv:func:`Sobel` for the list of supported combination of ``src.depth()`` and ``ddepth``).
1598
1599     :param dx: order of the derivative x.
1600
1601     :param dy: order of the derivative y.
1602
1603     :param scale: optional scale factor for the computed derivative values; by default, no scaling is applied (see  :ocv:func:`getDerivKernels` for details).
1604
1605     :param delta: optional delta value that is added to the results prior to storing them in ``dst``.
1606
1607     :param borderType: pixel extrapolation method (see  :ocv:func:`borderInterpolate` for details).
1608
1609 The function computes the first x- or y- spatial image derivative using the Scharr operator. The call
1610
1611 .. math::
1612
1613     \texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}
1614
1615 is equivalent to
1616
1617 .. math::
1618
1619     \texttt{Sobel(src, dst, ddepth, dx, dy, CV\_SCHARR, scale, delta, borderType)} .
1620
1621 .. seealso::
1622
1623     :ocv:func:`cartToPolar`
1624