boxFilter 滤波器实现

cv::Ptr<cv::FilterEngine> cv::createBoxFilter( int srcType, 
    int dstType, Size ksize,Point anchor, 
    bool normalize, int borderType )
{
    // 基础参数设置 图像深度
    int sdepth = CV_MAT_DEPTH(srcType);
    int cn = CV_MAT_CN(srcType), sumType = CV_64F;
    if( sdepth <= CV_32S && (!normalize ||
        ksize.width*ksize.height <= (sdepth == CV_8U ? (1<<23) :
        sdepth == CV_16U ? (1 << 15) : (1 << 16))) )
        sumType = CV_32S;
    sumType = CV_MAKETYPE( sumType, cn );
    // 获取滤波类中行滤波器信息
    Ptr<BaseRowFilter> rowFilter = getRowSumFilter(srcType,
     sumType, ksize.width, anchor.x );
    // 获取滤波类中列滤波器信息
    Ptr<BaseColumnFilter> columnFilter = getColumnSumFilter(sumType,
        dstType, ksize.height, anchor.y, normalize ? 
        1./(ksize.width*ksize.height) : 1);
    // 返回滤波器基类生成
    return Ptr<FilterEngine>(new FilterEngine(Ptr<BaseFilter>(0),
       rowFilter, columnFilter,
       srcType, dstType, sumType, borderType ));
}
// 盒子滤波器实现
void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth,
                Size ksize, Point anchor,
                bool normalize, int borderType )
{
    // 获取矩阵相关信息
    Mat src = _src.getMat();
    int sdepth = src.depth(), cn = src.channels();
    if( ddepth < 0 )
        ddepth = sdepth;
    _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) );
    Mat dst = _dst.getMat();
    // 边界因子设定
    if( borderType != BORDER_CONSTANT && normalize )
    {
        if( src.rows == 1 )
            ksize.height = 1;
        if( src.cols == 1 )
            ksize.width = 1;
    }
    // 盒子滤波基类生成
    Ptr<FilterEngine> f = createBoxFilter( src.type(), dst.type(),
                        ksize, anchor, normalize, borderType );
    // apply方法实现相关滤波操作
    f->apply( src, dst );

}

转载:http://blog.csdn.net/zhuwei1988


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值