对图片进行去噪

在这个例子中,我们使用全变差、双边和小波去噪过滤器来去噪图片的噪声版本。

全变分和双边算法通常产生带有被锐利边缘分隔的平坦区域的“色调”图像。可以通过控制去噪和对原始图像的忠诚度之间的权衡来改变去噪程度。

全变差滤波

此滤波的结果是具有最小总变化范数的图像,同时尽可能接近初始图像。全变差是图像梯度的L1范数。

双边过滤器

双边滤波器是一种边缘保持和降噪的滤波器。它根据像素的空间邻近度和辐射相似性对其进行平均。

小波去噪滤波

小波去噪滤波器依赖于图像的小波表示。噪声由设置为0的小波域中的小值表示。

在彩色图像中,小波去噪通常是在 YCbCr color space 因为在单独的颜色通道中去噪可能会导致更明显的噪声。

Noisy, TV, Bilateral, Wavelet denoising, Original, (more) TV, (more) Bilateral, Wavelet denoising in YCbCr colorspace

输出:

/scikit-image/doc/examples/filters/plot_denoise.py:60: FutureWarning:

`multichannel` is a deprecated argument name for `estimate_sigma`. It will be removed in version 1.0. Please use `channel_axis` instead.

Estimated Gaussian noise standard deviation = 0.14946152021339662
/scikit-image/doc/examples/filters/plot_denoise.py:68: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_tv_chambolle`. It will be removed in version 1.0. Please use `channel_axis` instead.

/scikit-image/doc/examples/filters/plot_denoise.py:71: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_bilateral`. It will be removed in version 1.0. Please use `channel_axis` instead.

/scikit-image/doc/examples/filters/plot_denoise.py:75: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_wavelet`. It will be removed in version 1.0. Please use `channel_axis` instead.

/scikit-image/doc/examples/filters/plot_denoise.py:79: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_tv_chambolle`. It will be removed in version 1.0. Please use `channel_axis` instead.

/scikit-image/doc/examples/filters/plot_denoise.py:82: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_bilateral`. It will be removed in version 1.0. Please use `channel_axis` instead.

/scikit-image/doc/examples/filters/plot_denoise.py:86: FutureWarning:

`multichannel` is a deprecated argument name for `denoise_wavelet`. It will be removed in version 1.0. Please use `channel_axis` instead.

Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).

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, multichannel=True, 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, multichannel=True))
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,
                multichannel=True))
ax[0, 2].axis('off')
ax[0, 2].set_title('Bilateral')
ax[0, 3].imshow(denoise_wavelet(noisy, multichannel=True, 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, multichannel=True))
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,
                multichannel=True))
ax[1, 2].axis('off')
ax[1, 2].set_title('(more) Bilateral')
ax[1, 3].imshow(denoise_wavelet(noisy, multichannel=True, 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分10.157秒)

Gallery generated by Sphinx-Gallery