Skip to content

Improve EBSD graph construction and visualization#36

Merged
AHartmaier merged 1 commit into
ICAMS:masterfrom
JXRepo:jun_graph_established
May 14, 2026
Merged

Improve EBSD graph construction and visualization#36
AHartmaier merged 1 commit into
ICAMS:masterfrom
JXRepo:jun_graph_established

Conversation

@JXRepo
Copy link
Copy Markdown
Contributor

@JXRepo JXRepo commented May 13, 2026

This PR updates the EBSD based 2D graph construction in src/kanapy/texture.py and adds example scripts for visual graph inspection in the folder examples/EBSD_graph_analysis, where plot_ebsd_graph_manually.py saves the graph image and summary output in the folder plot_ebsd_graph_manually_result, while run_ebsd_analysis_with_graph.py adds the graph image to the standard EBSD analysis plotting workflow.

Main function change

Initial regions are now identified by a BFS based region growing procedure in:

find_similar_regions_by_misorientation(...)

Starting from each unassigned pixel, neighboring pixels are added to the same region when their local misorientation is below the threshold. The misorientation calculation uses the crystal symmetry of the current phase. This replaces the previous scalar angle based initial segmentation and gives a more physically meaningful starting graph before later graph cleanup and node merging.

New functions in texture.py

  1. mean_orientation_data(...)
    Computes the mean orientation of one graph node from its pixel quaternions. Pixel quaternions are normalized first, symmetry equivalent orientations are aligned to a reference orientation, and the q versus -q quaternion ambiguity is handled before averaging. The final mean quaternion is obtained from the dominant eigenvector of the quaternion accumulator matrix.

  2. get_node_boundary_stats(...)
    Computes boundary statistics for one graph node. For each pixel in the node, its local neighbors are checked against the node label to determine whether the pixel lies on the node boundary. The function then reports the number and fraction of boundary pixels, neighboring labels, map edge contact, bounding box size, and bounding box fill fraction.

  3. merge_boundary_artifact_nodes(...)
    Detects small nodes that are mainly boundary artifacts and merges them into the neighboring node with the closest orientation.

  4. find_similar_regions_by_misorientation(...)
    Performs the new initial EBSD region segmentation using local pixel to pixel misorientation.

  5. EBSDmap.plot_graph_overlay(...)
    Plots the final graph directly on the EBSD IPF map. Node centers are shown as black points and graph edges as black lines. The figure can also be saved to file.

Existing functions updated

  1. neighbors(...)
    Default connectivity changed from 8 neighbors to 4 neighbors in the 2D EBSD graph path.

  2. merge_nodes(...)
    After two nodes are merged, the node mean orientation is recomputed from the original pixel orientations.

  3. summarize_labels(...)
    Node mean orientations are now computed with mean_orientation_data(...) using the phase crystal symmetry.

  4. build_graph_from_labeled_pixels(...)
    Stores the original pixel rotations in the graph, passes symmetry information into node creation, and skips label 0 when adding graph edges.

  5. EBSDmap.__init__(...)
    Uses the new local misorientation based initial segmentation, stores intermediate graph diagnostics, applies boundary artifact pre merge, and supports graph plotting through:

show_graph=True
  1. EBSDmap.plot_graph_with_black_marker(...)
    Kept for compatibility and now delegates to plot_graph_overlay(...).

New examples

Two example scripts are added in:

examples/EBSD_graph_analysis/
  1. plot_ebsd_graph_manually.py
    Runs EBSD graph construction, saves the final graph overlay image, and writes a short text summary of the graph in the folder plot_ebsd_graph_manually_result.

  2. run_ebsd_analysis_with_graph.py
    Keeps the original EBSD analysis workflow and adds the final graph overlay through show_graph=True.

The manual plotting example produces:

plot_ebsd_graph_manually_result/ebsd_graph_overlay.png
plot_ebsd_graph_manually_result/ebsd_graph_summary.txt

The final image shows the cleaned graph node centers and graph edges on the EBSD IPF map.

@AHartmaier AHartmaier merged commit 8a69d08 into ICAMS:master May 14, 2026
2 checks passed
@JXRepo JXRepo deleted the jun_graph_established branch May 15, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants