0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

画像ピラミッド(ガウシアン・ラプラシアンピラミッド)

Last updated at Posted at 2025-08-24

1. 画像ピラミッド

  • 画像を多層構造としてあらわす方法として、ガウシアンピラミッドラプラシアンピラミッドがある

image.png

2. ガウシアンピラミッドの構築

  • 入力画像に対してGaussianフィルタを適用した後、縦横の解像度が半分になるようダウンサンプリングする
  • このダウンサンプリング処理をn回繰り返し、n層のガウシアンピラミッドを構築する(ここでは高解像側を上層、低解像側を下層と呼ぶ)

3. ラプラシアンピラミッドの構築

  • ガウシアンピラミッドから隣接する層の画像を取り出し、アップサンプリングによって上層側にスケールを合わせる
  • 各隣接画像に対して差分画像を計算する処理を繰り返す
  • 最下層にはガウシアンピラミッドの最下層画像をそのまま保存する
\displaylines{
L_0 &=& G_0 - \mathrm{upsample}(G_1) \\
L_1 &=& G_1 - \mathrm{upsample}(G_2) \\
L_2 &=& G_2 - \mathrm{upsample}(G_3) \\
L_3 &=& G_3 \\
}

4. ラプラシアンピラミッドを用いた画像再構成

  • ラプラシアンピラミッドの定義式によると、元の入力画像 $G_0$ はラプラシアンピラミッド画像のみ $(L_0, L_1, L_2, L_3)$ で表現できる
\displaylines{
G_0 &=& L_0 + \mathrm{upsample}(G_1) \\
&=& L_0 + \mathrm{upsample}(L_1 + \mathrm{upsample}(G_2)) \\
&=& L_0 + \mathrm{upsample}(L_1 + \mathrm{upsample}(L_2 + \mathrm{upsample}(G_3))) \\
&=& L_0 + \mathrm{upsample}(L_1 + \mathrm{upsample}(L_2 + \mathrm{upsample}(L_3))) \\
}
入力画像 再構成画像

スクリプト例

import cv2
import numpy as np
import os

def build_gaussian_pyramid(img, levels):
    gp = [img.astype(np.float64)]
    for i in range(levels):
        img = cv2.pyrDown(img)
        gp.append(img.astype(np.float64))
    return gp

def build_laplacian_pyramid(img, levels):
    gp = build_gaussian_pyramid(img, levels)
    lp = []
    for i in range(levels):
        size = (gp[i].shape[1], gp[i].shape[0])
        GE = cv2.pyrUp(gp[i+1], dstsize=size)
        L = gp[i] - GE
        lp.append(L)
    lp.append(gp[-1])  # 最下層はそのまま
    return lp

def reconstruct_from_laplacian(lp):
    levels = len(lp) - 1
    current = lp[-1]
    recons = [current]  # 各ステップを保存
    for i in range(levels-1, -1, -1):
        size = (lp[i].shape[1], lp[i].shape[0])
        current = cv2.pyrUp(current, dstsize=size)
        current = cv2.add(current, lp[i])
        recons.append(current)
    return recons

if __name__ == "__main__":
    os.makedirs("output", exist_ok=True)

    # 入力画像読み込み
    img = cv2.imread("input.png").astype(np.float64)
    levels = 3

    # ピラミッド分解
    gp = build_gaussian_pyramid(img, levels)
    lp = build_laplacian_pyramid(img, levels)

    # 再構成
    recons = reconstruct_from_laplacian(lp)
    cv2.imwrite("output.png", np.clip(recons[-1], 0, 255).astype(np.uint8))

5. 画像ピラミッドの応用例

  • 画像圧縮
  • 画像編集
    • マルチフォーカス合成
    • 画像ブレンディング

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?