ocl::
BaseRowFilter_GPU
¶Base class for linear or non-linear filters that processes rows of 2D arrays. Such filters are used for the “horizontal” filtering passes in separable filters.
class CV_EXPORTS BaseRowFilter_GPU
{
public:
BaseRowFilter_GPU(int ksize_, int anchor_, int bordertype_) : ksize(ksize_), anchor(anchor_), bordertype(bordertype_) {}
virtual ~BaseRowFilter_GPU() {}
virtual void operator()(const oclMat &src, oclMat &dst) = 0;
int ksize, anchor, bordertype;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside ocl::FilterEngine_GPU
.
ocl::
BaseColumnFilter_GPU
¶Base class for linear or non-linear filters that processes columns of 2D arrays. Such filters are used for the “vertical” filtering passes in separable filters.
class CV_EXPORTS BaseColumnFilter_GPU
{
public:
BaseColumnFilter_GPU(int ksize_, int anchor_, int bordertype_) : ksize(ksize_), anchor(anchor_), bordertype(bordertype_) {}
virtual ~BaseColumnFilter_GPU() {}
virtual void operator()(const oclMat &src, oclMat &dst) = 0;
int ksize, anchor, bordertype;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside ocl::FilterEngine_GPU
.
ocl::
BaseFilter_GPU
¶Base class for non-separable 2D filters.
class CV_EXPORTS BaseFilter_GPU
{
public:
BaseFilter_GPU(const Size &ksize_, const Point &anchor_, const int &borderType_)
: ksize(ksize_), anchor(anchor_), borderType(borderType_) {}
virtual ~BaseFilter_GPU() {}
virtual void operator()(const oclMat &src, oclMat &dst) = 0;
Size ksize;
Point anchor;
int borderType;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside ocl::FilterEngine_GPU
ocl::
FilterEngine_GPU
¶Base class for the Filter Engine.
class CV_EXPORTS FilterEngine_GPU
{
public:
virtual ~FilterEngine_GPU() {}
virtual void apply(const oclMat &src, oclMat &dst, Rect roi = Rect(0, 0, -1, -1)) = 0;
};
The class can be used to apply an arbitrary filtering operation to an image. It contains all the necessary intermediate buffers. Pointers to the initialized FilterEngine_GPU
instances are returned by various create*Filter_GPU
functions (see below), and they are used inside high-level functions such as ocl::filter2D()
, ocl::erode()
, ocl::Sobel()
, and others.
By using FilterEngine_GPU
instead of functions you can avoid unnecessary memory allocation for intermediate buffers and get better performance:
while (...)
{
ocl::oclMat src = getImg();
ocl::oclMat dst;
// Allocate and release buffers at each iterations
ocl::GaussianBlur(src, dst, ksize, sigma1);
}
// Allocate buffers only once
cv::Ptr<ocl::FilterEngine_GPU> filter =
ocl::createGaussianFilter_GPU(CV_8UC4, ksize, sigma1);
while (...)
{
ocl::oclMat src = getImg();
ocl::oclMat dst;
filter->apply(src, dst, cv::Rect(0, 0, src.cols, src.rows));
}
// Release buffers only once
filter.release();
FilterEngine_GPU
can process a rectangular sub-region of an image. By default, if roi == Rect(0,0,-1,-1)
, FilterEngine_GPU
processes the inner region of an image ( Rect(anchor.x, anchor.y, src_size.width - ksize.width, src_size.height - ksize.height)
) because some filters do not check whether indices are outside the image for better performance. See below to understand which filters support processing the whole image and which do not and identify image type limitations.
Note
The GPU filters do not support the in-place mode.
See also
ocl::BaseRowFilter_GPU
, ocl::BaseColumnFilter_GPU
, ocl::BaseFilter_GPU
, ocl::createFilter2D_GPU()
, ocl::createSeparableFilter_GPU()
, ocl::createBoxFilter_GPU()
, ocl::createMorphologyFilter_GPU()
, ocl::createLinearFilter_GPU()
, ocl::createSeparableLinearFilter_GPU()
, ocl::createDerivFilter_GPU()
, ocl::createGaussianFilter_GPU()
Creates a non-separable filter engine with the specified filter.
Ptr<FilterEngine_GPU> ocl::
createFilter2D_GPU
(const Ptr<BaseFilter_GPU> filter2D)¶Parameters: |
|
---|
Usually this function is used inside such high-level functions as ocl::createLinearFilter_GPU()
, ocl::createBoxFilter_GPU()
.
Creates a separable filter engine with the specified filters.
Ptr<FilterEngine_GPU> ocl::
createSeparableFilter_GPU
(const Ptr<BaseRowFilter_GPU>& rowFilter, const Ptr<BaseColumnFilter_GPU>& columnFilter)¶Parameters: |
|
---|
Usually this function is used inside such high-level functions as ocl::createSeparableLinearFilter_GPU()
.
Creates a normalized 2D box filter.
Ptr<FilterEngine_GPU> ocl::
createBoxFilter_GPU
(int srcType, int dstType, const Size& ksize, const Point& anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)¶
Ptr<BaseFilter_GPU> ocl::
getBoxFilter_GPU
(int srcType, int dstType, const Size& ksize, Point anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
See also
Smooths the image using the normalized box filter.
void ocl::
boxFilter
(const oclMat& src, oclMat& dst, int ddepth, Size ksize, Point anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
Smoothes image using box filter.
Acts as a synonym for the normalized box filter.
void ocl::
blur
(const oclMat& src, oclMat& dst, Size ksize, Point anchor=Point(-1, -1), int borderType=BORDER_CONSTANT)¶Parameters: |
|
---|
See also
Creates a 2D morphological filter.
Ptr<FilterEngine_GPU> ocl::
createMorphologyFilter_GPU
(int op, int type, const Mat& kernel, const Point& anchor=Point(-1, -1), int iterations=1)¶
Ptr<BaseFilter_GPU> ocl::
getMorphologyFilter_GPU
(int op, int type, const Mat& kernel, const Size& ksize, Point anchor=Point(-1, -1))¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Creates a non-separable linear filter.
Ptr<FilterEngine_GPU> ocl::
createLinearFilter_GPU
(int srcType, int dstType, const Mat& kernel, const Point& anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
See also
Applies the non-separable 2D linear filter to an image.
void ocl::
filter2D
(const oclMat& src, oclMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1, -1), double delta=0.0, int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
Creates a primitive row filter with the specified kernel.
Ptr<BaseRowFilter_GPU> ocl::
getLinearRowFilter_GPU
(int srcType, int bufType, const Mat& rowKernel, int anchor=-1, int bordertype=BORDER_DEFAULT)¶Parameters: |
|
---|
See also
Creates a primitive column filter with the specified kernel.
Ptr<BaseColumnFilter_GPU> ocl::
getLinearColumnFilter_GPU
(int bufType, int dstType, const Mat& columnKernel, int anchor=-1, int bordertype=BORDER_DEFAULT, double delta=0.0)¶Parameters: |
|
---|
Creates a separable linear filter engine.
Ptr<FilterEngine_GPU> ocl::
createSeparableLinearFilter_GPU
(int srcType, int dstType, const Mat& rowKernel, const Mat& columnKernel, const Point& anchor=Point(-1, -1), double delta=0.0, int bordertype=BORDER_DEFAULT, Size imgSize=Size(-1,-1) )¶Parameters: |
|
---|
Applies a separable 2D linear filter to an image.
void ocl::
sepFilter2D
(const oclMat& src, oclMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, Point anchor=Point(-1, -1), double delta=0.0, int bordertype=BORDER_DEFAULT)¶Parameters: |
|
---|
Creates a filter engine for the generalized Sobel operator.
Ptr<FilterEngine_GPU> ocl::
createDerivFilter_GPU
(int srcType, int dstType, int dx, int dy, int ksize, int borderType=BORDER_DEFAULT, Size imgSize=Size(-1,-1) )¶Parameters: |
|
---|
Returns void
void ocl::
Sobel
(const oclMat& src, oclMat& dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0.0, int bordertype=BORDER_DEFAULT)¶Parameters: |
|
---|
The function computes the first x- or y- spatial image derivative using Sobel operator. Surpport 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4 data type.
Returns void
void ocl::
Scharr
(const oclMat& src, oclMat& dst, int ddepth, int dx, int dy, double scale=1, double delta=0.0, int bordertype=BORDER_DEFAULT)¶Parameters: |
|
---|
The function computes the first x- or y- spatial image derivative using Scharr operator. Surpport 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4 data type.
Creates a Gaussian filter engine.
Ptr<FilterEngine_GPU> ocl::
createGaussianFilter_GPU
(int type, Size ksize, double sigma1, double sigma2=0, int bordertype=BORDER_DEFAULT, Size imgSize=Size(-1,-1) )¶Parameters: |
|
---|
Returns void
void ocl::
GaussianBlur
(const oclMat& src, oclMat& dst, Size ksize, double sigma1, double sigma2=0, int bordertype=BORDER_DEFAULT)¶Parameters: |
|
---|
The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported. Surpport 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4 data type.
Returns void
void ocl::
Laplacian
(const oclMat& src, oclMat& dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
The function calculates the Laplacian of the source image by adding up the second x and y derivatives calculated using the Sobel operator.
Returns void
void ocl::
convolve
(const oclMat& image, const oclMat& temp1, oclMat& result)¶Parameters: |
|
---|
Convolves an image with the kernel. Supports only CV_32FC1 data types and do not support ROI.
Returns void
void ocl::
bilateralFilter
(const oclMat& src, oclMat& dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
Applies bilateral filter to the image. Supports 8UC1 8UC4 data types.
Returns void
void ocl::
adaptiveBilateralFilter
(const oclMat& src, oclMat& dst, Size ksize, double sigmaSpace, double maxSigmaColor=20.0, Point anchor=Point(-1, -1), int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
A main part of our strategy will be to load each raw pixel once, and reuse it to calculate all pixels in the output (filtered) image that need this pixel value. The math of the filter is that of the usual bilateral filter, except that the sigma color is calculated in the neighborhood, and clamped by the optional input value.
Local memory organization
Note
We partition the image to non-overlapping blocks of size (Ux, Uy). Each such block will correspond to the pixel locations where we will calculate the filter result in one workgroup. Considering neighbourhoods of sizes (kx, ky), where kx = 2 dx + 1, and ky = 2 dy + 1 (in image ML, dx = dy = 1, and kx = ky = 3), it is clear that we need to load data of size Wx = Ux + 2 dx, Wy = Uy + 2 dy. Furthermore, if (Sx, Sy) is the top left pixel coordinates for a particular block, and (Sx + Ux - 1, Sy + Uy -1) is to botom right coordinate of the block, we need to load data starting at top left coordinate (PSx, PSy) = (Sx - dx, Sy - dy), and ending at bottom right coordinate (Sx + Ux - 1 + dx, Sy + Uy - 1 + dy). The workgroup layout is (Wx,1). However, to take advantage of the natural hardware properties (preferred wavefront sizes), we restrict Wx to be a multiple of that preferred wavefront size (for current AMD hardware this is typically 64). Each thread in the workgroup will load Wy elements (under the constraint that Wx*Wy*pixel width <= max local memory).
Applies bilateral filter to the image. Supports 8UC1 8UC3 data types.
Returns void
void ocl::
copyMakeBorder
(const oclMat& src, oclMat& dst, int top, int bottom, int left, int right, int boardtype, const Scalar& value=Scalar())¶Parameters: |
|
---|
Forms a border around the image. Supports 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4 data types.
Returns void
void ocl::
dilate
(const oclMat& src, oclMat& dst, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue())¶Parameters: |
|
---|
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. Supports 8UC1 8UC4 data types.
Returns void
void ocl::
erode
(const oclMat& src, oclMat& dst, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue())¶Parameters: |
|
---|
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. Supports 8UC1 8UC4 data types.
Returns void
void ocl::
morphologyEx
(const oclMat& src, oclMat& dst, int op, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1, int borderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue())¶Parameters: |
|
---|
A wrapper for erode and dilate. Supports 8UC1 8UC4 data types.
Smoothes an image and downsamples it.
void ocl::
pyrDown
(const oclMat& src, oclMat& dst)¶Parameters: |
|
---|
See also
Upsamples an image and then smoothes it.
void ocl::
pyrUp
(const oclMat& src, oclMat& dst)¶Parameters: |
|
---|
See also
Computes a vertical (column) sum.
void ocl::
columnSum
(const oclMat& src, oclMat& sum)¶Parameters: |
|
---|
Performs linear blending of two images.
void ocl::
blendLinear
(const oclMat& img1, const oclMat& img2, const oclMat& weights1, const oclMat& weights2, oclMat& result)¶Parameters: |
|
---|
Blurs an image using the median filter.
void ocl::
medianFilter
(const oclMat& src, oclMat& dst, int m)¶Parameters: |
|
---|
The function smoothes an image using the median filter with the texttt{m} times texttt{m} aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.