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 ...
随机推荐
- MFC中修改程序图标
在使用MFC时,我们经常需要修改我们得到的exe文件的图标.如:写一个随机画圆的小程序,我们就希望该程序的图标是个圆或者是和圆有关的图标.所以,在这里我就记录一下我修改图标的步骤. 顺便提一下,我使用 ...
- 【转】Python的hasattr() getattr() setattr() 函数使用方法详解
Python的hasattr() getattr() setattr() 函数使用方法详解 hasattr(object, name)判断一个对象里面是否有name属性或者name方法,返回BOOL值 ...
- MapX小试
需MapX 控件 string layerName = "12Q3_new"; string tabFile = string.Format(@"E:\map\地图\现在 ...
- hadoop linux 杂记
切换到root su 修改sudo sudo + 命令 --> root权限 + 命令 su root vim /etc/sudoers ...
- linux免密登录配置
第一步:安装openssh-clients yum install -y openssh-clients.x86_64第二步:生成密钥 ssh-keygen第三步:拷贝公钥到其他机器 ssh-copy ...
- 【HackerRank】QuickSort(稳定快排,空间复杂度O(n))
QuickSort In the previous challenge, you wrote a partition method to split an array into 2 sub-array ...
- Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介
转:https://www.cnblogs.com/shoemaker/p/linux_graphics01.html Linux/Unix环境下最早的图形系统是Xorg图形系统,Xorg图形系统通过 ...
- Listening Carefully SP1403
Listening Carefully仔细聆听When people talk, listen completely. Most people never listen. ―Ernest Heming ...
- Vue.js学习笔记 第六篇 内置属性
computed属性 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...
- 模型融合之blending和stacking
1. blending 需要得到各个模型结果集的权重,然后再线性组合. """Kaggle competition: Predicting a Biological Re ...