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.
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. ::
16 Various border types, image boundaries are denoted with '|'
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'
27 .. ocv:class:: BaseColumnFilter
29 Base class for filters with single-column kernels. ::
31 class BaseColumnFilter
34 virtual ~BaseColumnFilter();
36 // To be overriden by the user.
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)
48 int ksize; // the aperture size
49 int anchor; // position of the anchor point,
50 // normally not used during the processing
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:
58 \texttt{dst} (x,y) = F( \texttt{src} [y](x), \; \texttt{src} [y+1](x), \; ..., \; \texttt{src} [y+ \texttt{ksize} -1](x)
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.
66 :ocv:class:`BaseRowFilter`,
67 :ocv:class:`BaseFilter`,
68 :ocv:class:`FilterEngine`,
69 :ocv:func:`getColumnSumFilter`,
70 :ocv:func:`getLinearColumnFilter`,
71 :ocv:func:`getMorphologyColumnFilter`
76 .. ocv:class:: BaseFilter
78 Base class for 2D image filters. ::
83 virtual ~BaseFilter();
85 // To be overriden by the user.
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)
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:
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))
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.
116 :ocv:class:`BaseColumnFilter`,
117 :ocv:class:`BaseRowFilter`,
118 :ocv:class:`FilterEngine`,
119 :ocv:func:`getLinearFilter`,
120 :ocv:func:`getMorphologyFilter`
126 .. ocv:class:: BaseRowFilter
128 Base class for filters with single-row kernels. ::
133 virtual ~BaseRowFilter();
135 // To be overriden by the user.
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;
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:
150 \texttt{dst} (x,y) = F( \texttt{src} [y](x), \; \texttt{src} [y](x+1), \; ..., \; \texttt{src} [y](x+ \texttt{ksize.width} -1))
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.
158 :ocv:class:`BaseColumnFilter`,
159 :ocv:class:`BaseFilter`,
160 :ocv:class:`FilterEngine`,
161 :ocv:func:`getLinearRowFilter`,
162 :ocv:func:`getMorphologyRowFilter`,
163 :ocv:func:`getRowSumFilter`
169 .. ocv:class:: FilterEngine
171 Generic image filtering class. ::
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;
228 // the starting and the ending rows in the source image
231 // pointers to the filters
232 Ptr<BaseFilter> filter2D;
233 Ptr<BaseRowFilter> rowFilter;
234 Ptr<BaseColumnFilter> columnFilter;
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`,
244 :ocv:func:`dilate`, and others. Thus, the class plays a key role in many of OpenCV filtering functions.
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` : ::
249 void laplace_f(const Mat& src, Mat& dst)
251 CV_Assert( src.type() == CV_32F );
252 dst.create(src.size(), src.type());
254 // get the derivative and smooth kernels for d2I/dx2.
255 // for d2I/dy2 consider using the same kernels, just swapped
257 getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
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() );
266 int y = Fxx->start(src), dsty = 0, dy = 0;
268 const uchar* sptr = src.data + y*src.step;
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() );
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 )
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 );
294 Mat dstripe = dst.rowRange(dsty, dsty + dy);
295 add(Ixx.rowRange(0, dy), Iyy.rowRange(0, dy), dstripe);
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: ::
303 void FilterEngine::apply(const Mat& src, Mat& dst,
304 const Rect& srcRoi, Point dstOfs, bool isolated)
306 // check matrix types
307 CV_Assert( src.type() == srcType && dst.type() == dstType );
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);
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 );
321 int y = start(src, _srcRoi, isolated);
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 );
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: ::
335 // compute dI/dx derivative at src(x,y)
338 // form a matrix header for a single value
340 Mat dst1(1,1,CV_32F,&val1);
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);
347 // form a matrix header for a single value
349 Mat dst2(1,1,CV_32F,&val2);
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);
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:
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)`` .
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`` .
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`
384 Applies the bilateral filter to an image.
386 .. ocv:function:: void bilateralFilter( InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT )
388 .. ocv:pyfunction:: cv2.bilateralFilter(src, d, sigmaColor, sigmaSpace[, dst[, borderType]]) -> dst
390 :param src: Source 8-bit or floating-point, 1-channel or 3-channel image.
392 :param dst: Destination image of the same size and type as ``src`` .
394 :param d: Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from ``sigmaSpace`` .
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.
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`` .
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.
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".
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.
408 This filter does not work inplace.
415 Blurs an image using the normalized box filter.
417 .. ocv:function:: void blur( InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT )
419 .. ocv:pyfunction:: cv2.blur(src, ksize[, dst[, anchor[, borderType]]]) -> dst
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``.
423 :param dst: output image of the same size and type as ``src``.
425 :param ksize: blurring kernel size.
427 :param anchor: anchor point; default value ``Point(-1,-1)`` means that the anchor is at the kernel center.
429 :param borderType: border mode used to extrapolate pixels outside of the image.
431 The function smoothes an image using the kernel:
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}
437 The call ``blur(src, dst, ksize, anchor, borderType)`` is equivalent to ``boxFilter(src, dst, src.type(), anchor, true, borderType)`` .
441 :ocv:func:`boxFilter`,
442 :ocv:func:`bilateralFilter`,
443 :ocv:func:`GaussianBlur`,
444 :ocv:func:`medianBlur`
449 Computes the source location of an extrapolated pixel.
451 .. ocv:function:: int borderInterpolate( int p, int len, int borderType )
453 .. ocv:pyfunction:: cv2.borderInterpolate(p, len, borderType) -> retval
455 :param p: 0-based coordinate of the extrapolated pixel along one of the axes, likely <0 or >= ``len`` .
457 :param len: Length of the array along the corresponding axis.
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`` .
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: ::
463 float val = img.at<float>(borderInterpolate(100, img.rows, BORDER_REFLECT_101),
464 borderInterpolate(-5, img.cols, BORDER_WRAP));
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.
473 :ocv:class:`FilterEngine`,
474 :ocv:func:`copyMakeBorder`
480 Blurs an image using the box filter.
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 )
484 .. ocv:pyfunction:: cv2.boxFilter(src, ddepth, ksize[, dst[, anchor[, normalize[, borderType]]]]) -> dst
486 :param src: input image.
488 :param dst: output image of the same size and type as ``src``.
490 :param ddepth: the output image depth (-1 to use ``src.depth()``).
492 :param ksize: blurring kernel size.
494 :param anchor: anchor point; default value ``Point(-1,-1)`` means that the anchor is at the kernel center.
496 :param normalize: flag, specifying whether the kernel is normalized by its area or not.
498 :param borderType: border mode used to extrapolate pixels outside of the image.
500 The function smoothes an image using the kernel:
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}
510 \alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}
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` .
517 :ocv:func:`bilateralFilter`,
518 :ocv:func:`GaussianBlur`,
519 :ocv:func:`medianBlur`,
526 Constructs the Gaussian pyramid for an image.
528 .. ocv:function:: void buildPyramid( InputArray src, OutputArrayOfArrays dst, int maxlevel, int borderType=BORDER_DEFAULT )
530 :param src: Source image. Check :ocv:func:`pyrDown` for the list of supported types.
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.
534 :param maxlevel: 0-based index of the last (the smallest) pyramid layer. It must be non-negative.
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`` .
543 Forms a border around an image.
545 .. ocv:function:: void copyMakeBorder( InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() )
547 .. ocv:pyfunction:: cv2.copyMakeBorder(src, top, bottom, left, right, borderType[, dst[, value]]) -> dst
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
552 :param src: Source image.
554 :param dst: Destination image of the same type as ``src`` and the size ``Size(src.cols+left+right, src.rows+top+bottom)`` .
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.
564 :param borderType: Border type. See :ocv:func:`borderInterpolate` for details.
566 :param value: Border value if ``borderType==BORDER_CONSTANT`` .
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.
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: ::
573 // let border be the same in all directions
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 ...
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``.
594 :ocv:func:`borderInterpolate`
599 Returns a box filter engine.
601 .. ocv:function:: Ptr<FilterEngine> createBoxFilter( int srcType, int dstType, Size ksize, Point anchor=Point(-1,-1), bool normalize=true, int borderType=BORDER_DEFAULT)
603 .. ocv:function:: Ptr<BaseRowFilter> getRowSumFilter(int srcType, int sumType, int ksize, int anchor=-1)
605 .. ocv:function:: Ptr<BaseColumnFilter> getColumnSumFilter(int sumType, int dstType, int ksize, int anchor=-1, double scale=1)
607 :param srcType: Source image type.
609 :param sumType: Intermediate horizontal sum type that must have as many channels as ``srcType`` .
611 :param dstType: Destination image type that must have as many channels as ``srcType`` .
613 :param ksize: Aperture size.
615 :param anchor: Anchor position with the kernel. Negative values mean that the anchor is at the kernel center.
617 :param normalize: Flag specifying whether the sums are normalized or not. See :ocv:func:`boxFilter` for details.
619 :param scale: Another way to specify normalization in lower-level ``getColumnSumFilter`` .
621 :param borderType: Border type to use. See :ocv:func:`borderInterpolate` .
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.
628 The function itself is used by
630 :ocv:func:`boxFilter` .
634 :ocv:class:`FilterEngine`,
636 :ocv:func:`boxFilter`
641 ---------------------
642 Returns an engine for computing image derivatives.
644 .. ocv:function:: Ptr<FilterEngine> createDerivFilter( int srcType, int dstType, int dx, int dy, int ksize, int borderType=BORDER_DEFAULT )
646 :param srcType: Source image type.
648 :param dstType: Destination image type that must have as many channels as ``srcType`` .
650 :param dx: Derivative order in respect of x.
652 :param dy: Derivative order in respect of y.
654 :param ksize: Aperture size See :ocv:func:`getDerivKernels` .
656 :param borderType: Border type to use. See :ocv:func:`borderInterpolate` .
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
666 :ocv:func:`createSeparableLinearFilter`,
667 :ocv:func:`getDerivKernels`,
674 ------------------------
675 Returns an engine for smoothing images with the Gaussian filter.
677 .. ocv:function:: Ptr<FilterEngine> createGaussianFilter( int type, Size ksize, double sigma1, double sigma2=0, int borderType=BORDER_DEFAULT )
679 :param type: Source and destination image type.
681 :param ksize: Aperture size. See :ocv:func:`getGaussianKernel` .
683 :param sigma1: Gaussian sigma in the horizontal direction. See :ocv:func:`getGaussianKernel` .
685 :param sigma2: Gaussian sigma in the vertical direction. If 0, then :math:`\texttt{sigma2}\leftarrow\texttt{sigma1}` .
687 :param borderType: Border type to use. See :ocv:func:`borderInterpolate` .
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.
696 :ocv:func:`createSeparableLinearFilter`,
697 :ocv:func:`getGaussianKernel`,
698 :ocv:func:`GaussianBlur`
703 ----------------------
704 Creates a non-separable linear filter engine.
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() )
708 .. ocv:function:: Ptr<BaseFilter> getLinearFilter(int srcType, int dstType, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int bits=0)
710 :param srcType: Source image type.
712 :param dstType: Destination image type that must have as many channels as ``srcType`` .
714 :param kernel: 2D array of filter coefficients.
716 :param anchor: Anchor point within the kernel. Special value ``Point(-1,-1)`` means that the anchor is at the kernel center.
718 :param delta: Value added to the filtered results before storing them.
720 :param bits: Number of the fractional bits. The parameter is used when the kernel is an integer matrix representing fixed-point filter coefficients.
722 :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see :ocv:func:`borderInterpolate`.
724 :param columnBorderType: Pixel extrapolation method in the horizontal direction.
726 :param borderValue: Border value used in case of a constant border.
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.
733 :ocv:func:`createSeparableLinearFilter`,
734 :ocv:class:`FilterEngine`,
738 createMorphologyFilter
739 --------------------------
740 Creates an engine for non-separable morphological operations.
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() )
744 .. ocv:function:: Ptr<BaseFilter> getMorphologyFilter( int op, int type, InputArray kernel, Point anchor=Point(-1,-1) )
746 .. ocv:function:: Ptr<BaseRowFilter> getMorphologyRowFilter( int op, int type, int ksize, int anchor=-1 )
748 .. ocv:function:: Ptr<BaseColumnFilter> getMorphologyColumnFilter( int op, int type, int ksize, int anchor=-1 )
750 .. ocv:function:: Scalar morphologyDefaultBorderValue()
752 :param op: Morphology operation ID, ``MORPH_ERODE`` or ``MORPH_DILATE`` .
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``.
756 :param kernel: 2D 8-bit structuring element for a morphological operation. Non-zero elements indicate the pixels that belong to the element.
758 :param ksize: Horizontal or vertical structuring element size for separable morphological operations.
760 :param anchor: Anchor position within the structuring element. Negative values mean that the anchor is at the kernel center.
762 :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see :ocv:func:`borderInterpolate`.
764 :param columnBorderType: Pixel extrapolation method in the horizontal direction.
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.
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
771 :ocv:func:`dilate` , or
772 :ocv:func:`morphologyEx` .
774 :ocv:func:`createMorphologyFilter` analyzes the structuring element shape and builds a separable morphological filter engine when the structuring element is square.
780 :ocv:func:`morphologyEx`,
781 :ocv:class:`FilterEngine`
784 createSeparableLinearFilter
785 -------------------------------
786 Creates an engine for a separable linear filter.
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() )
790 .. ocv:function:: Ptr<BaseColumnFilter> getLinearColumnFilter( int bufType, int dstType, InputArray kernel, int anchor, int symmetryType, double delta=0, int bits=0 )
792 .. ocv:function:: Ptr<BaseRowFilter> getLinearRowFilter( int srcType, int bufType, InputArray kernel, int anchor, int symmetryType )
794 :param srcType: Source array type.
796 :param dstType: Destination image type that must have as many channels as ``srcType`` .
798 :param bufType: Intermediate buffer type that must have as many channels as ``srcType`` .
800 :param rowKernel: Coefficients for filtering each row.
802 :param columnKernel: Coefficients for filtering each column.
804 :param anchor: Anchor position within the kernel. Negative values mean that anchor is positioned at the aperture center.
806 :param delta: Value added to the filtered results before storing them.
808 :param bits: Number of the fractional bits. The parameter is used when the kernel is an integer matrix representing fixed-point filter coefficients.
810 :param rowBorderType: Pixel extrapolation method in the vertical direction. For details, see :ocv:func:`borderInterpolate`.
812 :param columnBorderType: Pixel extrapolation method in the horizontal direction.
814 :param borderValue: Border value used in case of a constant border.
816 :param symmetryType: Type of each row and column kernel. See :ocv:func:`getKernelType` .
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.
826 :ocv:func:`sepFilter2D`,
827 :ocv:func:`createLinearFilter`,
828 :ocv:class:`FilterEngine`,
829 :ocv:func:`getKernelType`
834 Dilates an image by using a specific structuring element.
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() )
838 .. ocv:pyfunction:: cv2.dilate(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
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
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``.
845 :param dst: output image of the same size and type as ``src``.
847 :param element: structuring element used for dilation; if ``element=Mat()`` , a ``3 x 3`` rectangular structuring element is used.
849 :param anchor: position of the anchor within the element; default value ``(-1, -1)`` means that the anchor is at the element center.
851 :param iterations: number of times dilation is applied.
853 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
855 :param borderValue: border value in case of a constant border (see :ocv:func:`createMorphologyFilter` for details).
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:
861 \texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')
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.
868 :ocv:func:`morphologyEx`,
869 :ocv:func:`createMorphologyFilter`
874 Erodes an image by using a specific structuring element.
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() )
878 .. ocv:pyfunction:: cv2.erode(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
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
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``.
885 :param dst: output image of the same size and type as ``src``.
887 :param element: structuring element used for erosion; if ``element=Mat()`` , a ``3 x 3`` rectangular structuring element is used.
889 :param anchor: position of the anchor within the element; default value ``(-1, -1)`` means that the anchor is at the element center.
891 :param iterations: number of times erosion is applied.
893 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
895 :param borderValue: border value in case of a constant border (see :ocv:func:`createMorphologyFilter` for details).
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:
901 \texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')
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.
908 :ocv:func:`morphologyEx`,
909 :ocv:func:`createMorphologyFilter`
915 Convolves an image with the kernel.
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 )
919 .. ocv:pyfunction:: cv2.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) -> dst
921 .. ocv:cfunction:: void cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel, CvPoint anchor=cvPoint(-1,-1) )
923 .. ocv:pyoldfunction:: cv.Filter2D(src, dst, kernel, anchor=(-1, -1))-> None
925 :param src: input image.
927 :param dst: output image of the same size and the same number of channels as ``src``.
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``
936 when ``ddepth=-1``, the output image will have the same depth as the source.
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.
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.
942 :param delta: optional value added to the filtered pixels before storing them in ``dst``.
944 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
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.
948 The function does actually compute correlation, not the convolution:
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} )
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)`` .
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.
961 :ocv:func:`sepFilter2D`,
962 :ocv:func:`createLinearFilter`,
964 :ocv:func:`matchTemplate`
970 Blurs an image using a Gaussian filter.
972 .. ocv:function:: void GaussianBlur( InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
974 .. ocv:pyfunction:: cv2.GaussianBlur(src, ksize, sigmaX[, dst[, sigmaY[, borderType]]]) -> dst
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``.
978 :param dst: output image of the same size and type as ``src``.
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*`` .
982 :param sigmaX: Gaussian kernel standard deviation in X direction.
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``.
986 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
988 The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported.
992 :ocv:func:`sepFilter2D`,
993 :ocv:func:`filter2D`,
995 :ocv:func:`boxFilter`,
996 :ocv:func:`bilateralFilter`,
997 :ocv:func:`medianBlur`
1002 Returns filter coefficients for computing spatial image derivatives.
1004 .. ocv:function:: void getDerivKernels( OutputArray kx, OutputArray ky, int dx, int dy, int ksize, bool normalize=false, int ktype=CV_32F )
1006 .. ocv:pyfunction:: cv2.getDerivKernels(dx, dy, ksize[, kx[, ky[, normalize[, ktype]]]]) -> kx, ky
1008 :param kx: Output matrix of row filter coefficients. It has the type ``ktype`` .
1010 :param ky: Output matrix of column filter coefficients. It has the type ``ktype`` .
1012 :param dx: Derivative order in respect of x.
1014 :param dy: Derivative order in respect of y.
1016 :param ksize: Aperture size. It can be ``CV_SCHARR`` , 1, 3, 5, or 7.
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`` .
1020 :param ktype: Type of filter coefficients. It can be ``CV_32f`` or ``CV_64F`` .
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` .
1033 Returns Gaussian filter coefficients.
1035 .. ocv:function:: Mat getGaussianKernel( int ksize, double sigma, int ktype=CV_64F )
1037 .. ocv:pyfunction:: cv2.getGaussianKernel(ksize, sigma[, ktype]) -> retval
1039 :param ksize: Aperture size. It should be odd ( :math:`\texttt{ksize} \mod 2 = 1` ) and positive.
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`` .
1044 The function computes and returns the
1045 :math:`\texttt{ksize} \times 1` matrix of Gaussian filter coefficients:
1049 G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma} )^2},
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`.
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`.
1063 :ocv:func:`sepFilter2D`,
1064 :ocv:func:`createSeparableLinearFilter`,
1065 :ocv:func:`getDerivKernels`,
1066 :ocv:func:`getStructuringElement`,
1067 :ocv:func:`GaussianBlur`
1073 Returns the kernel type.
1075 .. ocv:function:: int getKernelType(InputArray kernel, Point anchor)
1077 :param kernel: 1D array of the kernel coefficients to analyze.
1079 :param anchor: Anchor position within the kernel.
1081 The function analyzes the kernel coefficients and returns the corresponding kernel type:
1083 * **KERNEL_GENERAL** The kernel is generic. It is used when there is no any type of symmetry or other properties.
1085 * **KERNEL_SYMMETRICAL** The kernel is symmetrical: :math:`\texttt{kernel}_i == \texttt{kernel}_{ksize-i-1}` , and the anchor is at the center.
1087 * **KERNEL_ASYMMETRICAL** The kernel is asymmetrical: :math:`\texttt{kernel}_i == -\texttt{kernel}_{ksize-i-1}` , and the anchor is at the center.
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`` .
1094 getStructuringElement
1095 ---------------------
1096 Returns a structuring element of the specified size and shape for morphological operations.
1098 .. ocv:function:: Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1))
1100 .. ocv:pyfunction:: cv2.getStructuringElement(shape, ksize[, anchor]) -> retval
1102 .. ocv:cfunction:: IplConvKernel* cvCreateStructuringElementEx( int cols, int rows, int anchor_x, int anchor_y, int shape, int* values=NULL )
1104 .. ocv:pyoldfunction:: cv.CreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values=None)-> kernel
1106 :param shape: Element shape that could be one of the following:
1108 * **MORPH_RECT** - a rectangular structuring element:
1114 * **MORPH_ELLIPSE** - an elliptic structuring element, that is, a filled ellipse inscribed into the rectangle ``Rect(0, 0, esize.width, 0.esize.height)``
1116 * **MORPH_CROSS** - a cross-shaped structuring element:
1120 E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}
1122 * **CV_SHAPE_CUSTOM** - custom structuring element (OpenCV 1.x API)
1124 :param ksize: Size of the structuring element.
1126 :param cols: Width of the structuring element
1128 :param rows: Height of the structuring element
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.
1132 :param anchor_x: x-coordinate of the anchor
1134 :param anchor_y: y-coordinate of the anchor
1136 :param values: integer array of ``cols``*``rows`` elements that specifies the custom shape of the structuring element, when ``shape=CV_SHAPE_CUSTOM``.
1138 The function constructs and returns the structuring element that can be further passed to
1139 :ocv:func:`createMorphologyFilter`,
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.
1144 .. note:: When using OpenCV 1.x C API, the created structuring element ``IplConvKernel* element`` must be released in the end using ``cvReleaseStructuringElement(&element)``.
1149 Blurs an image using the median filter.
1151 .. ocv:function:: void medianBlur( InputArray src, OutputArray dst, int ksize )
1153 .. ocv:pyfunction:: cv2.medianBlur(src, ksize[, dst]) -> dst
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``.
1157 :param dst: destination array of the same size and type as ``src``.
1159 :param ksize: aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
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.
1166 :ocv:func:`bilateralFilter`,
1168 :ocv:func:`boxFilter`,
1169 :ocv:func:`GaussianBlur`
1175 Performs advanced morphological transformations.
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() )
1179 .. ocv:pyfunction:: cv2.morphologyEx(src, op, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst
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
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``.
1186 :param dst: Destination image of the same size and type as ``src`` .
1188 :param element: Structuring element.
1190 :param op: Type of a morphological operation that can be one of the following:
1192 * **MORPH_OPEN** - an opening operation
1194 * **MORPH_CLOSE** - a closing operation
1196 * **MORPH_GRADIENT** - a morphological gradient
1198 * **MORPH_TOPHAT** - "top hat"
1200 * **MORPH_BLACKHAT** - "black hat"
1202 :param iterations: Number of times erosion and dilation are applied.
1204 :param borderType: Pixel extrapolation method. See :ocv:func:`borderInterpolate` for details.
1206 :param borderValue: Border value in case of a constant border. The default value has a special meaning. See :ocv:func:`createMorphologyFilter` for details.
1208 The function can perform advanced morphological transformations using an erosion and dilation as basic operations.
1214 \texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))
1220 \texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))
1222 Morphological gradient:
1226 \texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )
1232 \texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )
1238 \texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}
1240 Any of the operations can be done in-place. In case of multi-channel images, each channel is processed independently.
1246 :ocv:func:`createMorphologyFilter`
1251 Calculates the Laplacian of an image.
1253 .. ocv:function:: void Laplacian( InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
1255 .. ocv:pyfunction:: cv2.Laplacian(src, ddepth[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst
1257 .. ocv:cfunction:: void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 )
1259 .. ocv:pyoldfunction:: cv.Laplace(src, dst, apertureSize=3) -> None
1261 :param src: Source image.
1263 :param dst: Destination image of the same size and the same number of channels as ``src`` .
1265 :param ddepth: Desired depth of the destination image.
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.
1269 :param scale: Optional scale factor for the computed Laplacian values. By default, no scaling is applied. See :ocv:func:`getDerivKernels` for details.
1271 :param delta: Optional delta value that is added to the results prior to storing them in ``dst`` .
1273 :param borderType: Pixel extrapolation method. See :ocv:func:`borderInterpolate` for details.
1275 The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator:
1279 \texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}
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:
1286 \vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}
1297 Blurs an image and downsamples it.
1299 .. ocv:function:: void pyrDown( InputArray src, OutputArray dst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT )
1301 .. ocv:pyfunction:: cv2.pyrDown(src[, dst[, dstsize[, borderType]]]) -> dst
1303 .. ocv:cfunction:: void cvPyrDown( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 )
1305 .. ocv:pyoldfunction:: cv.PyrDown(src, dst, filter=CV_GAUSSIAN_5X5) -> None
1307 :param src: input image.
1309 :param dst: output image; it has the specified size and the same type as ``src``.
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:
1316 | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}
1318 The function performs the downsampling step of the Gaussian pyramid construction. First, it convolves the source image with the kernel:
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}
1324 Then, it downsamples the image by rejecting even rows and columns.
1330 Upsamples an image and then blurs it.
1332 .. ocv:function:: void pyrUp( InputArray src, OutputArray dst, const Size& dstsize=Size(), int borderType=BORDER_DEFAULT )
1334 .. ocv:pyfunction:: cv2.pyrUp(src[, dst[, dstsize[, borderType]]]) -> dst
1336 .. ocv:cfunction:: cvPyrUp( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 )
1338 .. ocv:pyoldfunction:: cv.PyrUp(src, dst, filter=CV_GAUSSIAN_5X5) -> None
1340 :param src: input image.
1342 :param dst: output image. It has the specified size and the same type as ``src`` .
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:
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}
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.
1355 pyrMeanShiftFiltering
1356 ---------------------
1357 Performs initial step of meanshift segmentation of an image.
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) )
1361 .. ocv:pyfunction:: cv2.pyrMeanShiftFiltering(src, sp, sr[, dst[, maxLevel[, termcrit]]]) -> dst
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))
1365 .. ocv:pyoldfunction:: cv.PyrMeanShiftFiltering(src, dst, sp, sr, max_level=1, termcrit=(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 5, 1)) -> None
1367 :param src: The source 8-bit, 3-channel image.
1369 :param dst: The destination image of the same format and the same size as the source.
1371 :param sp: The spatial window radius.
1373 :param sr: The color window radius.
1375 :param maxLevel: Maximum level of the pyramid for the segmentation.
1377 :param termcrit: Termination criteria: when to stop meanshift iterations.
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:
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}
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:
1393 (X,Y)~(X',Y'), (R,G,B)~(R',G',B').
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):
1399 I(X,Y) <- (R*,G*,B*)
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``).
1406 Applies a separable linear filter to an image.
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 )
1410 .. ocv:pyfunction:: cv2.sepFilter2D(src, ddepth, kernelX, kernelY[, dst[, anchor[, delta[, borderType]]]]) -> dst
1412 :param src: Source image.
1414 :param dst: Destination image of the same size and the same number of channels as ``src`` .
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``
1422 when ``ddepth=-1``, the destination image will have the same depth as the source.
1424 :param kernelX: Coefficients for filtering each row.
1426 :param kernelY: Coefficients for filtering each column.
1428 :param anchor: Anchor position within the kernel. The default value :math:`(-1, 1)` means that the anchor is at the kernel center.
1430 :param delta: Value added to the filtered results before storing them.
1432 :param borderType: Pixel extrapolation method. See :ocv:func:`borderInterpolate` for details.
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`` .
1438 :ocv:func:`createSeparableLinearFilter`,
1439 :ocv:func:`filter2D`,
1441 :ocv:func:`GaussianBlur`,
1442 :ocv:func:`boxFilter`,
1448 Smooths the image in one of several ways.
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 )
1452 .. ocv:pyoldfunction:: cv.Smooth(src, dst, smoothtype=CV_GAUSSIAN, param1=3, param2=0, param3=0, param4=0)-> None
1454 :param src: The source image
1456 :param dst: The destination image
1458 :param smoothtype: Type of the smoothing:
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`
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})`
1466 * **CV_GAUSSIAN** linear convolution with a :math:`\texttt{size1}\times\texttt{size2}` Gaussian kernel
1469 * **CV_MEDIAN** median filter with a :math:`\texttt{size1}\times\texttt{size1}` square aperture
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
1475 :param size1: The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
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.
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:
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}
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).
1487 The function smooths an image using one of several methods. Every of the methods has some features and restrictions listed below:
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.
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.
1493 * Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.
1495 .. note:: The function is now obsolete. Use :ocv:func:`GaussianBlur`, :ocv:func:`blur`, :ocv:func:`medianBlur` or :ocv:func:`bilateralFilter`.
1500 Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
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 )
1504 .. ocv:pyfunction:: cv2.Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst
1506 .. ocv:cfunction:: void cvSobel( const CvArr* src, CvArr* dst, int xorder, int yorder, int aperture_size=3 )
1508 .. ocv:pyoldfunction:: cv.Sobel(src, dst, xorder, yorder, apertureSize=3)-> None
1510 :param src: input image.
1512 :param dst: output image of the same size and the same number of channels as ``src`` .
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``
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.
1522 :param xorder: order of the derivative x.
1524 :param yorder: order of the derivative y.
1526 :param ksize: size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
1528 :param scale: optional scale factor for the computed derivative values; by default, no scaling is applied (see :ocv:func:`getDerivKernels` for details).
1530 :param delta: optional delta value that is added to the results prior to storing them in ``dst``.
1532 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
1534 In all cases except one, the
1535 :math:`\texttt{ksize} \times
1536 \texttt{ksize}` separable kernel is used to calculate the
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.
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
1549 \vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}
1551 for the x-derivative, or transposed for the y-derivative.
1553 The function calculates an image derivative by convolving the image with the appropriate kernel:
1557 \texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}
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:
1566 \vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}
1568 The second case corresponds to a kernel of:
1572 \vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}
1577 :ocv:func:`Laplacian`,
1578 :ocv:func:`sepFilter2D`,
1579 :ocv:func:`filter2D`,
1580 :ocv:func:`GaussianBlur`,
1581 :ocv:func:`cartToPolar`
1587 Calculates the first x- or y- image derivative using Scharr operator.
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 )
1591 .. ocv:pyfunction:: cv2.Scharr(src, ddepth, dx, dy[, dst[, scale[, delta[, borderType]]]]) -> dst
1593 :param src: input image.
1595 :param dst: output image of the same size and the same number of channels as ``src``.
1597 :param ddepth: output image depth (see :ocv:func:`Sobel` for the list of supported combination of ``src.depth()`` and ``ddepth``).
1599 :param dx: order of the derivative x.
1601 :param dy: order of the derivative y.
1603 :param scale: optional scale factor for the computed derivative values; by default, no scaling is applied (see :ocv:func:`getDerivKernels` for details).
1605 :param delta: optional delta value that is added to the results prior to storing them in ``dst``.
1607 :param borderType: pixel extrapolation method (see :ocv:func:`borderInterpolate` for details).
1609 The function computes the first x- or y- spatial image derivative using the Scharr operator. The call
1613 \texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}
1619 \texttt{Sobel(src, dst, ddepth, dx, dy, CV\_SCHARR, scale, delta, borderType)} .
1623 :ocv:func:`cartToPolar`