学习c++版opencv3.4之14-图像金字塔
图像金字塔,上采样与将采样。
上采样与下采样过程中图像的尺寸会发生变化,与图像普通的resize改变尺寸不同的是,上采样下采样这种变化保留了不同尺度下图像的特征。一个图像金字塔由一系列不同尺寸图像组成,最低下的尺寸最大,最上方的尺寸最小,从空间上由上向下看就像一个金字塔。
图像金字塔包括两种:高斯金字塔,主要进行降采样;拉普拉斯金字塔,根据它的上层降采样的图像进行重建一张图像(上采样)。
高斯金字塔:从底向上逐渐采样得到;降采样之后图像尺寸变为原来的1/2(首先对当前图像进行高斯模糊,然后删除当前图像偶数行与列,得到降采样的图像)。
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace std;
using namespace cv;
Mat src ,gray_src, dst;
int main(){
src = imread("/Users/ming/Documents/test.jpg");
if (!src.data){
printf("cannot load image ...");
return -1;
}
namedWindow("src img", CV_WINDOW_AUTOSIZE);
imshow("src img", src);
// pyrUp(src, dst); //上采样
// pyrDown(src, dst); //下采样
/* 高斯不同 DOG */
cvtColor(src, gray_src, CV_BGR2GRAY);
Mat g1, g2, dogImg;
GaussianBlur(gray_src, g1, Size(3,3), 0);
GaussianBlur(g1, g2, Size(3,3), 0);
subtract(g1, g2, dogImg);
imshow("difference of gaussian(DOG)", dogImg);
waitKey(0);
return 0;
}