This commit is contained in:
xixu-me committed 2024-09-18 17:07:59 +08:00
1 parent f6b44e8e6e
commit 6abe2b069c
3 files changed
+61

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import numpy as np
import pywt
data = np.array([22, 26, 30, 18, 16, 20, 25, 36])
coeffs0 = pywt.dwt(data, "haar")
coeffs1 = pywt.wavedec(data, "haar", level=2)
data1 = np.array([[12, 4, 26, 14], [6, 27, 32, 22], [18, 12, 30, 24], [32, 28, 10, 8]])
coeffs2 = pywt.dwt2(data1, "haar")
coeffs3 = pywt.wavedec2(data1, "haar", level=2)
print(coeffs0)
print(coeffs1)
print(coeffs2)
print(coeffs3)
+21
View File
@@ -0,0 +1,21 @@
import cv2 as cv
import numpy as np
import pywt
from matplotlib import pyplot as plt
img = cv.imread("images/house.jpg")
img = cv.resize(img, (512, 512))
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY).astype(np.float32)
plt.figure("二维小波一级变换")
coeffs = pywt.dwt2(img, "haar")
cA, (cH, cV, cD) = coeffs
AH = np.concatenate([cA, cH], axis=1)
VD = np.concatenate([cV, cD], axis=1)
img1 = np.concatenate([AH, VD], axis=0)
plt.imshow(img1, cmap="gray")
plt.title("result")
plt.axis("off")
plt.show()
+25
View File
@@ -0,0 +1,25 @@
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
import pywt
img = cv.imread("images/house.jpg")
img = cv.resize(img, (512, 512))
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY).astype(np.float32)
plt.figure("二维图像多级分解")
coeffs = pywt.wavedec2(img, "haar", level=2)
cA2, (cH2, cV2, cD2), (cH1, cV1, cD1) = coeffs
AH2 = np.concatenate([cA2, cH2 + 510], axis=1)
VD2 = np.concatenate([cV2 + 510, cD2 + 510], axis=1)
cA1 = np.concatenate([AH2, VD2], axis=0)
AH = np.concatenate([cA1, (cH1 + 255) * 2], axis=1)
VD = np.concatenate([(cV1 + 255) * 2, (cD1 + 255) * 2], axis=1)
img = np.concatenate([AH, VD], axis=0)
plt.imshow(img, cmap="gray")
plt.title("2D WT")
plt.axis("off")
plt.show()