opencv 学习笔记(十三) 图像金字塔

opencv 学习笔记(十三) 图像金字塔,第1张

图像金字塔
  • 前言

  • 一、高斯金字塔

    • 1.pyrDown
    • 2.向下采样
    • 3pyrUp
    • 4向上采样

  • 二、拉普拉斯金字塔

    • 1.Laplacian
    • 2.代码


前言

图像金字塔是以多个分辨率来表示图像的一种有效且概念简单的结构。


图像金字塔可以通过梯次向下采样获得,直至达到某个终止条件才停止采样,在向下采样中,层级越高,则图像越小,分辨率越低。


图像金字塔分为两种,一种是高斯金字塔,一种是拉普拉斯金字塔。




一、高斯金字塔

高斯金字塔用来向下采样图片,在class="superseo">opencv中,向下采样使用的函数为pyrDown

1.pyrDown
void pyrDown(InputArray src, OutputArray dst,
		const Size& dstsize = Size(), int borderType = BORDER_DEFAULT);

	src 输入
	dst 输出
	dstsize 输出图像的大小 默认1/4
	borderType 边界像素模式
2.向下采样
#include
#include
using namespace std;
using namespace cv;


int main()
{
	Mat img1, img2;
	
	img1 = imread("猫1.jpg");
	
	imshow("原图", img1);
	
	pyrDown(img1, img2);
	
	imshow("效果图", img2);
	
	waitKey(0);
}

效果图

3pyrUp
void pyrUp(InputArray src, OutputArray dst,
		const Size& dstsize = Size(), int borderType = BORDER_DEFAULT);

	src 输入
	dst 输出
	dstsize 输出图像的大小 默认  4
	borderType 边界像素模式
4向上采样
int main()
{
	Mat img1, img2;
	img1 = imread("猫1.jpg");
	imshow("原图", img1);
	pyrUp(img1, img2);
	imshow("效果图", img2);
	waitKey(0);
}

效果如下:


二、拉普拉斯金字塔

拉普拉斯金字塔用来从金字塔底层图像重建上层未采样图像,在数字图像处理中就是预测残差,可以对图像进行最大程度的还原,配合高斯金字塔一块使用

1.Laplacian
void Laplacian(InputArray src, OutputArray dst, int ddepth,
		int ksize = 1, double scale = 1, double delta = 0,
		int borderType = BORDER_DEFAULT);
	src 输入图像
	dst 输出图像
	ddepth 目标图像深度
	Ksize 孔径大小 正奇数
	scale 缩放因子
	delta 将结果存储到dst之前添加到结果中的可选增量
	bordertype 边界像素模式
2.代码
int main()
{
	Mat img1, img2, img3, img4;
	
	img1 = imread("img.jpg");
	
	imshow("原图", img1);
	
	GaussianBlur(img1, img2, Size(3, 3), 3, 3);
	
	cvtColor(img2, img3, COLOR_BGR2GRAY);
	
	Laplacian(img3, img4, CV_64F, 3);
	
	convertScaleAbs(img4, img4);
	
	threshold(img4, img4, 2, 255, THRESH_OTSU);
	
	imshow("Laplacian", img4);
	
	waitKey(0);
}

效果如下:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/569554.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存