.. _example_decomposition_plot_image_denoising.py:


=========================================
Image denoising using dictionary learning
=========================================

An example comparing the effect of reconstructing noisy fragments
of Lena using online :ref:`DictionaryLearning` and various transform methods.

The dictionary is fitted on the non-distorted left half of the image, and
subsequently used to reconstruct the right half.

A common practice for evaluating the results of image denoising is by looking
at the difference between the reconstruction and the original image. If the
reconstruction is perfect this will look like gaussian noise.

It can be seen from the plots that the results of :ref:`omp` with two
non-zero coefficients is a bit less biased than when keeping only one
(the edges look less prominent). It is in addition closer from the ground
truth in Frobenius norm.

The result of :ref:`least_angle_regression` is much more strongly biased: the
difference is reminiscent of the local intensity value of the original image.

Thresholding is clearly not useful for denoising, but it is here to show that
it can produce a suggestive output with very high speed, and thus be useful
for other tasks such as object classification, where performance is not
necessarily related to visualisation.




.. rst-class:: horizontal


    *

      .. image:: images/plot_image_denoising_1.png
            :scale: 50

    *

      .. image:: images/plot_image_denoising_2.png
            :scale: 50

    *

      .. image:: images/plot_image_denoising_3.png
            :scale: 50

    *

      .. image:: images/plot_image_denoising_4.png
            :scale: 50

    *

      .. image:: images/plot_image_denoising_5.png
            :scale: 50

    *

      .. image:: images/plot_image_denoising_6.png
            :scale: 50


**Python source code:** :download:`plot_image_denoising.py <plot_image_denoising.py>`

.. literalinclude:: plot_image_denoising.py
    :lines: 30-