.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/filters/plot_blur_effect.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 or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_filters_plot_blur_effect.py: ========================= Estimate strength of blur ========================= This example shows how the metric implemented in ``measure.blur_effect`` behaves, both as a function of the strength of blur and of the size of the re-blurring filter. This no-reference perceptual blur metric is described in [1]_. .. [1] Frederique Crete, Thierry Dolmiere, Patricia Ladret, and Marina Nicolas "The blur effect: perception and estimation with a new no-reference perceptual blur metric" Proc. SPIE 6492, Human Vision and Electronic Imaging XII, 64920I (2007) https://hal.archives-ouvertes.fr/hal-00232709 :DOI:`10.1117/12.702790` .. GENERATED FROM PYTHON SOURCE LINES 19-32 .. code-block:: default import matplotlib.pyplot as plt import numpy as np import pandas as pd import scipy.ndimage as ndi import plotly import plotly.express as px from skimage import ( color, data, measure ) .. GENERATED FROM PYTHON SOURCE LINES 33-37 Generate series of increasingly blurred images ============================================== Let us load an image available through scikit-image’s data registry. The blur metric applies to single-channel images. .. GENERATED FROM PYTHON SOURCE LINES 37-41 .. code-block:: default image = data.astronaut() image = color.rgb2gray(image) .. GENERATED FROM PYTHON SOURCE LINES 42-43 Let us blur this image with a series of uniform filters of increasing size. .. GENERATED FROM PYTHON SOURCE LINES 43-55 .. code-block:: default blurred_images = [ndi.uniform_filter(image, size=k) for k in range(2, 32, 2)] img_stack = np.stack(blurred_images) fig = px.imshow( img_stack, animation_frame=0, binary_string=True, labels={'animation_frame': 'blur strength ~'} ) plotly.io.show(fig) .. raw:: html :file: images/sphx_glr_plot_blur_effect_001.html .. GENERATED FROM PYTHON SOURCE LINES 56-61 Plot blur metric ================ Let us compute the blur metric for all blurred images: We expect it to increase towards 1 with increasing blur strength. We compute it for three different values of re-blurring filter: 3, 11 (default), and 30. .. GENERATED FROM PYTHON SOURCE LINES 61-76 .. code-block:: default B = pd.DataFrame( data=np.zeros((len(blurred_images), 3)), columns=['h_size = 3', 'h_size = 11', 'h_size = 30'] ) for ind, im in enumerate(blurred_images): B.loc[ind, 'h_size = 3'] = measure.blur_effect(im, h_size=3) B.loc[ind, 'h_size = 11'] = measure.blur_effect(im, h_size=11) B.loc[ind, 'h_size = 30'] = measure.blur_effect(im, h_size=30) B.plot().set(xlabel='blur strength (half the size of uniform filter)', ylabel='blur metric') plt.show() .. image-sg:: /auto_examples/filters/images/sphx_glr_plot_blur_effect_002.png :alt: plot blur effect :srcset: /auto_examples/filters/images/sphx_glr_plot_blur_effect_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 77-83 We can see that as soon as the blur is stronger than (reaches the scale of) the size of the uniform filter, the metric gets close to 1 and, hence, tends asymptotically to 1 with increasing blur strength. The value of 11 pixels gives a blur metric which correlates best with human perception. That's why it's the default value in the implementation of the perceptual blur metric ``measure.blur_effect``. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.191 seconds) .. _sphx_glr_download_auto_examples_filters_plot_blur_effect.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.21.x?filepath=notebooks/auto_examples/filters/plot_blur_effect.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_blur_effect.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_blur_effect.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_