我需要使用pyWavelet,即pywt读取我的图像以使其成为小波,下面的示例仅用于加载相机图像,如何使用计算机路径中的另一幅图像?
import pywt
import pywt.data
# Load image
original = pywt.data.camera()
答案 0 :(得分:0)
我不确定是否可以仅使用pywt
读取图像,但是可以使用OpenCV加载图像,然后将其转换为可用的格式以供pywt
import cv2
import numpy as np
import pywt
image = cv2.imread('1.png')
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Convert to float for more resolution for use with pywt
image = np.float32(image)
image /= 255
# ...
# Do your processing
# ...
# Convert back to uint8 OpenCV format
image *= 255
image = np.uint8(image)
cv2.imshow('image', image)
cv2.waitKey(0)
答案 1 :(得分:0)
您可以尝试以下操作。
import numpy as np
import matplotlib.pyplot as plt
import pywt
import pywt.data
# Load image
original = pywt.data.camera()
# Wavelet transform of image, and plot approximation and details
titles = ['Approximation', ' Horizontal detail', 'Vertical detail', 'Diagonal detail']
coeffs2 = pywt.dwt2(original, 'bior1.3')
LL, (LH, HL, HH) = coeffs2
fig = plt.figure(figsize=(12, 3))
for i, a in enumerate([LL, LH, HL, HH]):
ax = fig.add_subplot(1, 4, i + 1)
ax.imshow(a, interpolation="nearest", cmap=plt.cm.gray)
ax.set_title(titles[i], fontsize=10)
ax.set_xticks([])
ax.set_yticks([])
fig.tight_layout()
plt.show()
答案 2 :(得分:0)
OpenCV的替代方法是scikit-image。
import pywt
from skimage import io, color
data = io.imread(filename)
# Process your image
gray = color.rgb2gray(data)
coeffs = pywt.dwt2(gray, 'haar')
# Or... process each channel separately
r, g, b = [c.T for c in data.T]
cr = pywt.dwt2(r, 'haar')
cg = pywt.dwt2(r, 'haar')
cb = pywt.dwt2(r, 'haar')
# output: PIL, matplotlib, dump to file...
答案 3 :(得分:0)
您可以使用matplotlib和numpy:
from matplotlib.image import imread
import numpy as np
import pywt
A = imread("1.jpg")
original = np.mean(A, -1)
#rest of your codes
答案 4 :(得分:0)
我使用pandas
来读取图像,因为我使用hm3.6
数据集进行运动预测并将小波变换用作预处理。
我的代码如下:
path = ".../your_path"
img = pd.read_csv(path + "h3.6m/dataset/S1/directions_1.txt") #read the image
#if you want to apply DWT you can continue with dataframe
coeffs2 = dwt(image, 'bior1.3')
titles = ['Approximation', ' Horizontal detail',
'Vertical detail', 'Diagonal detail']
LL, LH = coeffs2