Opencv3 C++ VS2017 学习笔记 10 图像金字塔-上采样和降采样

  • 图像金字塔
    • 调整图像大小,最常见的就是放大(zoom in)和缩小(zoom out)
    • 图像的金字塔是一系列以金字塔形状排列的分辨率逐步降低的图像集合。金字塔的底部是待处理图像的高分辨率表示,而顶部是低分辨率的近似
  • 上采样和下采样
    • 采样的点越多图像越清晰
    • 上采样是扩大分辨率
      • API
        • pyrUp(src0, dst, Size(src0.cols*2, src0.rows*2));
    • 下采样是降低分辨率
      • API
        • pyrDown(src0, bin, Size(src0.cols / 2, src0.rows / 2));
  • 图像金字塔分类:Gaussian pyramid&Laplacian pyramid
    • Gaussian pyramid
      • 主要是下采样,即爬金字塔
      • 步骤
      1. 对当前层进行GaussianBlur高斯模糊,即Gaussian内核卷积
      2. 删除当前层的偶数行列
    • Laplacian pyramid
      • 主要是上采样,即下金字塔
  • Difference of Gaussian DOG
    • 把同一张图的不同GaussianBlur参数所得到的两张图相减,得到输出图像为DOG
    • 理论
      • 差分金字塔,DOG(Difference of Gaussian)金字塔是在高斯金字塔的基础上构建起来的,其实生成高斯金字塔的目的就是为了构建DOG金字塔。DOG金字塔的第1组第1层是由高斯金字塔的第1组第2层减第1组第1层得到的。以此类推,逐组逐层生成每一个差分图像,所有差分图像构成差分金字塔。概括为DOG金字塔的第0组第l层图像是由高斯金字塔的第0组第i+1层减第0组第i层得到的。
    • 算法实现
      •     GaussianBlur(gray_src, g1, Size(3, 3), 0, 0);
            GaussianBlur(g1, g2, Size(5, 5), 0, 0);
            subtract(g1, g2, dogImg);
      • subtract()像素级减法操作
#include "pch.h"
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

using namespace std;
using namespace cv;

Mat src0, gray, bin, dst;
int main(int argc, char ** argv)
{
	src0 = imread("C:\\Users\\xujin\\Desktop\\test1.JPG");
	if (!src0.data)
	{
		cout << "no image";
		return -1;
	}
	namedWindow("src0_image", WINDOW_AUTOSIZE);
	imshow("src0_image", src0);
	//上采样
	pyrUp(src0, dst, Size(src0.cols*2, src0.rows*2));
	namedWindow("dst_image", WINDOW_AUTOSIZE);
	imshow("dst_image", dst);
	//降采样
	pyrDown(src0, bin, Size(src0.cols / 2, src0.rows / 2));
	namedWindow("bin_image", WINDOW_AUTOSIZE);
	imshow("bin_image", dst);
	//DOG 高斯不同
	Mat gray_src, g1, g2, dogImg;
	cvtColor(src0, gray_src, CV_BGR2GRAY);
	GaussianBlur(gray_src, g1, Size(3, 3), 0, 0);
	GaussianBlur(g1, g2, Size(5, 5), 0, 0);
	subtract(g1, g2, dogImg);
	namedWindow("dog_image", WINDOW_AUTOSIZE);
	//归一化显示
	//normalize(dogImg, dogImg, 255, NORM_MINMAX);
	imshow("dog_image", dogImg);

	waitKey(0);
	return 0;
}

文章参考: https://blog.csdn.net/zhu_hongji/article/details/81536820

猜你喜欢

转载自blog.csdn.net/Mrsherlock_/article/details/104518395
今日推荐