.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/filters/plot_dog.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_dog.py: ============================================== Band-pass filtering by Difference of Gaussians ============================================== Band-pass filters attenuate signal frequencies outside of a range (band) of interest. In image analysis, they can be used to denoise images while at the same time reducing low-frequency artifacts such a uneven illumination. Band-pass filters can be used to find image features such as blobs and edges. One method for applying band-pass filters to images is to subtract an image blurred with a Gaussian kernel from a less-blurred image. This example shows two applications of the Difference of Gaussians approach for band-pass filtering. .. GENERATED FROM PYTHON SOURCE LINES 18-20 Denoise image and reduce shadows ================================ .. GENERATED FROM PYTHON SOURCE LINES 20-45 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from skimage.data import gravel from skimage.filters import difference_of_gaussians, window from scipy.fft import fftn, fftshift image = gravel() wimage = image * window('hann', image.shape) # window image to improve FFT filtered_image = difference_of_gaussians(image, 1, 12) filtered_wimage = filtered_image * window('hann', image.shape) im_f_mag = fftshift(np.abs(fftn(wimage))) fim_f_mag = fftshift(np.abs(fftn(filtered_wimage))) fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(8, 8)) ax[0, 0].imshow(image, cmap='gray') ax[0, 0].set_title('Original Image') ax[0, 1].imshow(np.log(im_f_mag), cmap='magma') ax[0, 1].set_title('Original FFT Magnitude (log)') ax[1, 0].imshow(filtered_image, cmap='gray') ax[1, 0].set_title('Filtered Image') ax[1, 1].imshow(np.log(fim_f_mag), cmap='magma') ax[1, 1].set_title('Filtered FFT Magnitude (log)') plt.show() .. image-sg:: /auto_examples/filters/images/sphx_glr_plot_dog_001.png :alt: Original Image, Original FFT Magnitude (log), Filtered Image, Filtered FFT Magnitude (log) :srcset: /auto_examples/filters/images/sphx_glr_plot_dog_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-48 Enhance edges in an image ========================= .. GENERATED FROM PYTHON SOURCE LINES 48-68 .. code-block:: Python from skimage.data import camera image = camera() wimage = image * window('hann', image.shape) # window image to improve FFT filtered_image = difference_of_gaussians(image, 1.5) filtered_wimage = filtered_image * window('hann', image.shape) im_f_mag = fftshift(np.abs(fftn(wimage))) fim_f_mag = fftshift(np.abs(fftn(filtered_wimage))) fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(8, 8)) ax[0, 0].imshow(image, cmap='gray') ax[0, 0].set_title('Original Image') ax[0, 1].imshow(np.log(im_f_mag), cmap='magma') ax[0, 1].set_title('Original FFT Magnitude (log)') ax[1, 0].imshow(filtered_image, cmap='gray') ax[1, 0].set_title('Filtered Image') ax[1, 1].imshow(np.log(fim_f_mag), cmap='magma') ax[1, 1].set_title('Filtered FFT Magnitude (log)') plt.show() .. image-sg:: /auto_examples/filters/images/sphx_glr_plot_dog_002.png :alt: Original Image, Original FFT Magnitude (log), Filtered Image, Filtered FFT Magnitude (log) :srcset: /auto_examples/filters/images/sphx_glr_plot_dog_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.577 seconds) .. _sphx_glr_download_auto_examples_filters_plot_dog.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.24.0?filepath=notebooks/auto_examples/filters/plot_dog.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dog.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dog.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_