3D-DWT或者nD-DWT python下多維離散小波變換代碼

參考資料:
https://www.pantechsolutions.net/image-processing-projects/matlab-code-for-3d-dwt-3-dimensonal-discrete-wavelet-transform
https://pywavelets.readthedocs.io/en/latest/

3D-小波分解
這個示例是將一個三通道的RGB圖片看做一個時長爲3的視頻序列來做3維的小波分解,通常2D-DWT的一級分解是將一張灰度圖分解爲四個分量,而3D-DWT的以及分解是將一段視頻序列分解爲8個分量。

import numpy as np
import cv2
import matplotlib.pyplot as plt
import pywt
import pywt.data
from skimage import io,data,color
from PIL import Image

original=cv2.imread('/home/jinbeibei/Pictures/1781985300.jpg')
print(original.shape)
#original=color.rgb2grey(original)
#print(original.shape)





# Wavelet transform of image, and plot approximation and details
titles = ['A', ' B',
          'C', 'D','E','F','G','H']
coeffs2 = pywt.dwtn(original,wavelet='haar',mode='symmetric',axes=None)
print(len(coeffs2))#the len of dict is 4 for a gray image
i=0
fig = plt.figure(figsize=(12, 3))
for value in coeffs2.values():

    print(type(value))#ndarray
    print(value.shape)#(493,302,2)
    ax = fig.add_subplot(1, 16, i+1)
    ax.imshow(value[:,:,0], interpolation="nearest", cmap=plt.cm.gray)
    ax.set_title(titles[i-1], fontsize=10)
    ax.set_xticks([])
    ax.set_yticks([])
    i=i+1
    print(i)
    print(titles[i-1])
    ax.imshow(value[:, :, 1], interpolation="nearest", cmap=plt.cm.gray)
    ax.set_title(titles[i-1], fontsize=10)
    ax.set_xticks([])
    ax.set_yticks([])


fig.tight_layout()
plt.show()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章