-
Notifications
You must be signed in to change notification settings - Fork 3
/
readLabDCT.m
90 lines (73 loc) · 2.87 KB
/
readLabDCT.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 resultFile = readLabDCT(filepath)
% The readLabDCT function reads the result file from GrainMapper3D and
% write into a struct file.
% Parameters
% filepath: string of path to the result file
% Haixing Fang on March 22, 2019
fid = H5F.open(filepath);
fapl = H5F.get_access_plist(fid);
DataInfo = h5info(filepath);
for i=1:length(DataInfo.Groups(2).Groups.Datasets)
PropertyName{i} = DataInfo.Groups(2).Groups.Datasets(i).Name;
end
str=strjoin(PropertyName,',')
resultFile.Center = h5read(filepath,'/LabDCT/Center');
resultFile.VoxSize = h5read(filepath,'/LabDCT/Spacing');
resultFile.GIDvol = h5read(filepath,'/LabDCT/Data/GrainId');
resultFile.CompVol = h5read(filepath,'/LabDCT/Data/Completeness');
resultFile.Mask = h5read(filepath,'/LabDCT/Data/PhaseId');
resultFile.Dimension = size(resultFile.GIDvol);
if ~isempty(strfind(str, 'Rodrigues'))
resultFile.RodVec3D = h5read(filepath,'/LabDCT/Data/Rodrigues');
else
fprintf('/LabDCT/Data/Rodrigues property does not exist\n');
end
if ~isempty(strfind(str, 'EulerZXZ'))
resultFile.EulerAngle = h5read(filepath,'/LabDCT/Data/EulerZXZ');
else
fprintf('/LabDCT/Data/EulerZXZ property does not exist\n');
end
if ~isempty(strfind(str, 'IPF001'))
resultFile.IPF001 = h5read(filepath,'/LabDCT/Data/IPF001');
else
fprintf('/LabDCT/Data/IPF001 property does not exist\n');
end
resultFile.SeedID = 1:max(max(max(resultFile.GIDvol)));
for i = resultFile.SeedID
% resultFile.SeedComp(i,1) = mean(resultFile.CompVol(resultFile.GIDvol == i)); % completeness for each grain
resultFile.SeedComp(i,1) = nanmean(resultFile.CompVol(resultFile.GIDvol == i)); % completeness for each grain
end
if ~isempty(strfind(str, 'Rodrigues'))
for i = resultFile.SeedID
ex = resultFile.RodVec3D(:,resultFile.GIDvol == i);
if isempty(ex)
resultFile.RodVec(i,:) = [0 0 0];
else
resultFile.RodVec(i,:) = ex(:,1)'; % each row represents Rodrigues vector for each grain
if sum(ex(:,1)'>2*pi)==0
resultFile.EulerZXZ(i,:)=resultFile.EulerZXZ(i,:)*180/pi; % [degrees]
end
end
end
end
if ~isempty(strfind(str, 'EulerZXZ'))
for i = resultFile.SeedID
ex = resultFile.EulerAngle(:,resultFile.GIDvol == i);
if isempty(ex)
resultFile.EulerZXZ(i,:) = [0 0 0];
else
resultFile.EulerZXZ(i,:) = ex(:,1)'; % each row represents ZXZ Euler angles for each grain
end
resultFile.EulerZXZ(i,:)=resultFile.EulerZXZ(i,:)*180/pi; % [degrees]
end
end
for i = resultFile.SeedID
resultFile.nVox(i,1) = length(find(resultFile.GIDvol == i)); % number of voxels for each grain
end
for i = resultFile.SeedID
[x,y,z] = ind2sub(size(resultFile.GIDvol),find(resultFile.GIDvol == i));
X = mean(x);
Y = mean(y);
Z = mean(z);
resultFile.Coord(i,:) = [X,Y,Z]; % each row represents coodinate for each grain
end