-
Notifications
You must be signed in to change notification settings - Fork 181
/
GrainSpatialPlots.m
182 lines (132 loc) · 5 KB
/
GrainSpatialPlots.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
%% Plotting
%
%%
% We start by importing some EBSD data and reconstructing some grains
% import a demo data set
mtexdata forsterite silent
plotx2east
% consider only indexed data for grain segmentation
ebsd = ebsd('indexed');
% perform grain segmentation
[grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd);
%% Phase maps
% When using the <grain2d.plot.html |plot|> command without additional
% argument the associated color is defined by color stored in the crystal
% symmetry for each phase
close all
plot(grains)
grains('Fo').CS.color
%%
% Accordingly, changing the color stored in the crystal symmetry changes the
% color in the map
grains('Fo').CS.color = str2rgb('salmon')
plot(grains)
%%
% The color can also been specified directly by using the option
% |FaceColor|. Note, that this requires the color to be specified by RGB
% values.
% detect the largest grain
[~,id] = max(grains.area);
% plot the grain in dark black with some transparency
hold on
plot(grains(id),'FaceColor','darkgray','FaceAlpha',0.5)
hold off
%% Orientation Maps
% Coloring grains according to their mean orientations is very similar to
% EBSD maps colored by orientations. The most important thing is that the
% misorientation can only extracted from grains of the same phase.
% the implicit way
plot(grains('Fo'),grains('fo').meanOrientation)
%%
% This implicit way gives no control about how the color is computed from
% the meanorientation. When using the explicit way by defining a
% orientation to color map
% this defines a ipf color key
ipfKey = ipfColorKey(grains('Fo'));
%%
% we can set the inverse pole figure direction and many other properties
ipfKey.inversePoleFigureDirection = xvector;
% compute the color from the meanorientation
color = ipfKey.orientation2color(grains('Fo').meanOrientation);
% and use them for plotting
plot(grains('fo'),color)
%% Plotting arbitrary properties
% As we have seen in the previous section the |plot| command accepts as
% second argument any list of RGB values specifying a color. Instead of RGB
% values the second argument can also be a list of values which are then
% transformed by a colormap into color.
%
%%
% As an example we colorize the grains according to their aspect ratio.
plot(grains,grains.aspectRatio)
%%
% we see that we have a very elongated grain which makes it difficult to
% distinguish the aspect ration of the other grains. A solution for this is
% to specify the values of the aspect ration which should mapped to the
% top and bottom color of the colormap
setColorRange([1 5])
%% Colorizing circular properties
% Sometimes the property we want to display is a circular, e.g., the
% direction of the grain elongation. In this case it is important to use a
% circular colormap which assign the same color to high values and low
% values. In the case of the direction of the grain elongation the angles 0
% and 180 should get the same color since they represent the same
% direction.
% consider only elongated grains
alongated_grains = grains(grains.aspectRatio > 1.5);
% get the grain elongation
dir = alongated_grains.principalComponents;
% transfer this into degree and project it into the interval [0,180]
dir = mod(dir./degree,180);
% plot the direction
plot(alongated_grains,dir,'micronbar','off')
% change the default colormap to a circular one
mtexColorMap HSV
% display the colormap
mtexColorbar
%% Plotting the orientation within a grain
% In order to plot the orientations of EBSD data within certain grains one
% first has to extract the EBSD data that belong to the specific grains.
% let have a look at the biggest grain
[~,id] = max(grains.area)
% and select the corresponding EBSD data
ebsd_maxGrain = ebsd(ebsd.grainId == id)
% the previous command is equivalent to the more simpler
ebsd_maxGrain = ebsd(grains(id));
%%
% compute the color out of the orientations
color = ipfKey.orientation2color(ebsd_maxGrain.orientations);
% plot it
plot(ebsd_maxGrain, color,'micronbar','off')
% plot the grain boundary on top
hold on
plot(grains(id).boundary,'linewidth',2)
hold off
%% Visualizing directions
%
% We may also visualize directions by arrows placed at the center of the
% grains.
% load some single phase data set
mtexdata csl
% compute and plot grains
[grains,ebsd.grainId] = calcGrains(ebsd);
plot(grains,grains.meanOrientation,'micronbar','off','figSize','large')
% next we want to visualize the direction of the 100 axis
dir = grains.meanOrientation * Miller(1,0,0,grains.CS);
% the length of the vectors should depend on the grain diameter
len = 0.25*grains.diameter;
% arrows are plotted using the command quiver. We need to switch of auto
% scaling of the arrow length
hold on
quiver(grains,len.*dir,'autoScale','off','color','black')
hold off
%% Labeling Grains
% In the above example the vectors are centered at the centroids of the
% grains. Other elements
% only the very big grains
big_grains = grains(grains.grainSize>1000);
% plot them
plot(big_grains,big_grains.meanOrientation,'micronbar','off')
% plot on top their ids
text(big_grains,int2str(big_grains.id))
%#ok<*NASGU>