Skip to content

Instantly share code, notes, and snippets.

@leetschau
Created September 30, 2018 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leetschau/7816018fcce3457e78d4d7fad26b929a to your computer and use it in GitHub Desktop.
Save leetschau/7816018fcce3457e78d4d7fad26b929a to your computer and use it in GitHub Desktop.
基于小波分析实现图片降噪的实例
import numpy as np
import matplotlib.pyplot as plt
import pywt
original = pywt.data.camera()
noiseSigma = 16.0
image = original + np.random.normal(0, noiseSigma, size=original.shape)
wavelet = pywt.Wavelet('haar')
levels = int(np.floor(np.log2(image.shape[0])))
waveletCoeffs = pywt.wavedec2(image, wavelet, level=levels)
threshold = noiseSigma * np.sqrt(2 * np.log2(image.size))
newWaveletCoeffs = list(map(lambda x: pywt.threshold(x,threshold), waveletCoeffs))
newImage = pywt.waverec2(newWaveletCoeffs, wavelet)
plt.imshow(original)
plt.imshow(image)
plt.imshow(newImage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment