Improve EBSD graph construction and visualization#36
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates the EBSD based 2D graph construction in
src/kanapy/texture.pyand adds example scripts for visual graph inspection in the folderexamples/EBSD_graph_analysis, whereplot_ebsd_graph_manually.pysaves the graph image and summary output in the folderplot_ebsd_graph_manually_result, whilerun_ebsd_analysis_with_graph.pyadds 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.pymean_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
qversus-qquaternion ambiguity is handled before averaging. The final mean quaternion is obtained from the dominant eigenvector of the quaternion accumulator matrix.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.
merge_boundary_artifact_nodes(...)Detects small nodes that are mainly boundary artifacts and merges them into the neighboring node with the closest orientation.
find_similar_regions_by_misorientation(...)Performs the new initial EBSD region segmentation using local pixel to pixel misorientation.
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
neighbors(...)Default connectivity changed from 8 neighbors to 4 neighbors in the 2D EBSD graph path.
merge_nodes(...)After two nodes are merged, the node mean orientation is recomputed from the original pixel orientations.
summarize_labels(...)Node mean orientations are now computed with
mean_orientation_data(...)using the phase crystal symmetry.build_graph_from_labeled_pixels(...)Stores the original pixel rotations in the graph, passes symmetry information into node creation, and skips label
0when adding graph edges.EBSDmap.__init__(...)Uses the new local misorientation based initial segmentation, stores intermediate graph diagnostics, applies boundary artifact pre merge, and supports graph plotting through:
EBSDmap.plot_graph_with_black_marker(...)Kept for compatibility and now delegates to
plot_graph_overlay(...).New examples
Two example scripts are added in:
plot_ebsd_graph_manually.pyRuns 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.run_ebsd_analysis_with_graph.pyKeeps the original EBSD analysis workflow and adds the final graph overlay through
show_graph=True.The manual plotting example produces:
The final image shows the cleaned graph node centers and graph edges on the EBSD IPF map.