注意
前往結尾下載完整的範例程式碼。或透過 Binder 在您的瀏覽器中執行此範例
圖片去噪#
在此範例中,我們使用總變異、雙邊和波去噪濾波器,為圖片的雜訊版本去噪。
總變異和雙邊演算法通常會產生「海報化」圖像,其具有由銳利邊緣分隔的平坦區域。可以透過控制去噪與對原始圖像忠實度之間的權衡來變更海報化的程度。
總變異濾波器#
此濾波器的結果是具有最小總變異範數的圖像,同時盡可能接近初始圖像。總變異是圖像梯度的 L1 範數。
雙邊濾波器#
雙邊濾波器是一種保留邊緣並降低雜訊的濾波器。它會根據像素的空間接近度和放射相似性來平均像素。
小波去噪濾波器#
小波去噪濾波器依賴於圖像的小波表示。雜訊由小波域中設定為 0 的小值表示。
在彩色圖像中,小波去噪通常在 YCbCr 色彩空間中完成,因為在單獨的色彩通道中去噪可能會導致更明顯的雜訊。

Estimated Gaussian noise standard deviation = 0.1496192774329601
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [-0.002508543763914225..0.8470964845245508].
import matplotlib.pyplot as plt
from skimage.restoration import (
denoise_tv_chambolle,
denoise_bilateral,
denoise_wavelet,
estimate_sigma,
)
from skimage import data, img_as_float
from skimage.util import random_noise
original = img_as_float(data.chelsea()[100:250, 50:300])
sigma = 0.155
noisy = random_noise(original, var=sigma**2)
fig, ax = plt.subplots(nrows=2, ncols=4, figsize=(8, 5), sharex=True, sharey=True)
plt.gray()
# Estimate the average noise standard deviation across color channels.
sigma_est = estimate_sigma(noisy, channel_axis=-1, average_sigmas=True)
# Due to clipping in random_noise, the estimate will be a bit smaller than the
# specified sigma.
print(f'Estimated Gaussian noise standard deviation = {sigma_est}')
ax[0, 0].imshow(noisy)
ax[0, 0].axis('off')
ax[0, 0].set_title('Noisy')
ax[0, 1].imshow(denoise_tv_chambolle(noisy, weight=0.1, channel_axis=-1))
ax[0, 1].axis('off')
ax[0, 1].set_title('TV')
ax[0, 2].imshow(
denoise_bilateral(noisy, sigma_color=0.05, sigma_spatial=15, channel_axis=-1)
)
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')
ax[0, 3].imshow(denoise_wavelet(noisy, channel_axis=-1, rescale_sigma=True))
ax[0, 3].axis('off')
ax[0, 3].set_title('Wavelet denoising')
ax[1, 1].imshow(denoise_tv_chambolle(noisy, weight=0.2, channel_axis=-1))
ax[1, 1].axis('off')
ax[1, 1].set_title('(more) TV')
ax[1, 2].imshow(
denoise_bilateral(noisy, sigma_color=0.1, sigma_spatial=15, channel_axis=-1)
)
ax[1, 2].axis('off')
ax[1, 2].set_title('(more) Bilateral')
ax[1, 3].imshow(
denoise_wavelet(noisy, channel_axis=-1, convert2ycbcr=True, rescale_sigma=True)
)
ax[1, 3].axis('off')
ax[1, 3].set_title('Wavelet denoising\nin YCbCr colorspace')
ax[1, 0].imshow(original)
ax[1, 0].axis('off')
ax[1, 0].set_title('Original')
fig.tight_layout()
plt.show()
腳本的總執行時間: (0 分鐘 12.432 秒)