-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathclean4fem.m
87 lines (74 loc) · 2.91 KB
/
clean4fem.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
function [ret,indSmallCi] = clean4fem(ebsd,minSize,minCi,angle)
% *clean4fem* removes data from inaccurate pixels and
% assigns them with the data from the surrounding grain
%
% pixels are considered inaccurate if
% - their CI is lower than allowed minimum, or
% - they belong to grain whose px size is lower than allowed minimum
%
% % Syntax
% clean4fem(ebsd,minSize,minCi,angle)
%
% % Input
% ebsd - raw ebsd data to be cleaned up (required)
% minSize - minimum allowed grain size [in px] (default: 25 px)
% minCi - minimum allowed confidence index (default: 0.1)
% angle - threshold angle for grain reconstruction (default: 15 deg)
% --------------------------
% written by
% Marat I. Latypov (GT Lorraine)
% marat.latypov@georgiatech-metz.fr
% March 2015
% --------------------------
%% remove inaccurate pixels
% segment grains
[grains,ebsd.grainId,ebsd.mis2mean] = calcGrains(ebsd,'angle',angle*degree);
figure; plot(ebsd)
set(gcf,'renderer','zBuffer')
% remove non-indexed pixels
cleanEbsd = ebsd;
cleanEbsd('notIndexed') = [];
% check if CI or MAD properties exist
try
indSmallCi = cleanEbsd.ci <= minCi;
catch ME
if strcmp(ME.identifier,'MATLAB:noSuchMethodOrField')
try
indSmallCi = cleanEbsd.confidenceindex <= minCi;
catch ME
if strcmp(ME.identifier,'MATLAB:noSuchMethodOrField')
try
indSmallCi = cleanEbsd.mad <= minCi;
catch ME
if strcmp(ME.identifier,'MATLAB:noSuchMethodOrField')
fprintf(1,'WARNING: no CI property found! Cleaning of pixels CI will be skipped');
indSmallCi = false(numel(ebsd.x),1);
end
end
end
end
end
end
% remove pixels with low CI
cleanEbsd(indSmallCi) = [];
% remove pixels of tiny grains
indSmallSize = grains.grainSize < minSize;
cleanEbsd(grains(indSmallSize)) = [];
% plot data without inaccurate points
figure; plot(cleanEbsd)
set(gcf,'renderer','zBuffer')
% identify grains with 15 degree boundary:
[cleanGrains,cleanEbsd.grainId,cleanEbsd.mis2mean] = calcGrains(cleanEbsd,'angle',angle*degree);
%% assign good values
poly = cleanGrains.poly;
for ii = 1:max(cleanEbsd.grainId)
v = cleanGrains.V(poly{ii},:);
inside = inpolygon(ebsd.x,ebsd.y,v(:,1),v(:,2));
ebsd(inside).grainId = cleanGrains(ii).id;
ebsd(inside).phase = cleanGrains(ii).phase;
ebsd(inside).rotations = cleanGrains(ii).meanOrientation;
end
figure; plot(ebsd)
set(gcf,'renderer','zBuffer')
ret = ebsd;
end