Border Extrapolation
Many filtering functions need to extrapolate values of non-existing pixels (e.g., when processing pixels near image borders). OpenCV provides several border extrapolation methods via theBorderTypes enum.
Smoothing Filters
blur
Blurs an image using the normalized box filter.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.
Output image of the same size and type as src.
Blurring kernel size.
Anchor point; default value Point(-1,-1) means that the anchor is at the kernel center.
Border mode used to extrapolate pixels outside of the image. BORDER_WRAP is not supported.
GaussianBlur
Blurs an image using a Gaussian filter.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.
Output image of the same size and type as src.
Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. Or, they can be zeros and then they are computed from sigma.
Gaussian kernel standard deviation in X direction.
Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX.
Pixel extrapolation method. BORDER_WRAP is not supported.
medianBlur
Blurs an image using the median filter.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.
Destination array of the same size and type as src.
Aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 …
The median filter uses BORDER_REPLICATE internally to cope with border pixels.
bilateralFilter
Applies the bilateral filter to an image.Source 8-bit or floating-point, 1-channel or 3-channel image.
Destination image of the same size and type as src.
Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace.
Filter sigma in the color space. A larger value means that farther colors within the pixel neighborhood will be mixed together.
Filter sigma in the coordinate space. A larger value means that farther pixels will influence each other as long as their colors are close enough.
Border mode used to extrapolate pixels outside of the image.
This filter does not work inplace.
boxFilter
Blurs an image using the box filter.Input image.
Output image of the same size and type as src.
The output image depth (-1 to use src.depth()).
Blurring kernel size.
Anchor point; default value Point(-1,-1) means that the anchor is at the kernel center.
Flag, specifying whether the kernel is normalized by its area or not.
Border mode used to extrapolate pixels outside of the image. BORDER_WRAP is not supported.
Custom Filters
filter2D
Convolves an image with the kernel.Input image.
Output image of the same size and the same number of channels as src.
Desired depth of the destination image. See combinations in the documentation.
Convolution kernel (or rather a correlation kernel), a single-channel floating point matrix.
Anchor of the kernel that indicates the relative position of a filtered point within the kernel; default value (-1,-1) means that the anchor is at the kernel center.
Optional value added to the filtered pixels before storing them in dst.
Pixel extrapolation method. BORDER_WRAP is not supported.
The function actually computes correlation, not convolution. If you need a real convolution, flip the kernel using flip() and set the new anchor.
sepFilter2D
Applies a separable linear filter to an image.Source image.
Destination image of the same size and the same number of channels as src.
Destination image depth.
Coefficients for filtering each row.
Coefficients for filtering each column.
Anchor position within the kernel. The default value (-1,-1) means that the anchor is at the kernel center.
Value added to the filtered results before storing them.
Pixel extrapolation method. BORDER_WRAP is not supported.
Helper Functions
getGaussianKernel
Returns Gaussian filter coefficients.Aperture size. It should be odd and positive.
Gaussian standard deviation. If it is non-positive, it is computed from ksize as sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8.
Type of filter coefficients. It can be CV_32F or CV_64F.
getDerivKernels
Returns filter coefficients for computing spatial image derivatives.Output matrix of row filter coefficients.
Output matrix of column filter coefficients.
Derivative order in respect of x.
Derivative order in respect of y.
Aperture size. It can be FILTER_SCHARR, 1, 3, 5, or 7.
Flag indicating whether to normalize (scale down) the filter coefficients or not.
Type of filter coefficients. It can be CV_32F or CV_64F.
getStructuringElement
Returns a structuring element of the specified size and shape for morphological operations.Element shape that could be one of MorphShapes: MORPH_RECT, MORPH_CROSS, MORPH_ELLIPSE, MORPH_DIAMOND.
Size of the structuring element.
Anchor position within the element. The default value (-1, -1) means that the anchor is at the center.
Enumerations
MorphShapes
Shape of the structuring element:MORPH_RECT- A rectangular structuring elementMORPH_CROSS- A cross-shaped structuring elementMORPH_ELLIPSE- An elliptic structuring elementMORPH_DIAMOND- A diamond structuring element defined by Manhattan distance
SpecialFilter
FILTER_SCHARR- Scharr filter (-1)
