def plot_wavelet_decomposition(image, level=3):
"""
Plot of 2D wavelet decompositions for given number of levels.
image needs to be either a colour channel or greyscale image:
rgb: self.I[:, :, n], where n = {0, 1, 2}
greyscale: use rgb_to_grey(self.I)
"""
coeffs = pywt.wavedec2(image, wavelet='haar', level=level)
for i, (cH, cV, cD) in enumerate(coeffs[1:]):
if i == 0:
cAcH = np.concatenate((coeffs[0], cH), axis=1)
cVcD = np.concatenate((cV, cD), axis=1)
plot_image = np.concatenate((cAcH, cVcD), axis=0)
else:
plot_image = np.concatenate((plot_image, cH), axis=1)
cVcD = np.concatenate((cV, cD), axis=1)
plot_image = np.concatenate((plot_image, cVcD), axis=0)
plt.grid(False)
io.imshow(abs(plot_image), cmap='gray_r')
plt.show()
评论列表
文章目录