### Navigation

- index
- next |
- previous |
- OpenCV 3.0.0.0-dev documentation »
- OpenCV API Reference »
- gpufilters. GPU-accelerated Image Filtering »

# Image Filtering

Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images.

Note

- An example containing all basic morphology operators like erode and dilate can be found at opencv_source_code/samples/gpu/morphology.cpp

## gpu::Filter

class `gpu::``Filter`

Common interface for all GPU filters

    class CV_EXPORTS Filter : public Algorithm
    {
    public:
        virtual void apply(InputArray src, OutputArray dst, Stream& stream = Stream::Null()) = 0;
    };

## gpu::Filter::apply

Applies the specified filter to the image.

C++:`` void `gpu::Filter::``apply`(InputArray src, OutputArray dst, Stream& stream=Stream::Null())`= 0`

  Parameters: | src – Input image. dst – Output image. stream – Stream for the asynchronous version.

## gpu::createBoxFilter

Creates a normalized 2D box filter.

C++:`` Ptr<Filter> `gpu::``createBoxFilter`(int srcType, int dstType, Size ksize, Point anchor=Point(-1,-1), int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input image type. Only `CV_8UC1` and `CV_8UC4` are supported for now. dstType – Output image type. Only the same type as `src` is supported for now. ksize – Kernel size. anchor – Anchor point. The default value `Point(-1, -1)` means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

See also

`boxFilter()`

## gpu::createLinearFilter

Creates a non-separable linear 2D filter.

C++:`` Ptr<Filter> `gpu::``createLinearFilter`(int srcType, int dstType, InputArray kernel, Point anchor=Point(-1,-1), int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input image type. Supports `CV_8U` , `CV_16U` and `CV_32F` one and four channel image. dstType – Output image type. Only the same type as `src` is supported for now. kernel – 2D array of filter coefficients. anchor – Anchor point. The default value Point(-1, -1) means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

See also

`filter2D()`

## gpu::createLaplacianFilter

Creates a Laplacian operator.

C++:`` Ptr<Filter> `gpu::``createLaplacianFilter`(int srcType, int dstType, int ksize=1, double scale=1, int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input image type. Supports `CV_8U` , `CV_16U` and `CV_32F` one and four channel image. dstType – Output image type. Only the same type as `src` is supported for now. ksize – Aperture size used to compute the second-derivative filters (see `getDerivKernels()`). It must be positive and odd. Only `ksize` = 1 and `ksize` = 3 are supported. scale – Optional scale factor for the computed Laplacian values. By default, no scaling is applied (see `getDerivKernels()` ). borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

See also

`Laplacian()`

## gpu::createSeparableLinearFilter

Creates a separable linear filter.

C++:`` Ptr<Filter> `gpu::``createSeparableLinearFilter`(int srcType, int dstType, InputArray rowKernel, InputArray columnKernel, Point anchor=Point(-1,-1), int rowBorderMode=BORDER_DEFAULT, int columnBorderMode=-1)

  Parameters: | srcType – Source array type. dstType – Destination array type. rowKernel – Horizontal filter coefficients. Support kernels with `size <= 32` . columnKernel – Vertical filter coefficients. Support kernels with `size <= 32` . anchor – Anchor position within the kernel. Negative values mean that anchor is positioned at the aperture center. rowBorderMode – Pixel extrapolation method in the vertical direction For details, see `borderInterpolate()`. columnBorderMode – Pixel extrapolation method in the horizontal direction.

See also

`sepFilter2D()`

## gpu::createDerivFilter

Creates a generalized Deriv operator.

C++:`` Ptr<Filter> `gpu::``createDerivFilter`(int srcType, int dstType, int dx, int dy, int ksize, bool normalize=false, double scale=1, int rowBorderMode=BORDER_DEFAULT, int columnBorderMode=-1)

  Parameters: | srcType – Source image type. dstType – Destination array type. dx – Derivative order in respect of x. dy – Derivative order in respect of y. ksize – Aperture size. See `getDerivKernels()` for details. normalize – Flag indicating whether to normalize (scale down) the filter coefficients or not. See `getDerivKernels()` for details. scale – Optional scale factor for the computed derivative values. By default, no scaling is applied. For details, see `getDerivKernels()` . rowBorderMode – Pixel extrapolation method in the vertical direction. For details, see `borderInterpolate()`. columnBorderMode – Pixel extrapolation method in the horizontal direction.

## gpu::createSobelFilter

Creates a Sobel operator.

C++:`` Ptr<Filter> `gpu::``createSobelFilter`(int srcType, int dstType, int dx, int dy, int ksize=3, double scale=1, int rowBorderMode=BORDER_DEFAULT, int columnBorderMode=-1)

  Parameters: | srcType – Source image type. dstType – Destination array type. dx – Derivative order in respect of x. dy – Derivative order in respect of y. ksize – Size of the extended Sobel kernel. Possible values are 1, 3, 5 or 7. scale – Optional scale factor for the computed derivative values. By default, no scaling is applied. For details, see `getDerivKernels()` . rowBorderMode – Pixel extrapolation method in the vertical direction. For details, see `borderInterpolate()`. columnBorderMode – Pixel extrapolation method in the horizontal direction.

See also

`Sobel()`

## gpu::createScharrFilter

Creates a vertical or horizontal Scharr operator.

C++:`` Ptr<Filter> `gpu::``createScharrFilter`(int srcType, int dstType, int dx, int dy, double scale=1, int rowBorderMode=BORDER_DEFAULT, int columnBorderMode=-1)

  Parameters: | srcType – Source image type. dstType – Destination array type. dx – Order of the derivative x. dy – Order of the derivative y. scale – Optional scale factor for the computed derivative values. By default, no scaling is applied. See `getDerivKernels()` for details. rowBorderMode – Pixel extrapolation method in the vertical direction. For details, see `borderInterpolate()`. columnBorderMode – Pixel extrapolation method in the horizontal direction.

See also

`Scharr()`

## gpu::createGaussianFilter

Creates a Gaussian filter.

C++:`` Ptr<Filter> `gpu::``createGaussianFilter`(int srcType, int dstType, Size ksize, double sigma1, double sigma2=0, int rowBorderMode=BORDER_DEFAULT, int columnBorderMode=-1)

  Parameters: | srcType – Source image type. dstType – Destination array type. ksize – Aperture size. See `getGaussianKernel()` for details. sigma1 – Gaussian sigma in the horizontal direction. See `getGaussianKernel()` for details. sigma2 – Gaussian sigma in the vertical direction. If 0, then . rowBorderMode – Pixel extrapolation method in the vertical direction. For details, see `borderInterpolate()`. columnBorderMode – Pixel extrapolation method in the horizontal direction.

See also

`GaussianBlur()`

## gpu::createMorphologyFilter

Creates a 2D morphological filter.

C++:`` Ptr<Filter> `gpu::``createMorphologyFilter`(int op, int srcType, InputArray kernel, Point anchor=Point(-1, -1), int iterations=1)

  Parameters: | op – Type of morphological operation. The following types are possible: MORPH_ERODE erode MORPH_DILATE dilate MORPH_OPEN opening MORPH_CLOSE closing MORPH_GRADIENT morphological gradient MORPH_TOPHAT “top hat” MORPH_BLACKHAT “black hat” srcType – Input/output image type. Only `CV_8UC1` and `CV_8UC4` are supported. kernel – 2D 8-bit structuring element for the morphological operation. anchor – Anchor position within the structuring element. Negative values mean that the anchor is at the center. iterations – Number of times erosion and dilation to be applied.

See also

`morphologyEx()`

## gpu::createBoxMaxFilter

Creates the maximum filter.

C++:`` Ptr<Filter> `gpu::``createBoxMaxFilter`(int srcType, Size ksize, Point anchor=Point(-1, -1), int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input/output image type. Only `CV_8UC1` and `CV_8UC4` are supported. ksize – Kernel size. anchor – Anchor point. The default value (-1) means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

## gpu::createBoxMinFilter

Creates the minimum filter.

C++:`` Ptr<Filter> `gpu::``createBoxMinFilter`(int srcType, Size ksize, Point anchor=Point(-1, -1), int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input/output image type. Only `CV_8UC1` and `CV_8UC4` are supported. ksize – Kernel size. anchor – Anchor point. The default value (-1) means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

## gpu::createRowSumFilter

Creates a horizontal 1D box filter.

C++:`` Ptr<Filter> `gpu::``createRowSumFilter`(int srcType, int dstType, int ksize, int anchor=-1, int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input image type. Only `CV_8UC1` type is supported for now. sumType – Output image type. Only `CV_32FC1` type is supported for now. ksize – Kernel size. anchor – Anchor point. The default value (-1) means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

## gpu::createColumnSumFilter

Creates a vertical 1D box filter.

C++:`` Ptr<Filter> `gpu::``createColumnSumFilter`(int srcType, int dstType, int ksize, int anchor=-1, int borderMode=BORDER_DEFAULT, Scalar borderVal=Scalar::all(0))

  Parameters: | srcType – Input image type. Only `CV_8UC1` type is supported for now. sumType – Output image type. Only `CV_32FC1` type is supported for now. ksize – Kernel size. anchor – Anchor point. The default value (-1) means that the anchor is at the kernel center. borderMode – Pixel extrapolation method. For details, see `borderInterpolate()` . borderVal – Default border value.

## Help and Feedback

You did not find what you were looking for?

- Ask a question on the Q&A forum.
- If you think something is missing or wrong in the documentation, please file a bug report.

### Navigation

- index
- next |
- previous |
- OpenCV 3.0.0.0-dev documentation »
- OpenCV API Reference »
- gpufilters. GPU-accelerated Image Filtering »