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


前言

图像金字塔是以多个分辨率来表示图像的一种有效且概念简单的结构。图像金字塔可以通过梯次向下采样获得,直至达到某个终止条件才停止采样,在向下采样中,层级越高,则图像越小,分辨率越低。图像金字塔分为两种,一种是高斯金字塔,一种是拉普拉斯金字塔。


一、高斯金字塔

高斯金字塔用来向下采样图片,在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<iostream>
#include<opencv.hpp>
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);
}

效果如下:
在这里插入图片描述

  • 13
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浅念念52

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值