文章目录

一、函数介绍

算法详情见:图像金字塔 官方给出了好的示例。

这两个函数参数类似,输入矩阵,输出矩阵,采样后图像大小,边界处理


void pyrDown(
InputArray src,
OutputArray dst,
const Size& dstsize = Size(),
int borderType = BORDER_DEFAULT );
void pyrUp(
InputArray src,
OutputArray dst,
const Size& dstsize = Size(),
int borderType = BORDER_DEFAULT );



二、演示

头文件 quick_opencv.h:声明类与公共函数

#pragma once
#include <opencv2\opencv.hpp>
using namespace cv;

class QuickDemo {
public:
...
void DoG_Demo(Mat& image);
};

主函数调用该类的公共成员函数

#include <opencv2\opencv.hpp>
#include <quick_opencv.h>
#include <iostream>
using namespace cv;


int main(int argc, char** argv) {
Mat src = imread("D:\\Desktop\\pandas_small22.png");
if (src.empty()) {
printf("Could not load images...\n");
return -1;
}
namedWindow("input", WINDOW_NORMAL);
imshow("input", src);

QuickDemo qk;
qk.DoG_Demo(src);
waitKey(0);
destroyAllWindows();
return 0;
}

源文件 quick_demo.cpp:实现类与公共函数

void QuickDemo::DoG_Demo(Mat& image) {
int height = image.rows;
int width = image.cols;
Mat down_dst, up_dst;

pyrDown(image, down_dst, Size(width / 2, height / 2));
pyrUp(image, up_dst, Size(width * 2, height * 2));
imshow("down_dst", down_dst);
imshow("up_dst", up_dst);

Mat gray_img, g1, g2, dog_dst, dog_dst2;
cvtColor(image, gray_img, COLOR_BGR2GRAY);


GaussianBlur(gray_img, g1, Size(3, 3), 0, 0);
GaussianBlur(g1, g2, Size(3, 3), 0, 0);
subtract(g1, g2, dog_dst);
normalize(dog_dst, dog_dst, 255, 0, NORM_MINMAX);

imshow("gray_img", gray_img);
imshow("g1", g1);
imshow("g2", g2);
imshow("dog_dst", dog_dst);

applyColorMap(dog_dst, dog_dst2, 2);
imshow("dog_dst2", dog_dst2);
}

演示效果:

OpenCV + CPP 系列(十七)图像金字塔(上采样 | 降采样)与 高斯差分_c++

OpenCV + CPP 系列(十七)图像金字塔(上采样 | 降采样)与 高斯差分_头文件_02

OpenCV + CPP 系列(十七)图像金字塔(上采样 | 降采样)与 高斯差分_ios_03