标签:高斯金字塔 拉普拉斯金字塔 opencv 上采样 下采样
收入囊中
对一张图像不断的模糊之后向下采样,得到不同分辨率的图像,同时每次得到的新的图像宽与高是原来图像的1/2, 最常见就是基于高斯的模糊之后采样,得到的
一系列图像称为高斯金字塔。
原图来自http://blog.csdn.net/jia20003/article/details/9116931
| 1 | 4 | 6 | 4 | 1 |
| 4 | 16 | 24 | 16 | 4 |
| 6 | 24 | 36 | 24 | 6 |
| 4 | 16 | 24 | 16 | 4 |
| 1 | 4 | 6 | 4 | 1 |
|
|
|
内部实现是不断call pyrDown()
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
Mat src, dst, tmp;
const char* window_name = "Pyramids Demo";
int main(int argc,char **argv)
{
printf( "\n Zoom In-Out demo \n " );
printf( "------------------ \n" );
printf( " * [u] -> Zoom in \n" );
printf( " * [d] -> Zoom out \n" );
printf( " * [ESC] -> Close program \n \n" );
src = imread(argv[1]);
if( !src.data )
{ printf(" No data! -- Exiting the program \n");
return -1; }
tmp = src;
dst = tmp;
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
imshow( window_name, dst );
for(;;)
{
int c;
c = waitKey(10);
if( (char)c == 27 )
{ break; }
if( (char)c == ‘u‘ )
{ pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
printf( "** Zoom In: Image x 2 \n" );
}
else if( (char)c == ‘d‘ )
{ pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) );
printf( "** Zoom Out: Image / 2 \n" );
}
imshow( window_name, dst );
tmp = dst;
}
return 0;
}#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <sstream>
using namespace cv;
using namespace std;
Mat src,tmp;
vector<Mat>gaussPyrs;
vector<Mat>DOG;
int maxLevel = 3;
int main(int argc,char **argv)
{
src = imread(argv[1]);
if( !src.data ){
printf(" No data! -- Exiting the program \n");
return -1;
}
buildPyramid(src, gaussPyrs, maxLevel);
for(int i = 0;i < maxLevel;i++){
Size ss;
pyrUp( gaussPyrs[i+1], tmp, ss);
Mat dst = gaussPyrs[i] - tmp;
DOG.push_back(dst);
}
for(int i = 0;i < maxLevel;i++){
stringstream ss;
ss << i;
string s;
ss >> s;
namedWindow( s, CV_WINDOW_AUTOSIZE );
imshow( s, DOG[i] );
}
waitKey(0);
return 0;
}
OpenCV2马拉松第7圈——图像金字塔,布布扣,bubuko.com
标签:高斯金字塔 拉普拉斯金字塔 opencv 上采样 下采样
原文地址:http://blog.csdn.net/abcd1992719g/article/details/24849585