平移不变小波去噪#

离散小波变换不是平移不变的。平移不变性可以通过非降采样小波变换(也称为平稳小波变换)来实现,但代价是增加了冗余(即小波系数比输入图像像素更多)。在使用离散小波变换进行图像去噪的情况下,另一种近似平移不变性的方法是使用称为“循环旋转”的技术。这涉及对多个空间偏移 n 执行以下 3 步过程的结果进行平均

  1. (循环)将信号偏移量 n

  2. 应用去噪

  3. 应用反向偏移

对于 2D 图像去噪,我们在此证明这种循环旋转可以在质量上提供实质性的提高,其中大部分增益仅通过对每个轴上的 n=0 和 n=1 偏移进行平均就能实现。

Noisy PSNR=16.48, Denoised: no cycle shifts PSNR=26.34, Denoised: 2x2 shifts PSNR=27.28, Denoised: 4x4 shifts PSNR=27.71, Denoised: 6x6 shifts PSNR=27.76
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [-0.01097494764481576..0.825995287510699].
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [-0.010762374571104991..0.8377816391551851].
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [-0.0023875380916145257..0.8265524462285105].

import matplotlib.pyplot as plt

from skimage.restoration import denoise_wavelet, cycle_spin
from skimage import data, img_as_float
from skimage.util import random_noise
from skimage.metrics import peak_signal_noise_ratio


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=3, figsize=(10, 4), sharex=False, sharey=False)
ax = ax.ravel()

psnr_noisy = peak_signal_noise_ratio(original, noisy)
ax[0].imshow(noisy)
ax[0].axis('off')
ax[0].set_title(f'Noisy\nPSNR={psnr_noisy:0.4g}')


# Repeat denosing with different amounts of cycle spinning.  e.g.
# max_shift = 0 -> no cycle spinning
# max_shift = 1 -> shifts of (0, 1) along each axis
# max_shift = 3 -> shifts of (0, 1, 2, 3) along each axis
# etc...

denoise_kwargs = dict(
    channel_axis=-1, convert2ycbcr=True, wavelet='db1', rescale_sigma=True
)

all_psnr = []
max_shifts = [0, 1, 3, 5]
for n, s in enumerate(max_shifts):
    im_bayescs = cycle_spin(
        noisy,
        func=denoise_wavelet,
        max_shifts=s,
        func_kw=denoise_kwargs,
        channel_axis=-1,
    )
    ax[n + 1].imshow(im_bayescs)
    ax[n + 1].axis('off')
    psnr = peak_signal_noise_ratio(original, im_bayescs)
    if s == 0:
        ax[n + 1].set_title(f'Denoised: no cycle shifts\nPSNR={psnr:0.4g}')
    else:
        ax[n + 1].set_title(f'Denoised: {s+1}x{s+1} shifts\nPSNR={psnr:0.4g}')
    all_psnr.append(psnr)

# plot PSNR as a function of the degree of cycle shifting
ax[5].plot(max_shifts, all_psnr, 'k.-')
ax[5].set_ylabel('PSNR (dB)')
ax[5].set_xlabel('max cycle shift along each axis')
ax[5].grid(True)
plt.subplots_adjust(wspace=0.35, hspace=0.35)

# Annotate with a cyan arrow on the 6x6 case vs. no cycle shift case to
# illustrate a region with reduced block-like artifact with cycle shifting
arrowprops = dict(
    arrowstyle="simple,tail_width=0.1,head_width=0.5", connectionstyle="arc3", color='c'
)
for i in [1, 4]:
    ax[i].annotate(
        "",
        xy=(101, 39),
        xycoords='data',
        xytext=(70, 70),
        textcoords='data',
        arrowprops=arrowprops,
    )

plt.show()

脚本的总运行时间:(0 分钟 1.033 秒)

由 Sphinx-Gallery 生成的图库