-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace reST user guide with Jupyter Notebook for image quality guide…
…, remove unused images (#244) * Add feature maps Jupyter Notebook, remove reST file and unused images Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com> * Download dataset externally (kikuchipy-data) Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
- Loading branch information
Showing
26 changed files
with
229 additions
and
128 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-143 KB
doc/_static/image/pattern_processing/fft_filter_highlowpass_result.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"nbsphinx": "hidden" | ||
}, | ||
"source": [ | ||
"This notebook is part of the `kikuchipy` documentation https://kikuchipy.org.\n", | ||
"Links to the documentation won't work from the notebook." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Feature maps\n", | ||
"\n", | ||
"This section details methods for extracting information from pattern\n", | ||
"intensities, called feature maps (for lack of a better description).\n", | ||
"\n", | ||
"Let's import the necessary libraries and a Nickel EBSD test data set:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# exchange inline for qt5 for interactive plotting from the pyqt package\n", | ||
"%matplotlib inline\n", | ||
"\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"plt.rcParams[\"font.size\"] = 15\n", | ||
"import numpy as np\n", | ||
"import kikuchipy as kp\n", | ||
"\n", | ||
"\n", | ||
"# Use kp.load(\"data.h5\") to load your own data\n", | ||
"s = kp.data.nickel_ebsd_large(allow_download=True) # External download\n", | ||
"s" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Image quality\n", | ||
"\n", | ||
"The image quality metric $Q$ presented by Krieger Lassen\n", | ||
"<cite data-cite=\"lassen1994automated\"> Lassen (1994)</cite>\n", | ||
"can be calculated for an [EBSD](reference.rst#kikuchipy.signals.EBSD) signal\n", | ||
"with\n", | ||
"[get_image_quality()](reference.rst#kikuchipy.signals.EBSD.get_image_quality),\n", | ||
"or, for a single pattern (`numpy.ndarray`), with\n", | ||
"[get_image_quality()](reference.rst#kikuchipy.pattern.get_image_quality).\n", | ||
"Following the notation in\n", | ||
"<cite data-cite=\"marquardt2017quantitative\">Marquardt et al. (2017)</cite>, it\n", | ||
"is given by\n", | ||
"\n", | ||
"$$\n", | ||
"\\begin{align}\n", | ||
"Q &= 1 - \\frac{J}{J_{\\mathrm{res}}w_{\\mathrm{tot}}},\\\\\n", | ||
"J &= \\sum_{h = -N/2}^{N/2} \\sum_{k = -N/2}^{N/2} w(h, k)\n", | ||
"\\left|\\mathbf{q}\\right|^2,\\\\\n", | ||
"J_{\\mathrm{res}} &= \\frac{1}{N^2} \\sum_{h = -N/2}^{N/2}\n", | ||
"\\sum_{k = -N/2}^{N/2} \\left|\\mathbf{q}\\right|^2,\\\\\n", | ||
"w_{\\mathrm{tot}} &= \\sum_{h = -N/2}^{N/2} \\sum_{k = -N/2}^{N/2} w(h, k).\n", | ||
"\\end{align}\n", | ||
"$$\n", | ||
"\n", | ||
"The function $w(h, k)$ is the Fast Fourier Transform (FFT) power spectrum of the\n", | ||
"EBSD pattern, and the vectors $\\mathbf{q}$ are the frequency vectors with\n", | ||
"components $(h, k)$. The sharper the Kikuchi bands, the greater the high\n", | ||
"frequency content of the power spectrum, and thus the closer $Q$ will be to\n", | ||
"unity.\n", | ||
"\n", | ||
"Since we want to use the image quality metric to determine how pronounced the\n", | ||
"Kikuchi bands in our patterns are, we first remove the static and dynamic\n", | ||
"background:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"s.remove_static_background()\n", | ||
"s.remove_dynamic_background()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"To visualize parts of the computation, we compute the power spectrum of a\n", | ||
"pattern in the Nickel EBSD data set and the frequency vectors, shift the\n", | ||
"zero-frequency components to the centre, and plot them:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"p = s.inav[20, 11].data\n", | ||
"p_fft = kp.pattern.fft(p, shift=True)\n", | ||
"q = kp.pattern.fft_frequency_vectors(shape=p.shape)\n", | ||
"\n", | ||
"fig, ax = plt.subplots(figsize=(22, 6), ncols=3)\n", | ||
"title_kwargs = dict(fontsize=22, pad=15)\n", | ||
"fig.subplots_adjust(wspace=0.05)\n", | ||
"\n", | ||
"im0 = ax[0].imshow(p, cmap=\"gray\")\n", | ||
"ax[0].set_title(\"Pattern\", **title_kwargs)\n", | ||
"fig.colorbar(im0, ax=ax[0])\n", | ||
"\n", | ||
"im1 = ax[1].imshow(np.log(kp.pattern.fft_spectrum(p_fft)), cmap=\"gray\")\n", | ||
"ax[1].set_title(\"Log of shifted power spectrum of FFT\", **title_kwargs)\n", | ||
"fig.colorbar(im1, ax=ax[1])\n", | ||
"\n", | ||
"im2 = ax[2].imshow(np.fft.fftshift(q), cmap=\"gray\")\n", | ||
"ax[2].set_title(r\"Shifted frequency vectors $q$\", **title_kwargs)\n", | ||
"_ = fig.colorbar(im2, ax=ax[2])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If we don't want the EBSD patterns to be\n", | ||
"[zero-mean normalized](pattern_processing.ipynb#normalize-intensity) before\n", | ||
"computing $Q$, we must pass `get_image_quality(normalize=False)`.\n", | ||
"\n", | ||
"Let's compute the image quality $Q$ and plot it for the entire data set:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"iq = s.get_image_quality(normalize=True) # Default\n", | ||
"\n", | ||
"plt.figure(figsize=(10, 6))\n", | ||
"plt.imshow(iq, cmap=\"gray\")\n", | ||
"_ = plt.colorbar(label=r\"Image quality, $Q$\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If we want to use this map to navigate around in when plotting patterns, we can\n", | ||
"easily do that as explained in the\n", | ||
"[visualizing patterns](visualizing_patterns.rst) guide." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.