Opencv3 C++ VS2017 Study Notes 10 Image Pyramid-Upsampling and Downsampling

  • Image pyramid
    • To adjust the image size, the most common ones are zoom in and zoom out
    • The image pyramid is a series of image collections arranged in a pyramid shape with gradually reduced resolution. The bottom of the pyramid is a high-resolution representation of the image to be processed, while the top is a low-resolution approximation
  • Upsampling and downsampling
    • The more points sampled, the clearer the image
    • Upsampling is to expand the resolution
      • API
        • pyrUp(src0, dst, Size(src0.cols*2, src0.rows*2));
    • Downsampling is to reduce the resolution
      • API
        • pyrDown(src0, bin, Size(src0.cols / 2, src0.rows / 2));
  • Image pyramid classification: Gaussian pyramid&Laplacian pyramid
    • Gaussian pyramid
      • Mainly downsampling, that is, climbing the pyramid
      • step
      1. Perform Gaussian Blur Gaussian blur on the current layer, that is, Gaussian kernel convolution
      2. Delete the even rows and columns of the current layer
    • Laplacian pyramid
      • Mainly upsampling, that is, the lower pyramid
  • Difference of Gaussian DOG
    • Subtract the two images obtained by different GaussianBlur parameters of the same image, and the output image is DOG
    • theory
      • Differential pyramid, DOG (Difference of Gaussian) pyramid is built on the basis of Gaussian pyramid. In fact, the purpose of generating Gaussian pyramid is to build DOG pyramid. The first layer of the first group of the DOG pyramid is obtained by subtracting the first layer of the first group from the second layer of the first group of the Gaussian pyramid. By analogy, each differential image is generated group by layer, and all differential images form a differential pyramid. The image of the first layer of the 0th group summed up as the DOG pyramid is obtained by subtracting the i+1th layer of the 0th group from the 0th group i+1 of the Gaussian pyramid.
    • Algorithm implementation
      •     GaussianBlur(gray_src, g1, Size(3, 3), 0, 0);
            GaussianBlur(g1, g2, Size(5, 5), 0, 0);
            subtract(g1, g2, dogImg);
      • subtract() pixel-level subtraction operation
#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;
}

Article reference:  https://blog.csdn.net/zhu_hongji/article/details/81536820

Guess you like

Origin blog.csdn.net/Mrsherlock_/article/details/104518395