Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images (represented as Mat() ‘s), that is, for each pixel location in the source image some its (normally rectangular) 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 etc. The computed response is stored to the destination image at the same location . It means, that the output image will be of the same size as the input image. Normally, the functions supports 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.
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 we want to smooth an image using a Gaussian filter, then during the processing of the left-most pixels in each row we need pixels to the left of them, i.e. outside of the image. We can let those pixels be the same as the left-most image pixels (i.e. use “replicated border” extrapolation method), or assume that all the non-existing pixels are zeros (“contant border” extrapolation method) etc.
An IplConvKernel is a rectangular convolution kernel, created by function CreateStructuringElementEx .
Copies an image and makes a border around it.
The function copies the source 2D array into the interior of the destination array and makes a border of the specified type around the copied area. The function is useful when one needs to emulate border type that is different from the one embedded into a specific algorithm implementation. For example, morphological functions, as well as most of other filtering functions in OpenCV, internally use replication border type, while the user may need a zero border or a border, filled with 1’s or 255’s.
Creates a structuring element.
The function CreateStructuringElementEx allocates and fills the structure IplConvKernel , which can be used as a structuring element in the morphological operations.
Dilates an image by using a specific structuring element.
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:
The function supports the in-place mode. Dilation can be applied several ( iterations ) times. For color images, each channel is processed independently.
Erodes an image by using a specific structuring element.
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:
The function supports the in-place mode. Erosion can be applied several ( iterations ) times. For color images, each channel is processed independently.
Convolves an image with the kernel.
The function applies an arbitrary linear filter to the image. In-place operation is supported. When the aperture is partially outside the image, the function interpolates outlier pixel values from the nearest pixels that are inside the image.
Calculates the Laplacian of an image.
The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator:
Setting apertureSize = 1 gives the fastest variant that is equal to convolving the image with the following kernel:
Similar to the Sobel function, no scaling is done and the same combinations of input and output formats are supported.
Performs advanced morphological transformations.
The function can perform advanced morphological transformations using erosion and dilation as basic operations.
The temporary image temp is required for a morphological gradient and, in the case of in-place operation, for “top hat” and “black hat”.
Downsamples an image.
The function performs the downsampling step of the Gaussian pyramid decomposition. First it convolves the source image with the specified filter and then downsamples the image by rejecting even rows and columns.
Deletes a structuring element.
|Parameter:||element – Pointer to the deleted structuring element|
The function releases the structure IplConvKernel that is no longer needed. If *element is NULL , the function has no effect.
Smooths the image in one of several ways.
The function smooths an image using one of several methods. Every of the methods has some features and restrictions listed below
Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format (similar to Sobel and Laplace ) and 32-bit floating point to 32-bit floating-point format.
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.
Median and bilateral filters work with 1- or 3-channel 8-bit images and can not process images in-place.
Calculates the first, second, third or mixed image derivatives using an extended Sobel operator.
In all cases except 1, an separable kernel will be used to calculate the derivative. For a or a kernel is used (Gaussian smoothing is not done). There is also the special value CV_SCHARR (-1) that corresponds to a Scharr filter that may give more accurate results than a Sobel. Scharr aperture is
for the x-derivative or transposed for the y-derivative.
The function calculates the image derivative by convolving the image with the appropriate kernel:
The Sobel operators combine Gaussian smoothing and differentiation so the result is more or less resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, apertureSize = 3) or ( xorder = 0, yorder = 1, apertureSize = 3) to calculate the first x- or y- image derivative. The first case corresponds to a kernel of:
and the second one corresponds to a kernel of:
or a kernel of:
depending on the image origin ( origin field of IplImage structure). No scaling is done, so the destination image usually has larger numbers (in absolute values) than the source image does. To avoid overflow, the function requires a 16-bit destination image if the source image is 8-bit. The result can be converted back to 8-bit using the ConvertScale or the ConvertScaleAbs function. Besides 8-bit images the function can process 32-bit floating-point images. Both the source and the destination must be single-channel images of equal size or equal ROI size.