我正在尝试为学生项目运行此代码:
只有那个功能:
def fwt97(s, width, height):
''' Forward Cohen-Daubechies-Feauveau 9 tap / 7 tap wavelet transform
performed on all columns of the 2D n*n matrix signal s via lifting.
The returned result is s, the modified input matrix.
The highpass and lowpass results are stored on the left half and right
half of s respectively, after the matrix is transposed. '''
# 9/7 Coefficients:
a1 = -1.586134342
a2 = -0.05298011854
a3 = 0.8829110762
a4 = 0.4435068522
# Scale coeff:
k1 = 0.81289306611596146 # 1/1.230174104914
k2 = 0.61508705245700002 # 1.230174104914/2
# Another k used by P. Getreuer is 1.1496043988602418
for col in range(width): # Do the 1D transform on all cols:
''' Core 1D lifting process in this loop. '''
''' Lifting is done on the cols. '''
# Predict 1. y1
for row in range(1, height-1, 2):
s[row][col] += a1 * (s[row-1][col] + s[row+1][col])
s[height-1][col] += 2 * a1 * s[height-2][col] # Symmetric extension
# Update 1. y0
for row in range(2, height, 2):
s[row][col] += a2 * (s[row-1][col] + s[row+1][col])
s[0][col] += 2 * a2 * s[1][col] # Symmetric extension
# Predict 2.
for row in range(1, height-1, 2):
s[row][col] += a3 * (s[row-1][col] + s[row+1][col])
s[height-1][col] += 2 * a3 * s[height-2][col]
# Update 2.
for row in range(2, height, 2):
s[row][col] += a4 * (s[row-1][col] + s[row+1][col])
s[0][col] += 2 * a4 * s[1][col]
# de-interleave
temp_bank = [[0]*width for i in range(height)]
for row in range(height):
for col in range(width):
# k1 and k2 scale the vals
# simultaneously transpose the matrix when deinterleaving
if row % 2 == 0: # even
temp_bank[col][row/2] = k1 * s[row][col]
else: # odd
temp_bank[col][row/2 + height/2] = k2 * s[row][col]
# write temp_bank to s:
for row in range(width):
for col in range(height):
s[row][col] = temp_bank[row][col]
return s
根据作者的说法,代码应该运行,但我收到此错误:
Traceback (most recent call last):
File “wavelet_02.py”, line 200, in
m = fwt97_2d(m, 3)
File “wavelet_02.py”, line 27, in fwt97_2d
m = fwt97(m, w, h) # cols
File “wavelet_02.py”, line 108, in fwt97
temp_bank[col][row/2 + height/2] = k2 * s[row][col]
IndexError: list assignment index out of range
测试:Windows 7 / Mac OS 10.7.3
Python 2.7.3
PIL 1.1.7
任何帮助都会很棒!
干杯,托比