.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/pattern_processing/neighbour_pattern_averaging.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_examples_pattern_processing_neighbour_pattern_averaging.py: =========================== Neighbour pattern averaging =========================== This example shows how to average each pattern in a scan with its nearest neighbours using :meth:`~kikuchipy.signals.EBSD.average_neighbour_patterns`. More details are given in the :doc:`pattern processing tutorial ` and the :doc:`feature maps tutorial `. .. GENERATED FROM PYTHON SOURCE LINES 13-55 .. image-sg:: /examples/pattern_processing/images/sphx_glr_neighbour_pattern_averaging_001.png :alt: Static + Dynamic, Static + Dynamic + Averaging :srcset: /examples/pattern_processing/images/sphx_glr_neighbour_pattern_averaging_001.png :class: sphx-glr-single-img .. code-block:: default import hyperspy.api as hs import kikuchipy as kp import matplotlib.pyplot as plt # Silence progressbars hs.preferences.General.show_progressbar = False # Load Ni patterns and subtract static and dynamic background s = kp.data.nickel_ebsd_large() s.remove_static_background() s.remove_dynamic_background() # Get image quality before averaging iq0 = s.get_image_quality() # Keep one pattern for comparison x, y = (50, 8) pattern0 = s.inav[x, y].deepcopy() # Average in a (3, 3) window with a Gaussian kernel with a standard # deviation of 1 s.average_neighbour_patterns(window="gaussian", std=1) iq1 = s.get_image_quality() pattern1 = s.inav[x, y] # Plot pattern and histograms of image qualities before and after # averaging fig, axes = plt.subplots(2, 2, height_ratios=[3, 1.5]) for ax, pattern, title in zip( axes[0], [pattern0, pattern1], ["Static + Dynamic", "Static + Dynamic + Averaging"], ): ax.imshow(pattern, cmap="gray") ax.set_title(title) ax.axis("off") for ax, iq in zip(axes[1], [iq0, iq1]): ax.hist(iq.ravel(), bins=100) fig.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.180 seconds) **Estimated memory usage:** 120 MB .. _sphx_glr_download_examples_pattern_processing_neighbour_pattern_averaging.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: neighbour_pattern_averaging.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: neighbour_pattern_averaging.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_