图像金字塔与高斯不同(DOG)
1、图像金字塔
1.1 图像金字塔上采样
拉普拉斯金字塔:图像的上采样
图像的宽高会增加到原来的2倍。
api如下:
pyrUp(src, dst, Size(src.cols * 2, src.rows * 2));
1.2图像的下采样
高斯金字塔:图像的降采样(下采样)
图像的宽高减少到原图的1/2倍。
api如下:
pyrDown(src, dst, Size(src.cols /2, src.rows /2));
1.2高斯不同(DOG)
高斯不同的意思就是对于同一张图像,采用不同的参数时,得到不同的灰度图进行相减,结果图像就是高斯不同。主要应用于灰度图的增强,以及角点检测。
步骤:
- 1、进行灰度转换
- 2、高斯模糊g1
- 3、高斯模糊g2
- 4 、相减:g1-g2
- 5、归一化:最大最小值归一化
2、代码实现
#include <opencv2/opecnv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img = imread("G:/testpic/img.png");
if (img.empty())
{
printf("cannot load the image");
return -1;
}
char input[] = "input";
namedWindow(input, WINDOW_AUTOSIZE);
imshow(input, img);
//上采样
pyrUp(img, imgup, Size(img.cols*2, img.rows*2));
imshow("Upimg", imgup);
//下采样
pyrDown(img, imgDown, Size(img.cols/2, img.rows/2));
imshow("Downimg", imgDown);
//高斯不同
Mat gray, dst1, dst2, result;
cvtColor(img, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, dst1, Size(5,5), 0, 0);
GaussianBlur(dst1, dst2, Size(5,5), 0, 0);
subtract(dst1, dst2, result, Mat());
//归一化
normalize(result, result, 0, 255, NORM_MINMAX);
imshow(output, result);
waitKey(0);
return 0;
}
原图
高斯不同: