cv::FilterEngine Class Reference

#include <imgproc.hpp>

List of all members.

Public Member Functions

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.
 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 ()
 the default constructor
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.
bool isSeparable () const
 returns true if the filter is separable
virtual int proceed (const uchar *src, int srcStep, int srcCount, uchar *dst, int dstStep)
 processes the next srcCount rows of the image.
int remainingInputRows () const
 returns the number
int remainingOutputRows () const
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.
virtual int start (Size wholeSize, Rect roi, int maxBufRows=-1)
 starts filtering of the specified ROI of an image of size wholeSize.
virtual ~FilterEngine ()
 the destructor

Public Attributes

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

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

cv::FilterEngine::FilterEngine (  ) 

the default constructor

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.

virtual cv::FilterEngine::~FilterEngine (  )  [virtual]

the destructor


Member Function Documentation

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.

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.

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

returns true if the filter is separable

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.

int cv::FilterEngine::remainingInputRows (  )  const

returns the number

int cv::FilterEngine::remainingOutputRows (  )  const
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.

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.


Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Thu Dec 23 11:40:55 2010 for opencv by  doxygen 1.6.3