A method of grain2d.

the grains joined into one along given boundaries, by pairs of ids, by a label per grain, below a misorientation angle, or every inclusion into the grain around it; MATLAB’s merge

Syntax

merged = grains.merge(grains.boundary['Forsterite', 'Forsterite'])

Every pair of grains sharing a segment of the boundary.

merged = grains.merge(np.array([[1, 2], [5, 9]]))

The pairs of these grain ids.

merged = grains.merge(grains.neighbors(matrix=True))

The pairs a sparse matrix over the ids marks.

merged = grains.merge(threshold=5*degree)

Neighbours of a misorientation below 5 degree.

merged = grains.merge(inclusions=True, maxSize=5)

Every inclusion of fewer than 5 pixels into its host.

merged = grains.merge(inclusions=True, host=grains.numPixel > 100)

Inclusions only into large grains.

parentId = grains.merge(threshold=5*degree, testRun=True)

The parent ids, nothing merged.

Description

Two grains go into one when a criterion joins them, directly or through a chain of other grains. Every criterion given applies at once: pairs or labels, a threshold and inclusions together join what any of them joins.

Grains of two phases are merged only by an inclusion, which then takes the phase and the orientation of its host. A pair of two phases is passed over, and a label spanning phases joins the grains of each phase apart, where MATLAB joins them and gives the merged grain the largest phase id.

The pixel counts of the parts add up, the mean orientation is their mean weighted by the pixels (MATLAB’s calcMeanOrientation, always done here) and GOS their weighted mean. The boundary between the parts becomes inner boundary. The merged grains carry the ids of their parts as childId, and the grains passed get parentId, the id of the merged grain each went into, which MATLAB returns as a second output. MATLAB’s merge at a triple point list, grains.merge(tP), is not provided.

Input

grains grain2d
pairs what is merged: a grainBoundary, whose segments join the grains on both sides; an (n, 2) array of grain ids; a square matrix or sparse matrix M over the ids, M[i, j] nonzero joining the grains of ids i + 1 and j + 1; or a label per grain, the grains of one label joined

Keywords

keyword default description
threshold None join the neighbours whose mean orientations differ by less than this angle
inclusions None True to join every inclusion, a grain surrounded by one other grain, to that host; a mask over the grains to join only the inclusions it marks
host None mask over the grains of those that may take an inclusion
maxSize inf the inclusions joined are those of fewer pixels
testRun False return the parent id of every grain instead of the merged grains, the grains passed left unchanged

Output

merged grain2d, the merged grains, numbered from 1
parentId array, with testRun: the id in the merged list of every grain

Example

Join one neighbouring pair of reconstructed Forsterite grains and inspect the parent id mapping. The small sample is downloaded and cached on first use.

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)
pair = grains.neighbors()[:1]
parent = grains.merge(pair, testRun=True)
merged = grains.merge(pair)
print('Merged grain ids:', pair.tolist())
print('Grain count before and after:', grains.size, merged.size)
print('Preview agrees with parentId:', np.array_equal(parent, grains.parentId))
print('Total pixel count preserved:', int(grains.numPixel.sum()) == int(merged.numPixel.sum()))
plot(grains.boundary, lineColor='lightgray', lineWidth=3)
hold(True)
plot(merged.boundary, lineColor='black', lineWidth=1)
hold(False)
plt.show()

The pair is chosen only to demonstrate the operation; an analysis should select boundaries using a physical criterion. Grey traces show the original network and black the merged outlines. parentId is stored on the original grains. Update any pixel-to-parent mapping explicitly before using the merged grains with EBSD measurements; merge does not rewrite ebsd.grainId.

Merged grain ids: [[1, 2]]
Grain count before and after: 15 14
Preview agrees with parentId: True
Total pixel count preserved: True

Example output for grain2d.merge

See also

grain2d.isInclusion, grain2d.neighbors, calcGrains, GrainMerge, parentGrainReconstructor

Used on

LowLevelParentGrainReconstruction, MaParentGrainReconstructionAdvanced

MATLAB’s grain2d.merge

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/grain2d.merge_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.