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.InputArray
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.
OutputArray
Output image of the same size and type as src.
Size
Blurring kernel size.
Point
default:"Point(-1,-1)"
Anchor point; default value Point(-1,-1) means that the anchor is at the kernel center.
int
default:"BORDER_DEFAULT"
Border mode used to extrapolate pixels outside of the image. BORDER_WRAP is not supported.
GaussianBlur
Blurs an image using a Gaussian filter.InputArray
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.
OutputArray
Output image of the same size and type as src.
Size
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.
double
Gaussian kernel standard deviation in X direction.
double
default:"0"
Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
medianBlur
Blurs an image using the median filter.InputArray
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.
OutputArray
Destination array of the same size and type as src.
int
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.InputArray
Source 8-bit or floating-point, 1-channel or 3-channel image.
OutputArray
Destination image of the same size and type as src.
int
Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace.
double
Filter sigma in the color space. A larger value means that farther colors within the pixel neighborhood will be mixed together.
double
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.
int
default:"BORDER_DEFAULT"
Border mode used to extrapolate pixels outside of the image.
This filter does not work inplace.
boxFilter
Blurs an image using the box filter.InputArray
Input image.
OutputArray
Output image of the same size and type as src.
int
The output image depth (-1 to use src.depth()).
Size
Blurring kernel size.
Point
default:"Point(-1,-1)"
Anchor point; default value Point(-1,-1) means that the anchor is at the kernel center.
bool
default:"true"
Flag, specifying whether the kernel is normalized by its area or not.
int
default:"BORDER_DEFAULT"
Border mode used to extrapolate pixels outside of the image. BORDER_WRAP is not supported.
Custom Filters
filter2D
Convolves an image with the kernel.InputArray
Input image.
OutputArray
Output image of the same size and the same number of channels as src.
int
Desired depth of the destination image. See combinations in the documentation.
InputArray
Convolution kernel (or rather a correlation kernel), a single-channel floating point matrix.
Point
default:"Point(-1,-1)"
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.
double
default:"0"
Optional value added to the filtered pixels before storing them in dst.
int
default:"BORDER_DEFAULT"
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.InputArray
Source image.
OutputArray
Destination image of the same size and the same number of channels as src.
int
Destination image depth.
InputArray
Coefficients for filtering each row.
InputArray
Coefficients for filtering each column.
Point
default:"Point(-1,-1)"
Anchor position within the kernel. The default value (-1,-1) means that the anchor is at the kernel center.
double
default:"0"
Value added to the filtered results before storing them.
int
default:"BORDER_DEFAULT"
Pixel extrapolation method. BORDER_WRAP is not supported.
Helper Functions
getGaussianKernel
Returns Gaussian filter coefficients.int
Aperture size. It should be odd and positive.
double
Gaussian standard deviation. If it is non-positive, it is computed from ksize as sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8.
int
default:"CV_64F"
Type of filter coefficients. It can be CV_32F or CV_64F.
getDerivKernels
Returns filter coefficients for computing spatial image derivatives.OutputArray
Output matrix of row filter coefficients.
OutputArray
Output matrix of column filter coefficients.
int
Derivative order in respect of x.
int
Derivative order in respect of y.
int
Aperture size. It can be FILTER_SCHARR, 1, 3, 5, or 7.
bool
default:"false"
Flag indicating whether to normalize (scale down) the filter coefficients or not.
int
default:"CV_32F"
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.int
Element shape that could be one of MorphShapes: MORPH_RECT, MORPH_CROSS, MORPH_ELLIPSE, MORPH_DIAMOND.
Size
Size of the structuring element.
Point
default:"Point(-1,-1)"
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)
