.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "advanced/image_processing/auto_examples/plot_face_denoise.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_advanced_image_processing_auto_examples_plot_face_denoise.py: Image denoising ================ This example demoes image denoising on a Raccoon face. .. GENERATED FROM PYTHON SOURCE LINES 7-40 .. image-sg:: /advanced/image_processing/auto_examples/images/sphx_glr_plot_face_denoise_001.png :alt: noisy, Gaussian filter, Median filter :srcset: /advanced/image_processing/auto_examples/images/sphx_glr_plot_face_denoise_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import scipy as sp import matplotlib.pyplot as plt rng = np.random.default_rng(27446968) f = sp.datasets.face(gray=True) f = f[230:290, 220:320] noisy = f + 0.4 * f.std() * rng.random(f.shape) gauss_denoised = sp.ndimage.gaussian_filter(noisy, 2) med_denoised = sp.ndimage.median_filter(noisy, 3) plt.figure(figsize=(12, 2.8)) plt.subplot(131) plt.imshow(noisy, cmap="gray", vmin=40, vmax=220) plt.axis("off") plt.title("noisy", fontsize=20) plt.subplot(132) plt.imshow(gauss_denoised, cmap="gray", vmin=40, vmax=220) plt.axis("off") plt.title("Gaussian filter", fontsize=20) plt.subplot(133) plt.imshow(med_denoised, cmap="gray", vmin=40, vmax=220) plt.axis("off") plt.title("Median filter", fontsize=20) plt.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0, left=0, right=1) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.217 seconds) .. _sphx_glr_download_advanced_image_processing_auto_examples_plot_face_denoise.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_face_denoise.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_face_denoise.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_face_denoise.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_