
图像金字塔概念 – 高斯金字塔
高斯金子塔是从底向上,逐层降采样得到。
降采样之后图像大小是原图像MxN的M/2 x N/2 ,就是对原图像删除偶数行与列,即得到降采样之后上一层的图片。
高斯金子塔的生成过程分为两步:
- 对当前层进行高斯模糊
- 删除当前层的偶数行与列
即可得到上一层的图像,这样上一层跟下一层相比,都只有它的1/4大小。
高斯不同(Difference of Gaussian-DOG)
定义:就是把同一张图像在不同的参数下做高斯模糊之后的结果相减,得到的输出图像。称为高斯不同(DOG)
高斯不同是图像的内在特征,在灰度图像增强、角点检测中经常用到。
上采样(cv::pyrUp) – zoom in 放大
降采样 (cv::pyrDown) – zoom out 缩小
pyrUp(Mat src, Mat dst, Size(src.cols2, src.rows2))
生成的图像是原图在宽与高各放大两倍
pyrDown(Mat src, Mat dst, Size(src.cols/2, src.rows/2))
生成的图像是原图在宽与高各缩小1/2
#include "pch.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include "math.h"
using namespace cv;
int main(int agrc, char** argv) {
Mat src, dst;
src = imread("D:/11.jpg");
if (!src.data) {
printf("could not load image...");
return -1;
}
char INPUT_WIN[] = "input image";
char OUTPUT_WIN[] = "sample up";
namedWindow(INPUT_WIN, CV_WINDOW_AUTOSIZE);
namedWindow(OUTPUT_WIN, CV_WINDOW_AUTOSIZE);
imshow(INPUT_WIN, src);
// 上采样
pyrUp(src, dst, Size(src.cols*2, src.rows * 2));
imshow(OUTPUT_WIN, dst);
// 降采样
Mat s_down;
pyrDown(src, s_down, Size(src.cols / 2, src.rows / 2));
imshow("sample down", s_down);
// DOG
//两次高斯结果相减,得到高斯去除掉的部分
Mat gray_src, g1, g2, dogImg;
cvtColor(src, gray_src, CV_BGR2GRAY);//灰度图
GaussianBlur(gray_src, g1, Size(5, 5), 0, 0);//高斯滤波,去除噪声
GaussianBlur(g1, g2, Size(5, 5), 0, 0);//高斯滤波,去除噪声
subtract(g1, g2, dogImg, Mat());//相减
// 归一化显示 内容颜色太浅需要重新规定范围
normalize(dogImg, dogImg, 255, 0, NORM_MINMAX);//规定取值范围
imshow("DOG Image", dogImg);
imshow("result g1", g1);
imshow("result g2", g2);
waitKey(0);
return 0;
}


网友评论