文章目录
- 定义
- 向下取样函数
- 向上取样函数
- 拉普拉斯金字塔
- 实例
- 向下取样获取图像金字塔
- 向上取样获取图像金字塔
- 先向下采样再向上采样
- 先向上采样再向下采样
- 拉普拉斯金字塔
定义
- 同一图像的不同分辨率的子图集合
- 生成方式:
- 向下取样,缩小图像:从第i层获取第i+1层 G i − > G i + 1 G_i -> G_{i+1} Gi−>Gi+1
- 计算流程
- 对图像G_i进行高斯核卷积
- 高斯卷积核 1 256 [ 1 4 6 4 1 4 16 24 16 4 6 24 36 24 6 4 16 24 16 4 1 4 6 4 1 ] \frac{1}{256}\left[ \begin{matrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \\ \end{matrix} \right] 2561⎣⎢⎢⎢⎢⎡1464141624164624362464162416414641⎦⎥⎥⎥⎥⎤
- 删除所有的偶数行和列
- 原始图像 M * N -> 处理结果 M/2 * N/2, 每次处理后,结果图像是原来的1/4
- 该操作被称为:Octave
- 重复执行该过程,构造图像金字塔
- 向上取样
- 计算流程
- 在每个方向上扩大为原来的2倍,新增的行和列以0填充
- 使用与“向下采样”同样的卷积和乘以4,获取“新增像素”的新值
- 放大后的图像比原始图像要模糊
向下取样函数
- 函数pyrDown
dst = cv2.pyrDown(src)
向上取样函数
- 函数pyrUp
dst = cv2.pyrUp(src)
拉普拉斯金字塔
- 计算公式 L i = G i − P y r U p ( P y r D o w n ( G i ) ) L_i = G_i - PyrUp(PyrDown(G_i)) Li=Gi−PyrUp(PyrDown(Gi))
- G i G_i Gi : 原始图像
- L i L_i Li : 拉普拉斯金字塔图像
实例
向下取样获取图像金字塔
import cv2
o = cv2.imread("/home/forrest/图片/lena彩图.jpg", cv2.IMREAD_GRAYSCALE)
cv2.imshow("original", o)
r1 = cv2.pyrDown(o)
cv2.imshow("PyrDown1", r1)
r2 = cv2.pyrDown(r1)
cv2.imshow("PyrDown2", r2)
r3 = cv2.pyrDown(r2)
cv2.imshow("PyrDown3", r3)
cv2.waitKey()
cv2.destroyAllWindows()
向上取样获取图像金字塔
import cv2
o = cv2.imread("/home/forrest/图片/lena_small.png", cv2.IMREAD_GRAYSCALE)
cv2.imshow("original", o)
r1 = cv2.pyrUp(o)
cv2.imshow("pyrUp1", r1)
r2 = cv2.pyrUp(r1)
cv2.imshow("pyrUp2", r2)
r3 = cv2.pyrUp(r2)
cv2.imshow("pyrUp3", r3)
cv2.waitKey()
cv2.destroyAllWindows()
先向下采样再向上采样
import cv2
o = cv2.imread("/home/forrest/图片/lena彩图.png", cv2.IMREAD_GRAYSCALE)
cv2.imshow("original", o)
down = cv2.pyrDown(o)
up = cv2.pyrUp(down)
cv2.imshow("Up", up)
diff = up - o
cv2.imshow("diff", diff)
cv2.waitKey()
cv2.destroyAllWindows()
先向上采样再向下采样
import cv2
o = cv2.imread("/home/forrest/图片/lena彩图.png", cv2.IMREAD_GRAYSCALE)
cv2.imshow("original", o)
up = cv2.pyrUp(o)
down = cv2.pyrDown(up)
cv2.imshow("down", down)
diff = down - o
cv2.imshow("diff", diff)
cv2.waitKey()
cv2.destroyAllWindows()
拉普拉斯金字塔
import cv2
o = cv2.imread("/home/forrest/图片/lena彩图.png", cv2.IMREAD_GRAYSCALE)
cv2.imshow("original", o)
od = cv2.pyrDown(o)
odu = cv2.pyrUp(od)
lapPyr = o - odu
cv2.imshow("lapPyr", lapPyr)
o1 = od
o1d = cv2.pyrDown(o1)
o1du = cv2.pyrUp(o1d)
lapPyr1 = o1 - o1du
cv2.imshow("lapPyr1", lapPyr1)
cv2.waitKey()
cv2.destroyAllWindows()