OpenCV:等间隔采样和局部均值的图像缩小

博客围绕OpenCV展开,涉及等采样采样和局部均值的缩小操作,这些操作属于图像处理领域,在信息技术中可用于图像的预处理等工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void scalePartAverage(const Mat &src, Mat &dst, double xRatio, double yRatio)
{
    int rows = static_cast<int>(src.rows * xRatio);
    int cols = static_cast<int>(src.cols * yRatio);

    dst.create(rows, cols, src.type());

    int lastRow = 0;
    int lastCol = 0;

    Vec3b *p;
    for (int i = 0; i < rows; i++) {
        p = dst.ptr<Vec3b>(i);
        int row = static_cast<int>((i + 1) / xRatio + 0.5) - 1;

        for (int j = 0; j < cols; j++) {
            int col = static_cast<int>((j + 1) / yRatio + 0.5) - 1;

            Vec3b pix;
            average(src, Point_<int>(lastRow, lastCol), Point_<int>(row, col), pix);
            p[j] = pix;

            lastCol = col + 1; //下一个子块左上角的列坐标,行坐标不变
        }
        lastCol = 0; //子块的左上角列坐标,从0开始
        lastRow = row + 1; //子块的左上角行坐标
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值