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 ...
随机推荐
- Linux进程优先级查看及修改
进程cpu资源分配就是指进程的优先权(priority).优先权高的进程有优先执行权利.配置进程优先权对多任务环境的Linux很有用,可以改善系统性能.还可以把进程运行到指定的CPU上,这样一来,把不 ...
- c# 抽象类(abstract)
using System; using System.Collections.Generic; using System.Linq; using System.Text; //抽象类(abstract ...
- 06_Hadoop配置伪分布式模式详解
查看IP地址,设为手动模式: 配置hadoop用户sudo权限 su切换到root身份,配置vim /etc/sudoers文件,加入 hadoop ALL=(root)NOPASSWD:ALL ...
- 测试 js 方法运行时间
早期测速的时候是这样的,呵呵呵,一开始还挺爽的 function testFunctionTime(fn) { var start = new Date().getTime(); if (fn) fn ...
- linux创建指定大小的文件
一.生成文件大小和实际占空间大小一样的文件 dd if=/dev/zero of=50M.file bs=1M count=50 dd if=/dev/zero of=20G.file bs=1G c ...
- Cocos2d-x项目移植到WP8系列之四:文件操作
原文链接: http://www.cnblogs.com/zouzf/p/3972457.html 读写文件Cocos已经用fopen fwrite来做好了,这里说的主要是文件和文件夹的创建.删除.判 ...
- android开发之如何将一般应用变身系统级应用【转】
本文转载自:https://blog.csdn.net/zanelove/article/details/43953743 前提: ROOT过的手机 1,把代码编写好后,打包导出apk,copy到手机 ...
- 【P1582】倒水(数论??暴力!!)
这个题我很无语,一开始看绿题,还是数论,应该不会特别简单,应该要动笔写上好一会,过了一会旁边 #祝神 说这原来是个蓝题,我顿时觉得十分迷茫... 结果看了这个题看了一会,仔细一想,woc,这题怕不是可 ...
- Hadoop的Docker镜像构建
1.Dockerfile ###Dockerfile -- beagin FROM ubuntu:trusty #MAINTAINER The Hue Team "https://githu ...
- IOS 发布被拒 3.2 f
Dear Developer, We have determined that your Apple Developer Program membership, or another membersh ...