Image Pyramid
今天我们介绍图像处理邻域中比较常用的一种方法,image pyramid, 也叫图像金字塔。就是将图像进行一层一层的下采样,图像金字塔是为了构建图像的多尺度,让模型能够更好的适应图像的尺度变化,图像金字塔可以广泛应用于图像识别,目标检测,还有光流配准,块匹配都能看到它的身影。图像金字塔主要有两种,一种是高斯金字塔,gaussian pyramid,另外一种是拉普拉斯金字塔,Laplacian Pyramids。
Gk" role="presentation" style="position: relative;">GkGk 表示的每一层金字塔中的图像,F" role="presentation" style="position: relative;">FF 表示高斯卷积核,∗" role="presentation" style="position: relative;">∗∗ 表示卷积操作,Down" role="presentation" style="position: relative;">DownDown 表示下采样,上面的表达式,就可以构建一个图像金字塔。这个在 Open-CV 中有现成的函数,下面给出一段代码,看看高斯金字塔的构建:
import numpy as np
import matplotlib.pyplot as plt
A = cv2.imread('D:/Python_Code/Test_img/2.jpg')
row, col, dpt = A.shape
pyr_level = 4
# generate Gaussian pyramid for A
G = A.copy()
gpA = [G]
for i in range(pyr_level):
G = cv2.pyrDown(G)
gpA.append(G)
G = np.zeros([row, col, dpt], dtype='uint8')
rowX2 = row // 2
colX2 = col // 2
G[:rowX2, :colX2, :] = gpA[1]
rowX4 = rowX2 // 2
colX4 = colX2 // 2
G[rowX2:rowX2+rowX4, colX2:colX2+colX4, :] = gpA[2]
G[:rowX4, colX2:colX2+colX4, :] = gpA[2]
rowX8 = rowX4 // 2
colX8 = colX4 // 2
G[rowX2+rowX4:rowX2+rowX4+rowX8, colX2+colX4:colX2+colX4+colX8, :] = gpA[3]
G[ :rowX8, colX2+colX4:colX2+colX4+colX8, :] = gpA[3]
cv2.imshow("gau_pyr", G)
下面给出一个效果图:
下面看看,拉普拉斯金字塔,拉普拉斯金字塔其实是根据高斯金字塔计算得来的:
利用拉普拉斯金字塔,可以实现图像的重建,根据上面的表达式,我们可以得到:
也就是说,把拉普拉斯金字塔层层上采样,再累加,就可以重建出最初的图像。下面给出一段代码:
import cv2
import numpy as np
A = cv2.imread('D:/Python_Code/Test_img/2.jpg')
pyr_level = 4
# generate Gaussian pyramid for A
G = A.copy()
gpA = [G]
for i in range(pyr_level):
G = cv2.pyrDown(G)
gpA.append(G)
# generate Laplacian Pyramid for A
lpA = [gpA[pyr_level -1 ]]
for i in range(pyr_level - 1,0,-1):
GE = cv2.pyrUp(gpA[i])
L = cv2.subtract(gpA[i-1],GE)
lpA.append(L)
# Now add left and right halves of images in each level
LS = []
for la,lb in zip(lpA,lpB):
rows,cols,dpt = la.shape
ls = la
LS.append(ls)
# now reconstruct
ls_ = LS[0]
for i in range(1,pyr_level):
ls_ = cv2.pyrUp(ls_)
ls_ = cv2.add(ls_, LS[i])
cv2.imwrite('Pyramid_blending2.jpg',ls_)
原图:
重建后的图:
Image Pyramid的更多相关文章
- CF 676B Pyramid of Glasses[模拟]
B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Spatial pyramid pooling (SPP)-net (空间金字塔池化)笔记(转)
在学习r-cnn系列时,一直看到SPP-net的身影,许多有疑问的地方在这篇论文里找到了答案. 论文:Spatial Pyramid Pooling in Deep Convolutional Net ...
- 论文笔记之:Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks
Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks NIPS 2015 摘要:本文提出一种 ...
- codeforces 676B B. Pyramid of Glasses(模拟)
题目链接: B. Pyramid of Glasses time limit per test 1 second memory limit per test 256 megabytes input s ...
- hdu 5432 Pyramid Split 二分
Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...
- Spatial Pyramid Matching 小结
Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...
- pyramid的第一个项目
1,安装pyramid --在次之前最好先安装python virtualenv --python virtualenv ---激活方式pyenv activate pip install pyram ...
- OpenGL蓝宝书第五章代码勘误以及惯性坐标系去解释模型变换:Pyramid.cpp
假设你也发现依照教程代码完毕贴图时,你会底面的坐标和寻常顶点坐标正负相反,比方-1.0f, -1.0f, -1.0f这个顶点相应的却是世界坐标中1.0f,-1.0f,1.0f 问题到底出如今哪里? 原 ...
- Golden Pyramid
Golden Pyramid Our Robo-Trio need to train for future journeys and treasure hunts. Stephan has built ...
- hdu 5432 Pyramid Split(二分搜索)
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
随机推荐
- uwsgi+nginx项目上线
一.基础环境配置 1.Linux安装配置 1.设置IP地址 [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 ...
- Django基础(三)_分页器、COOKIE与SESSION、FORM表单
分页器(paginator) 分页器的使用 >>> from django.core.paginator import Paginator >>> objects ...
- substring splice
返回start到end之前 不包括end stringObject.substring(start,end) (不接受负数) stringObject.slice(start,end) start起始 ...
- 每天一个Linux命令(46)ifconfig命令
在windows系统中,ipconfig命令行工具被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config). ( ...
- 设计模式—迭代器Iterator模式
什么是迭代器模式? 让用户通过特定的接口访问容器的数据,不需要了解容器内部的数据结构. 首先我们先模仿集合中ArrayList和LinkedList的实现.一个是基于数组的实现.一个是基于链表的实现, ...
- verilog FAQ(zz)
1. What is the race condition in verilog? Ans :The situation when two expressions are allowed to exe ...
- INSPIRED启示录 读书笔记 - 第37章 大众网络服务产品
十大要点 1.可用性:大众网络服务产品必须具备良好的用户体验 2.人物角色:按典型特征将用户分类,抽象出有代表性的用户类型(人物角色) 3.扩展性:应该不间断地考虑扩展性问题,永远留有余地,不到万不得 ...
- Mybatis映射配置文件Mapper.xml详解
1.概述: MyBatis 的真正强大在于它的映射语句,也是它的魔力所在. 2.常用的属性 常用的几个属性: select元素:代表查询,类似的还有update.insert.delete id:这个 ...
- Kafaka高可用集群环境搭建
zk集群环境搭建:https://www.cnblogs.com/toov5/p/9897868.html 三台主机每台的Java版本1.8 下面kafka集群的搭建: 3台虚拟机均进行以下操作: ...
- maven 内置属性有哪些?该如何使用?
maven 共有6类内置属性: 内置属性(maven预定义,用户可以直接使用的) ${basedir}表示项目的根目录,既包含pom.xml文件的目录: ${version}表示项目版本: ${pro ...