.. only:: html

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

        Click :ref:`here <sphx_glr_download_auto_examples_filters_plot_rank_mean.py>`     to download the full example code or to run this example in your browser via Binder
    .. rst-class:: sphx-glr-example-title

    .. _sphx_glr_auto_examples_filters_plot_rank_mean.py:


============
Mean filters
============

This example compares the following mean filters of the rank filter package:

* **local mean**: all pixels belonging to the structuring element to compute
  average gray level.
* **percentile mean**: only use values between percentiles p0 and p1
  (here 10% and 90%).
* **bilateral mean**: only use pixels of the structuring element having a gray
  level situated inside g-s0 and g+s1 (here g-500 and g+500)

Percentile and usual mean give here similar results, these filters smooth the
complete image (background and details). Bilateral mean exhibits a high
filtering rate for continuous area (i.e. background) while higher image
frequencies remain untouched.



.. image:: /auto_examples/filters/images/sphx_glr_plot_rank_mean_001.png
    :class: sphx-glr-single-img






.. code-block:: default


    import matplotlib.pyplot as plt

    from skimage import data
    from skimage.morphology import disk
    from skimage.filters import rank


    image = data.coins()
    selem = disk(20)

    percentile_result = rank.mean_percentile(image, selem=selem, p0=.1, p1=.9)
    bilateral_result = rank.mean_bilateral(image, selem=selem, s0=500, s1=500)
    normal_result = rank.mean(image, selem=selem)

    fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 10),
                             sharex=True, sharey=True)
    ax = axes.ravel()

    titles = ['Original', 'Percentile mean', 'Bilateral mean', 'Local mean']
    imgs = [image, percentile_result, bilateral_result, normal_result]
    for n in range(0, len(imgs)):
        ax[n].imshow(imgs[n], cmap=plt.cm.gray)
        ax[n].set_title(titles[n])
        ax[n].axis('off')

    plt.tight_layout()
    plt.show()


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

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


.. _sphx_glr_download_auto_examples_filters_plot_rank_mean.py:


.. only :: html

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


  .. container:: binder-badge

    .. image:: https://mybinder.org/badge_logo.svg
      :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.17.x?filepath=notebooks/auto_examples/filters/plot_rank_mean.ipynb
      :width: 150 px


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

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



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

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


.. only:: html

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

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