-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathebsd_check_quality.m
214 lines (199 loc) · 5.1 KB
/
ebsd_check_quality.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function ebsd_check_quality(ebsd, out_path, varargin)
% EBSD_CHECK_QUALITY Check quality of indexing of Kikuchi diffraction
% patterns.
%
% Input
% ebsd - @EBSD object
% out_path - path to output directory
%
% Options
% save - bool, if 1 (default), write figures to file.
% type - string, {'ang' (default), 'osc', 'astro' or 'emsoft'}.
% to_plot - bool, if 1 (default), show plots and not just save them.
% scalebar - bool, if 1 (default), show a scalebar.
% colorbar - bool, if 1 (default), show colorbar.
%
% Assumes the indexing data file from AstroEBSD is created with the
% astroebsd2mtex script found here (https://github.com/hwagit/mtex-snippets).
%
% Requires the export_fig package to write figures to file
% (https://se.mathworks.com/matlabcentral/fileexchange/23629-export_fig).
%
% Created by Håkon Wiik Ånes ([email protected]), 2019-02-21
% Set default values
save = 1;
type = 'ang';
to_plot = 1;
scalebar = 1;
colorbar = 1;
% Override default values if passed to function
if check_option(varargin, 'save')
save = get_option(varargin, 'save');
end
if check_option(varargin, 'type')
type = get_option(varargin, 'type');
end
if check_option(varargin, 'to_plot')
to_plot = get_option(varargin, 'to_plot');
end
if check_option(varargin, 'scalebar')
scalebar = get_option(varargin, 'scalebar');
end
if check_option(varargin, 'colorbar')
colorbar = get_option(varargin, 'colorbar');
end
% To show figures or not. Get current setting to revert at the end.
figure_visible = get(0, 'DefaultFigureVisible');
set(0, 'DefaultFigureVisible', 'on')
if ~to_plot
set(0, 'DefaultFigureVisible', 'off')
end
% Image resolution
res = '-r200';
% Write mean values for index and reliability to file
if save
fid = fopen(fullfile(out_path, 'ebsd_quality.dat'), 'w');
if strcmp(type, 'ang')
fprintf(fid, 'iq\t\tci\t\tfitn\n%.4f\t%.4f\t%.4f', nanmean(ebsd.iq),...
nanmean(ebsd.ci), nanmean(ebsd.fit));
elseif strcmp(type, 'osc')
fprintf(fid, 'iq\t\tci\t\tfit\n%.4f\t%.4f\t%.4f',...
nanmean(ebsd.imagequality), nanmean(ebsd.confidenceindex),...
nanmean(ebsd.fit));
elseif strcmp(type, 'emsoft')
fprintf(fid, 'iq\t\tci\n%.4f\t%.4f',...
nanmean(ebsd.iq), nanmean(ebsd.ci));
else % astro
fprintf(fid, 'pq\t\tps\t\tmae\t\tbn\n%.4f\t%.4f\t%.4f\t%.4f',...
nanmean(ebsd.pq), nanmean(ebsd.ps), nanmean(ebsd.mae)/degree,...
nanmean(ebsd.bn));
end
fclose(fid);
end
% Plot pattern quality
figure
if ismember(type, {'ang', 'emsoft'})
[~, mP] = plot(ebsd, ebsd.iq);
fname = 'quality_iq.png';
elseif strcmp(type, 'osc')
[~, mP] = plot(ebsd, ebsd.imagequality);
fname = 'quality_iq.png';
else % astro
[~, mP] = plot(ebsd, ebsd.pq);
fname = 'quality_pq.png';
end
mtexColorMap black2white
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
% Plot confidence index
figure
if ismember(type, {'ang', 'emsoft'})
[~, mP] = plot(ebsd, ebsd.ci);
fname = 'quality_ci.png';
elseif strcmp(type, 'osc')
[~, mP] = plot(ebsd, ebsd.confidenceindex);
fname = 'quality_ci.png';
else % astro
[~, mP] = plot(ebsd, ebsd.ps);
fname = 'quality_ps.png';
end
mtexColorMap black2white
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
% Plot pattern fit
if strcmp(type, 'astro')
figure
[~, mP] = plot(ebsd, ebsd.mae);
fname = 'quality_mae.png';
elseif ismember(type, {'ang', 'osc'})
figure
[~, mP] = plot(ebsd, ebsd.fit);
fname = 'quality_fit.png';
end
if ismember(type, {'ang', 'osc', 'astro'})
mtexColorMap white2black
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
end
% Plot orientation similarity metric
if strcmp(type, 'emsoft')
[~, mP] = plot(ebsd, ebsd.osm);
fname = 'quality_osm.png';
end
mtexColorMap black2white
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
% Plot ISM
if strcmp(type, 'emsoft')
[~, mP] = plot(ebsd, ebsd.ism);
fname = 'quality_ism.png';
end
mtexColorMap black2white
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
% Plot average dot product
if strcmp(type, 'emsoft')
[~, mP] = plot(ebsd, ebsd.adp);
fname = 'quality_adp.png';
end
mtexColorMap black2white
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, fname), res);
end
% Plot kernel average misorientation
kam = KAM(ebsd, 'threshold', 2*degree);
figure
[~, mP] = plot(ebsd,kam./degree);
if colorbar
mtexColorbar
end
if ~scalebar
mP.micronBar.visible = 'off';
end
if save
export_fig(fullfile(out_path, 'quality_kam.png'), res);
end
% Revert change
set(0, 'DefaultFigureVisible', figure_visible)
end