
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/filters/plot_j_invariant.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_filters_plot_j_invariant.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_filters_plot_j_invariant.py:


========================================
Calibrating Denoisers Using J-Invariance
========================================

In this example, we show how to find an optimally calibrated
version of any denoising algorithm.

The calibration method is based on the `noise2self` algorithm of [1]_.

.. [1] J. Batson & L. Royer. Noise2Self: Blind Denoising by Self-Supervision,
       International Conference on Machine Learning, p. 524-533 (2019).

.. seealso::
   More details about the method are given in the full tutorial
   :ref:`sphx_glr_auto_examples_filters_plot_j_invariant_tutorial.py`.

.. GENERATED FROM PYTHON SOURCE LINES 20-21

Calibrating a wavelet denoiser

.. GENERATED FROM PYTHON SOURCE LINES 21-70

.. code-block:: Python


    import numpy as np
    from matplotlib import pyplot as plt

    from skimage.data import chelsea
    from skimage.restoration import calibrate_denoiser, denoise_wavelet

    from skimage.util import img_as_float, random_noise
    from functools import partial

    # rescale_sigma=True required to silence deprecation warnings
    _denoise_wavelet = partial(denoise_wavelet, rescale_sigma=True)

    image = img_as_float(chelsea())
    sigma = 0.3
    noisy = random_noise(image, var=sigma**2)

    # Parameters to test when calibrating the denoising algorithm
    parameter_ranges = {
        'sigma': np.arange(0.1, 0.3, 0.02),
        'wavelet': ['db1', 'db2'],
        'convert2ycbcr': [True, False],
        'channel_axis': [-1],
    }

    # Denoised image using default parameters of `denoise_wavelet`
    default_output = denoise_wavelet(noisy, channel_axis=-1, rescale_sigma=True)

    # Calibrate denoiser
    calibrated_denoiser = calibrate_denoiser(
        noisy, _denoise_wavelet, denoise_parameters=parameter_ranges
    )

    # Denoised image using calibrated denoiser
    calibrated_output = calibrated_denoiser(noisy)

    fig, axes = plt.subplots(1, 3, sharex=True, sharey=True, figsize=(15, 5))

    for ax, img, title in zip(
        axes,
        [noisy, default_output, calibrated_output],
        ['Noisy Image', 'Denoised (Default)', 'Denoised (Calibrated)'],
    ):
        ax.imshow(img)
        ax.set_title(title)
        ax.set_yticks([])
        ax.set_xticks([])

    plt.show()



.. image-sg:: /auto_examples/filters/images/sphx_glr_plot_j_invariant_001.png
   :alt: Noisy Image, Denoised (Default), Denoised (Calibrated)
   :srcset: /auto_examples/filters/images/sphx_glr_plot_j_invariant_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

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





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.443 seconds)


.. _sphx_glr_download_auto_examples_filters_plot_j_invariant.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_j_invariant.ipynb <plot_j_invariant.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_j_invariant.py <plot_j_invariant.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_j_invariant.zip <plot_j_invariant.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
