Created
September 30, 2018 02:12
-
-
Save leetschau/7816018fcce3457e78d4d7fad26b929a to your computer and use it in GitHub Desktop.
基于小波分析实现图片降噪的实例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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