OpenCV  2.4.13.3
Open Source Computer Vision
cv::FilterEngine Class Reference

#include <imgproc.hpp>

Public Member Functions

 FilterEngine ()
 the default constructor More...
 
 FilterEngine (const Ptr< BaseFilter > &_filter2D, const Ptr< BaseRowFilter > &_rowFilter, const Ptr< BaseColumnFilter > &_columnFilter, int srcType, int dstType, int bufType, int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1, const Scalar &_borderValue=Scalar())
 the full constructor. Either _filter2D or both _rowFilter and _columnFilter must be non-empty. More...
 
virtual ~FilterEngine ()
 the destructor More...
 
void init (const Ptr< BaseFilter > &_filter2D, const Ptr< BaseRowFilter > &_rowFilter, const Ptr< BaseColumnFilter > &_columnFilter, int srcType, int dstType, int bufType, int _rowBorderType=BORDER_REPLICATE, int _columnBorderType=-1, const Scalar &_borderValue=Scalar())
 reinitializes the engine. The previously assigned filters are released. More...
 
virtual int start (Size wholeSize, Rect roi, int maxBufRows=-1)
 starts filtering of the specified ROI of an image of size wholeSize. More...
 
virtual int start (const Mat &src, const Rect &srcRoi=Rect(0, 0,-1,-1), bool isolated=false, int maxBufRows=-1)
 starts filtering of the specified ROI of the specified image. More...
 
virtual int proceed (const uchar *src, int srcStep, int srcCount, uchar *dst, int dstStep)
 processes the next srcCount rows of the image. More...
 
virtual void apply (const Mat &src, Mat &dst, const Rect &srcRoi=Rect(0, 0,-1,-1), Point dstOfs=Point(0, 0), bool isolated=false)
 applies filter to the specified ROI of the image. if srcRoi=(0,0,-1,-1), the whole image is filtered. More...
 
bool isSeparable () const
 returns true if the filter is separable More...
 
int remainingInputRows () const
 returns the number More...
 
int remainingOutputRows () const
 

Public Attributes

int srcType
 
int dstType
 
int bufType
 
Size ksize
 
Point anchor
 
int maxWidth
 
Size wholeSize
 
Rect roi
 
int dx1
 
int dx2
 
int rowBorderType
 
int columnBorderType
 
vector< intborderTab
 
int borderElemSize
 
vector< ucharringBuf
 
vector< ucharsrcRow
 
vector< ucharconstBorderValue
 
vector< ucharconstBorderRow
 
int bufStep
 
int startY
 
int startY0
 
int endY
 
int rowCount
 
int dstY
 
vector< uchar * > rows
 
Ptr< BaseFilterfilter2D
 
Ptr< BaseRowFilterrowFilter
 
Ptr< BaseColumnFiltercolumnFilter
 

Detailed Description

The Main Class for Image Filtering.

The class can be used to apply an arbitrary filtering operation to an image. It contains all the necessary intermediate buffers, it computes extrapolated values of the "virtual" pixels outside of the image etc. Pointers to the initialized cv::FilterEngine instances are returned by various OpenCV functions, such as cv::createSeparableLinearFilter(), cv::createLinearFilter(), cv::createGaussianFilter(), cv::createDerivFilter(), cv::createBoxFilter() and cv::createMorphologyFilter().

Using the class you can process large images by parts and build complex pipelines that include filtering as some of the stages. If all you need is to apply some pre-defined filtering operation, you may use cv::filter2D(), cv::erode(), cv::dilate() etc. functions that create FilterEngine internally.

Here is the example on how to use the class to implement Laplacian operator, which is the sum of second-order derivatives. More complex variant for different types is implemented in cv::Laplacian().

void laplace_f(const Mat& src, Mat& dst)
{
CV_Assert( src.type() == CV_32F );
// make sure the destination array has the proper size and type
dst.create(src.size(), src.type());
// get the derivative and smooth kernels for d2I/dx2.
// for d2I/dy2 we could use the same kernels, just swapped
Mat kd, ks;
getSobelKernels( kd, ks, 2, 0, ksize, false, ktype );
// let's process 10 source rows at once
int DELTA = std::min(10, src.rows);
Ptr<FilterEngine> Fxx = createSeparableLinearFilter(src.type(),
dst.type(), kd, ks, Point(-1,-1), 0, borderType, borderType, Scalar() );
Ptr<FilterEngine> Fyy = createSeparableLinearFilter(src.type(),
dst.type(), ks, kd, Point(-1,-1), 0, borderType, borderType, Scalar() );
int y = Fxx->start(src), dsty = 0, dy = 0;
Fyy->start(src);
const uchar* sptr = src.data + y*src.step;
// allocate the buffers for the spatial image derivatives;
// the buffers need to have more than DELTA rows, because at the
// last iteration the output may take max(kd.rows-1,ks.rows-1)
// rows more than the input.
Mat Ixx( DELTA + kd.rows - 1, src.cols, dst.type() );
Mat Iyy( DELTA + kd.rows - 1, src.cols, dst.type() );
// inside the loop we always pass DELTA rows to the filter
// (note that the "proceed" method takes care of possibe overflow, since
// it was given the actual image height in the "start" method)
// on output we can get:
// * < DELTA rows (the initial buffer accumulation stage)
// * = DELTA rows (settled state in the middle)
// * > DELTA rows (then the input image is over, but we generate
// "virtual" rows using the border mode and filter them)
// this variable number of output rows is dy.
// dsty is the current output row.
// sptr is the pointer to the first input row in the portion to process
for( ; dsty < dst.rows; sptr += DELTA*src.step, dsty += dy )
{
Fxx->proceed( sptr, (int)src.step, DELTA, Ixx.data, (int)Ixx.step );
dy = Fyy->proceed( sptr, (int)src.step, DELTA, d2y.data, (int)Iyy.step );
if( dy > 0 )
{
Mat dstripe = dst.rowRange(dsty, dsty + dy);
add(Ixx.rowRange(0, dy), Iyy.rowRange(0, dy), dstripe);
}
}
}

Constructor & Destructor Documentation

§ FilterEngine() [1/2]

cv::FilterEngine::FilterEngine ( )

the default constructor

§ FilterEngine() [2/2]

cv::FilterEngine::FilterEngine ( const Ptr< BaseFilter > &  _filter2D,
const Ptr< BaseRowFilter > &  _rowFilter,
const Ptr< BaseColumnFilter > &  _columnFilter,
int  srcType,
int  dstType,
int  bufType,
int  _rowBorderType = BORDER_REPLICATE,
int  _columnBorderType = -1,
const Scalar _borderValue = Scalar() 
)

the full constructor. Either _filter2D or both _rowFilter and _columnFilter must be non-empty.

§ ~FilterEngine()

virtual cv::FilterEngine::~FilterEngine ( )
virtual

the destructor

Member Function Documentation

§ apply()

virtual void cv::FilterEngine::apply ( const Mat src,
Mat dst,
const Rect srcRoi = Rect(0, 0,-1,-1),
Point  dstOfs = Point(0, 0),
bool  isolated = false 
)
virtual

applies filter to the specified ROI of the image. if srcRoi=(0,0,-1,-1), the whole image is filtered.

§ init()

void cv::FilterEngine::init ( const Ptr< BaseFilter > &  _filter2D,
const Ptr< BaseRowFilter > &  _rowFilter,
const Ptr< BaseColumnFilter > &  _columnFilter,
int  srcType,
int  dstType,
int  bufType,
int  _rowBorderType = BORDER_REPLICATE,
int  _columnBorderType = -1,
const Scalar _borderValue = Scalar() 
)

reinitializes the engine. The previously assigned filters are released.

§ isSeparable()

bool cv::FilterEngine::isSeparable ( ) const
inline

returns true if the filter is separable

§ proceed()

virtual int cv::FilterEngine::proceed ( const uchar src,
int  srcStep,
int  srcCount,
uchar dst,
int  dstStep 
)
virtual

processes the next srcCount rows of the image.

§ remainingInputRows()

int cv::FilterEngine::remainingInputRows ( ) const

returns the number

§ remainingOutputRows()

int cv::FilterEngine::remainingOutputRows ( ) const

§ start() [1/2]

virtual int cv::FilterEngine::start ( Size  wholeSize,
Rect  roi,
int  maxBufRows = -1 
)
virtual

starts filtering of the specified ROI of an image of size wholeSize.

§ start() [2/2]

virtual int cv::FilterEngine::start ( const Mat src,
const Rect srcRoi = Rect(0, 0,-1,-1),
bool  isolated = false,
int  maxBufRows = -1 
)
virtual

starts filtering of the specified ROI of the specified image.

Member Data Documentation

§ anchor

Point cv::FilterEngine::anchor

§ borderElemSize

int cv::FilterEngine::borderElemSize

§ borderTab

vector<int> cv::FilterEngine::borderTab

§ bufStep

int cv::FilterEngine::bufStep

§ bufType

int cv::FilterEngine::bufType

§ columnBorderType

int cv::FilterEngine::columnBorderType

§ columnFilter

Ptr<BaseColumnFilter> cv::FilterEngine::columnFilter

§ constBorderRow

vector<uchar> cv::FilterEngine::constBorderRow

§ constBorderValue

vector<uchar> cv::FilterEngine::constBorderValue

§ dstType

int cv::FilterEngine::dstType

§ dstY

int cv::FilterEngine::dstY

§ dx1

int cv::FilterEngine::dx1

§ dx2

int cv::FilterEngine::dx2

§ endY

int cv::FilterEngine::endY

§ filter2D

Ptr<BaseFilter> cv::FilterEngine::filter2D

§ ksize

Size cv::FilterEngine::ksize

§ maxWidth

int cv::FilterEngine::maxWidth

§ ringBuf

vector<uchar> cv::FilterEngine::ringBuf

§ roi

Rect cv::FilterEngine::roi

§ rowBorderType

int cv::FilterEngine::rowBorderType

§ rowCount

int cv::FilterEngine::rowCount

§ rowFilter

Ptr<BaseRowFilter> cv::FilterEngine::rowFilter

§ rows

vector<uchar*> cv::FilterEngine::rows

§ srcRow

vector<uchar> cv::FilterEngine::srcRow

§ srcType

int cv::FilterEngine::srcType

§ startY

int cv::FilterEngine::startY

§ startY0

int cv::FilterEngine::startY0

§ wholeSize

Size cv::FilterEngine::wholeSize

The documentation for this class was generated from the following file: