2

我需要使用 pyWavelet,即 pywt 来读取我的图像为它制作小波,下面的示例仅用于加载相机图像,如何使用我计算机路径中的另一个图像?

import pywt
import pywt.data

# Load image
original = pywt.data.camera()
4

5 回答 5

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...
于 2020-01-13T03:15:40.207 回答
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)
于 2019-06-25T21:21:54.567 回答
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
于 2020-09-10T04:36:37.883 回答
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
于 2020-11-18T08:40:55.577 回答
-1

您可以尝试以下方法。

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()

参考:https ://pywavelets.readthedocs.io/en/latest/

于 2019-06-26T07:25:27.790 回答