the grains of a map, the pixels joined across every boundary the criterion keeps; MATLAB’s grain reconstruction from 2d and 3d EBSD data
Syntax
grains = calcGrains(ebsd)
Grain boundaries above 15 degree.
grains = calcGrains(ebsd, angle=10*degree, minPixel=5, alpha=3.7)
Another angle, no grains below 5 pixels.
grains = calcGrains(ebsd, angle=[10*degree, 2*degree])
High and low angle boundaries.
grains = calcGrains(ebsd, angle=[[10*degree], [5*degree]])
A threshold per indexed phase.
grains = calcGrains(ebsd, criterion=gbcAngle(10*degree, byPhase={'Enstatite': 5*degree}))
A threshold per phase.
grains = calcGrains(ebsd, criterion=gbcSoft(10*degree, 2*degree), mcl=(1.4, 4))
A soft threshold and Markov clustering.
grains = calcGrains(ebsd, fmc=1.5, minPixel=10)
Fast multiscale clustering.
grains = calcGrains(ebsd, grainId=True)
The grains stored with the map.
Description
Two neighbouring pixels belong to one grain when the misorientation between them stays below the threshold angle, and a grain is a connected set of such pixels. The angle takes these forms:
- one angle: the threshold of every phase.
- a pair [high, low]: the boundaries above high separate the grains, those between low and high stay inside them as low angle boundaries, grains.innerBoundary.
- a list of other than two entries, or of lists: an angle or a pair per indexed phase or per entry of ebsd.CSList, as MATLAB’s cell {a1, a2, a3}; two phases take [[a1], [a2]].
Any other rule, a soft threshold included, is a grainBoundaryCriterion.
A map of the plane is divided into cells around its pixels, a Voronoi decomposition bounded by alpha. A not indexed region narrower than 2 alpha pixel spacings is filled by the grains around it, a wider one becomes a notIndexed grain.
The map is changed: it keeps the grain ids, the pixels the minPixel cull drops and the notIndexed pixels the grains absorb, so MATLAB’s second output is the map passed. Run on ebsd.copy() to keep the map as it was.
Input
ebsd |
EBSD, a map of the plane, or EBSD3, a map of volumes |
Keywords
| keyword | default | description |
|---|---|---|
angle |
15*degree |
the misorientation angle above which neighbouring pixels belong to different grains; a pair [high, low] also keeps the low angle boundaries between low and high as grains.innerBoundary; a list of an angle or a pair per phase gives every phase its own |
threshold |
None |
the same as angle, which it replaces when given |
criterion |
None |
a grainBoundaryCriterion instead of the angle: gbcAngle with thresholds per phase, gbcSoft for a soft threshold, gbcEqual for a property that must agree, gbcCustom for a rule of your own, gbcFMC with every parameter of fast multiscale clustering |
minPixel |
1 |
the smallest number of pixels of a grain; the pixels of an indexed grain that would be smaller are marked notIndexed and the grains reconstructed again |
alpha |
3.1 |
the bound of the decomposition in pixel spacings: a not indexed region narrower than 2 alpha is filled (map of the plane) |
removeQuadruplePoints |
False |
split every point where four pixels of a square grid meet into two triple points, joining the diagonal pair the criterion connects more (map of the plane) |
mcl |
None |
(p, maxIter), Markov clustering of the links between the pixels before the grains are formed, the inflation power p (1.4 in MATLAB) and the number of iterations (4); with a soft criterion it merges grains a hard threshold would split (map of the plane) |
fmc |
None |
fast multiscale clustering with the sharpness cmaha, larger giving more grains; gbcFMC as the criterion takes its other parameters (map of the plane) |
verbose |
False |
report the cluster hierarchy of fast multiscale clustering |
backend |
None |
‘numba’ or ‘numpy’, the loops of the decomposition and the segmentation; by default the preference ‘kernels’ (map of the plane) |
grainId |
False |
join the pixels of one grain id stored with the map, ebsd.prop[‘grainId’] or the voxels’ ebsd.grainId, instead of a criterion on the orientations |
Output
grains |
grain2d, or grain3d for a map of volumes; ebsd.grainId numbers the grain of every pixel |
Example
Reconstruct grains in the small Forsterite sample and overlay their boundaries on an orientation map. The first call downloads and caches the sample file; later calls reuse it.
import numpy as np
import matplotlib.pyplot as plt
from mtex import mtexdata, calcGrains, degree, plot, hold
ebsd = mtexdata('small', verbose=False)['Forsterite']
grains = calcGrains(ebsd, angle=10*degree, minPixel=5)
print('Grains:', grains.size)
print('Grain ids assigned to pixels:', np.unique(ebsd.grainId)[:8])
plot(ebsd, ebsd.orientations)
hold(True)
plot(grains.boundary, lineColor='black', lineWidth=1.5)
hold(False)
plt.show()
The threshold is illustrative. calcGrains writes grain ids into ebsd and may change pixels when minPixel removes small grains; call it on ebsd.copy() when the original map is needed.
Grains: 15
Grain ids assigned to pixels: [0 1 2 3 4 5 6 7]

References
- F. Bachmann, R. Hielscher, H. Schaeben, Grain detection from 2d and 3d EBSD data - Specification of the MTEX algorithm, Ultramicroscopy 111 (2011) 1720-1733
- C. McMahon, B. Soe, A. Loeb, A. Vemulkar, M. Ferry, L. Bassman, Boundary identification in EBSD data with a generalization of fast multiscale clustering, Ultramicroscopy 133 (2013) 16-25
See also
GrainReconstruction, GrainReconstructionAdvanced, GrainReconstructionMCL, gbcAngle, grain2d.merge, smoothBoundary
Used on
CrystalShapes, OrientationFundamentalRegion, EBSD3Analysis, EBSD3Plotting, Grains3DBoundaries, Grains3DReconstruction, Grains3DSmoothing, EBSD2ODF, EBSDDenoising, EBSDFilling, EBSDGROD, EBSDGrid
MATLAB’s EBSD3.calcGrains
source
Citing this page.
This page is part of the documentation of
MTEX, a free and open
source MATLAB toolbox for analyzing and modeling crystallographic textures.
It was written by The MTEX Developers and is published at
https://mtex-toolbox.github.io/EBSD3.calcGrains_py.html.
If you use MTEX, or reuse text or figures from this page, in your research,
please cite
F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63
BibTeX
@article{bachmann2010mtex,
author = {F. Bachmann and R. Hielscher and H. Schaeben},
title = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
journal = {Solid State Phenomena},
volume = {160},
pages = {63-68},
year = {2010},
doi = {10.4028/www.scientific.net/SSP.160.63},
url = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}
Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.