计算机视觉攻略 图像滤波笔记2 (用滤波器进行缩减像素采样)

用滤波器进行缩减像素采样

需要调整图像精度(重新采样)的情况屡见不鲜,降低图像精度的过程称为缩减像素采样,提升图像精度的过程称为提升像素采样
为避免混叠现象的发生,在缩减图像之前必须进行低通滤波。低通滤波的作用是消除在缩减后的图像中无法表示的高频部分。这一现象称为奈奎斯特-香农定理,它表明如果
把图像缩小一半,那么其可见的频率带宽也将减少一半。
OpenCV中利用该原理的函数

void pyrDown(InputArray src, OutputArray dst, const Size_<int> &dstsize = Size(), int borderType = BORDER_DEFAULT)

在这里插入图片描述

程序代码(缩减像素采样)
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;

int main(int argc, char** argv) {
    if(argc != 2)
    {
        cerr << "please enter the right numbers of images" << endl;
        return -1;
    }
    cv::Mat image = cv::imread(argv[1]);
    if(image.empty())
    {
        cerr << "don`t get the data of the argv[1]" << endl;
        return -1;
    }
    cv::Mat reduceImage;
    const int64 start = cv::getTickCount();
    cv::pyrDown(image,reduceImage);
    double duration = (cv::getTickCount() - start) / cv::getTickFrequency();
    cout << "function uses time: " << duration << endl;
    cv::imshow("The original image", image);
    cv::imshow("The procesed image", reduceImage);
    cv::waitKey(0);
    return 0;
}

在这里插入图片描述

void pyrUp(InputArray src, OutputArray dst, const Size_<int> &dstsize = Size(), int borderType = BORDER_DEFAULT)

在这里插入图片描述

程序代码(提升像素采样)
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;

int main(int argc, char** argv) {
    if(argc != 2)
    {
        cerr << "please enter the right numbers of images" << endl;
        return -1;
    }
    cv::Mat image = cv::imread(argv[1]);
    if(image.empty())
    {
        cerr << "don`t get the data of the argv[1]" << endl;
        return -1;
    }
    cv::Mat reduceImage;
    const int64 start = cv::getTickCount();
    cv::pyrUp(image,reduceImage);
    double duration = (cv::getTickCount() - start) / cv::getTickFrequency();
    cout << "function uses time: " << duration << endl;
    cv::imshow("The original image", image);
    cv::imshow("The procesed image", reduceImage);
    cv::waitKey(0);
    return 0;
}


在这里插入图片描述
以上两个函数可以构建图像金字塔

void resize(InputArray src, OutputArray dst, Size_<int> dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR)

在这里插入图片描述

示例程序
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;

int main(int argc, char** argv) {
    if(argc != 2)
    {
        cerr << "please enter the right numbers of images" << endl;
        return -1;
    }
    cv::Mat image = cv::imread(argv[1]);
    if(image.empty())
    {
        cerr << "don`t get the data of the argv[1]" << endl;
        return -1;
    }
    cv::Mat resizedImage;
    const int64 start = cv::getTickCount();
//    cv::resize(image, resizedImage,cv::Size(image.cols*2, image.rows*2));
    cv::resize(image, resizedImage, cv::Size(), 1.0/4.0, 1.0/4.0);
    double duration = (cv::getTickCount() - start) / cv::getTickFrequency();
    cout << "function uses time: " << duration << endl;
    cv::imshow("The original image", image);
    cv::imshow("The procesced image", resizedImage);
    cv::waitKey(0);
    return 0;
}


在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值