Wavedec2 = wavedec2 = wavedec2 = wavedec2 = wavedec2 = wavedec2 = wavedec2
Let’s take a look at the general form of the WaveDec2 function,
Pywt. Wavedec2 (data, wavelet, symmetric mode = ', 'level =None, axes=(-2, -1) Input data: Wavelet base: scale (how many layers to transform)returnNote that the high frequencies of each layer are contained in atuple[cl, (cH3, cV3, cD3), (cH2, cV2, cD2), (cH1, cV1, cD1)]Copy the code
Only so may not be easy to understand, so since an example, my purpose is to 11. XLSX inside the gray image for 3 layers of wavelet transform, and to extract the coefficients of the low-frequency components and high-frequency components after the transformation
The instance
import pywt
import xlrd
import numpy as np
def excel2matrix(path) : # Change data from XLSX file to np.array
data = xlrd.open_workbook(path)
table = data.sheets()[0]
nrows = table.nrows # lines
ncols = table.ncols # the number of columns
datamatrix = np.zeros((nrows, ncols))
for i in range(nrows):
rows = table.row_values(i)
datamatrix[i,:] = rows
return datamatrix
pathX = '11.xlsx' # Data path
x = excel2matrix(pathX) # My grayscale data
w = 'sym4' # Wavelet base type
l = 3 # Wavelet transform hierarchy
coeffs = pywt.wavedec2(x,w,l)
[cl, (cH3, cV3, cD3), (cH2, cV2, cD2), (cH1, cV1, cD1)] = coeffs
Copy the code
To tell you what this coeffs return value is, it’s a list of two things: 1) low frequency coefficients, stored as an array. 2) high frequency coefficients, the high frequency coefficients of each layer (horizontal, vertical and diagonal) constitute a 3-dimensional tuple, so there are several tuples for several layers of wavelet decomposition
For those of you who don’t know how to set the values of variables after you see the code run, you can refer to my article PyCharm set to run in the console, showing the values of variables involved in the code (similar to the MATLAB workspace)
When using the waveDec2 function, pay attention to the matching of the input parameters. Try to specify the name, not the position of the parameter. If the position of the parameter matches, be sure to check that each parameter matches correctly. ValueError: Too many values to unpack (expected 4) error when wavedec2 is used
Data set link
Link: pan.baidu.com/s/1kqIBkgNe… Extract code: M600