Skip to content

Instantly share code, notes, and snippets.

@kilir
kilir / kax_demo.m
Last active March 17, 2021 17:13
neighborhood misorientation axes (demo and function) #mtexScript
mtexdata sharp
%make sure grain boundaries are not considered
[grains, ebsd.grainId] = ebsd.calcGrains;
% % smooth the data
f = halfQuadraticFilter;
ebsd = smooth(ebsd,f);
% make a single phase, gridified ebsd
ebsd =ebsd('c').gridify;
@kilir
kilir / grain_segmentation_demo.m
Created April 9, 2019 22:48
grain segmentation demo
% lets's have some data
mtexdata olivine
% Let's take a crop of the data
% This can also be accomplished interactively by:
% plot(ebsd)
% [ebsd,rec] = selectInteractive(ebsd);
ebsd = ebsd(inpolygon(ebsd,[152 296 427 313]))
plot(ebsd)
%% calculating grains
% In mtex, there are currently three different approaches to compute grains
@kilir
kilir / interphase_sliptransfer.m
Created April 5, 2019 07:51
demo for interphase slip transfer(m') #mtexScript
%% example how to compute inter-phase slip transmission (mprime)
%% get some example data
mtexdata forsterite
%for simplicity restrict phases and fill
[grains, ebsd.grainId] = ebsd.calcGrains;
ebsd(grains(grains.grainSize < 50)) =[];
ebsd = fill(ebsd);
[grains, ebsd.grainId] = ebsd.calcGrains;
@kilir
kilir / ellipse.m
Created October 2, 2018 17:54
Annotate an ellipse #mtexScript
function h = ellipse(r,a,b,varargin)
% annotate an ellipse
%
% Input
% r - @rotation specifying the ellipse position
% a,b - long/short half axes of ellipse in radian
%
h = [];
rho=(0:1:360)*degree;
@kilir
kilir / calcTDF.m
Last active June 22, 2019 19:01
working with boundary trend (= direction in a plane) distributions #mtexScript
function [totfreq, bc, azi]=calcTDF(g,varargin)
% calc circular axis/ trend distribution function of grain long axes
% OR grain boundary segments or from a list of angles for axial data (0:pi)
%
% Syntax:
% [freq,bc] = calcTDF(smoothgrains.boundary('indexed'))
% or
% [freq,bc] = calcTDF(smoothgrains('indexed'))
%
@kilir
kilir / pfIntensity.m
Last active August 9, 2023 07:50
calculate pfJ using S2Fun or manual calulation #mtexScript
function [pfTindex, m, pfg_max] = pfIntensity(odf,h)
% calculate pfJ using S2Fun
% input:
% odf - odf
% h - Miller
% output:
% pfTindex - pole figure J index
% m - multiplicity (needs to be considered when comparing pfJ of different h)
% pfmax - max of pf
@kilir
kilir / misor_boundary_colorcoding_demo.m
Last active June 22, 2019 18:56
demo on a single olivine grain to show a possible option to color misorientation axes #mtexScript
% import demo data
mtexdata forsterite
% prepare some data that might look interesting
[grains, ebsd.grainId, ebsd.mis2mean]=calcGrains(ebsd);
ebsd=ebsd(grains(grains.grainSize>100 & grains.phase==1)); %discard all small grains and non-forsterite grains before labeling
[grains, ebsd.grainId, ebsd.mis2mean]=calcGrains(ebsd,'unitcell');
% plot grains and find an interesting one
om=ipfHSVKey(ebsd('f').CS,ebsd('f').CS);
om.maxAngle=10*degree;
@kilir
kilir / loadPhaseMap.m
Last active March 27, 2024 10:19
Create fake ebsd from a grain boundary, particle and/or phase map to use @grain2d functionalities from mtex on those #mtexScript
function [ebsd, grains]=loadPhaseMap(varargin)
% Load a phase map and create "ebsd" which can be used with some
% of the avaiable tools for grain/grainboundary analysis
%
% Three cases are be distinguished.
%
% 1) Single phase,tightly packed no matrix ('single')
% input: boundary map - binary image ("white" boundaries, value should be 255)!
% output: ebsd with grains of distinct, nonsense orientation and notIndexed
% at the boundaries
@kilir
kilir / BinghamSphericalFunction.m
Created February 10, 2018 12:43
Some experiment with S2FunctionHarminc to create a Bingham distribution #mtexScript
function SF = BinghamSphericalFunction(r,Z,varargin)
% define a Bingham Distribution on a sphere
%
% Input
% r - @ rotation
% Z - 3-by-1 smoothing parameter with Z(1)>=Z(2)>=Z(3), Z3<0
% or diagonal matrix with Z1, Z2 ,Z3
% Z1=Z2 rotationally symmetric unimodal distribution
% Z1<<Z2 (partial girdle distribution
%
@kilir
kilir / crystal_shape_demo.m
Last active May 25, 2018 15:49
demo to plot crystal shapes at user defined positions in a map #mtexScript
% crystal shape demo
% needs @crystalShape avaiable in mtex 4.5.3
% script plots a map and the user can select points where a little crystal shape
% will be dispalyed -crystal will be cc according to the map
mtexdata titanium
[grains,ebsd.grainId]=calcGrains(ebsd,'angle',5*degree);
% plot something
cs=ebsd('t').CS;
f=newMtexFigure;