OpenCV learning basic image operations (eight): image upsampling and downsampling

Image pyramid

In image processing, the image size is often adjusted. The most common ones are zoom in and zoom out. An image pyramid is composed of a series of images, with the largest size at the bottom and the smallest size at the top. It looks like a pyramid.

Gaussian pyramid

  • The Gaussian pyramid is obtained by down-sampling from the bottom to the top.
  • After downsampling, the image size is changed from MxN to M/2xN/2, which means that even rows and columns of the original image are deleted to obtain the picture of the upper layer.
  • The generation process of Gaussian pyramid is divided into two steps:
    • Gaussian blur on the current layer
    • Delete the even rows and columns of the current layer

Different Gaussian (DOG)

  • The output image is obtained by subtracting the results of an image after Gaussian blurring under different parameters.
  • Gaussian difference is the inherent feature of the image, which is often used in gray-scale image enhancement and corner detection.

Laplace pyramid

  • It is composed of different Gaussian layers.
  • Often used in image fusion to restore large-scale images from small-scale images

API introduction

Upsampling and downsampling

void pyrUp(InputArray src,//输入图像,即源图像,填Mat类的对象即可
           OutputArraydst,//输出图像,和源图片有一样的尺寸和类型。
           const Size& dstsize=Size(),// 输出图像的大小;有默认值Size(),即默认情况下由Size(src.cols*2,src.rows*2)来进行计算
           int borderType=BORDER_DEFAULT )   //边界模式 默认deaft就好



void pyrDown(InputArray src,//输入图像,即源图像,填Mat类的对象即可
           OutputArraydst,//输出图像,和源图片有一样的尺寸和类型。
           const Size& dstsize=Size(),// 输出图像的大小
           int borderType=BORDER_DEFAULT )   //边界模式 默认deaft就好

Matrix normalization


normalize(src, det, 255, 0, NORM_MINMAX);	
//src输入;dst输出,支持原地运算;alpha:range normalization模式的最小值;beta:range normalization模式的最大值,不用于norm normalization(范数归一化)模式。	
//normType	
//归一化的类型,可以有以下的取值:	
//NORM_MINMAX : 数组的数值被平移或缩放到一个指定的范围,线性归一化,一般较常用。	
//NORM_INF : 此类型的定义没有查到,根据OpenCV 1的对应项,可能是归一化数组的C - 范数(绝对值的最大值)	
//NORM_L1 : 归一化数组的L1 - 范数(绝对值的和)	
//NORM_L2 : 归一化数组的(欧几里德)L2 - 范数

Code and practice

#include <iostream>
#include <math.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
	//src = imread("src.jpg");
	Mat src = imread("cat.png");
	if (!src.data)
	{
		cout << "cannot open image" << endl;
		return -1;
	}
	namedWindow("input image", WINDOW_AUTOSIZE);
	imshow("input image", src);

	Mat up_out(src.size(),src.type());
	Mat down_out(src.size(), src.type());

	pyrDown(src, down_out);
	pyrUp(src,up_out);
	imshow("Down", down_out);
	imshow("Up", up_out);


	//高斯不同DOG(different of gaussian)	
        //就是把同一张图像在不同的参数下做高斯模糊之后的结果相减,得到的输出图像;
        //高斯不同是图像的内在特征,在灰度图像增强、角点检测中经常用到。
	Mat gray_src, dst2, dst3, dog_Image;	

	cvtColor(src, gray_src, COLOR_BGR2GRAY);	

	GaussianBlur(gray_src, dst2, Size(3, 3), 0, 0);	
	GaussianBlur(dst2, dst3, Size(3, 3), 0, 0);	
	subtract(dst2, dst3, dog_Image);

	//归一化显示	
	normalize(dog_Image, dog_Image, 255, 0, NORM_MINMAX);	
	

	imshow("DOG", dog_Image);
	
	waitKey(0);
	return 0;
}

Picture pyramid

DOG

 

Guess you like

Origin blog.csdn.net/fan1102958151/article/details/107096978