-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStep5_plot_local_porosity.m
162 lines (121 loc) · 2.78 KB
/
Step5_plot_local_porosity.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB CODES ACCOMPANYING QUAN ET AL. (2021) PAPER
% CODES CALCULATE POROSITY ON PROCESSED X-RAY CT IMAGES
%
% STEP5: PLOT LOCAL POROSITY
% REFER TO README.MD FOR COMPLETE INSTRUCTION
%
% CITE AND CREDIT:
% SUN ET AL. (2021). POWDER TECHNOLOGY, 388:496-504.
% HTTPS://DOI.ORG/10.1016/J.POWTEC.2021.05.006
%
% TESTED ON MATLAB VERSION 2018(a) OR NEWER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear; close all;
addpath(genpath('BW_figures'));
%% user input
n = 5;% kernel size (L_e by voxel), must be identical with Step 3!!
% read the 3D binary matrix
% type = 'Loose'; for example 1
type = 'Steel'; % for example 2
%%
kernels = num2str(n);
filename = [type '_porosity_' kernels,'.mat'];
load(filename);
%% Prepare variables
rows=sum(sum(output,1),2);
cols=sum(sum(output,1),3);
zs=sum(sum(output,2),3);
rows = squeeze(rows);
cols = squeeze(cols);
[z,ZI]=max(rows);
[y,YI]=max(cols);
[x,XI]=max(zs);
xslice = [XI];
yslice = [YI];
zslice = [ZI];
%% Plot the 3D slices
f = figure
fontsize = 16;
% Select colormap
map = [flipud(jet)];
% map = [parula];
% map = [hsv];
% map = [cool];
% map = [spring];
% map = [summer];
% map = [autumn];
% map = [winter];
% map = [gray];
colormap(map)
hold on
h = slice(output,xslice,[],[]);
h.FaceColor = 'interp';
h.EdgeColor = 'none';
h.DiffuseStrength = 0.8;
h = slice(output,[],yslice,[]);
h.FaceColor = 'interp';
h.EdgeColor = 'none';
h.DiffuseStrength = 0.8;
%
h = slice(output,[],[],zslice);
h.FaceColor = 'interp';
h.EdgeColor = 'none';
h.DiffuseStrength = 0.8;
axis image
box on
bx = gca;
bx.LineWidth = 2;
colorbar
caxis([0 1])
xlabel X(voxel), ylabel Y(voxel), zlabel Z(voxel)
ax = gca;
ax.FontSize = fontsize;
grid on
view([39, 29])
axis image
%% Plot 2D slices
%Prepare section position
sz = size(output);
n = 4; %select how many slices you need
xpos = linspace(1,sz(1),n);
xpos = floor(xpos);
ypos = linspace(1,sz(2),n);
ypos = floor(ypos);
zpos = linspace(1,sz(3),n);
zpos = floor(zpos);
%% Local porosity distribution in three directions
%%Xslices
f = figure
s=slice(output,xpos,[],[])
for i = 1:n
s(i).EdgeColor = 'none'
end
colormap(map);
grid off
axis image
axis off
c = colorbar('FontSize', fontsize);
c.Label.String = 'Porosity';
%%Yslices
f = figure
s=slice(output,[],ypos,[]);
for i = 1:n
s(i).EdgeColor = 'none'
end
axis image
axis off
colormap(map);
c = colorbar('FontSize', fontsize);
c.Label.String = 'Porosity';
%%Zslices
f = figure;
s=slice(output,[],[],zpos);
for i = 1:n
s(i).EdgeColor = 'none'
end
colormap(map);
c = colorbar('FontSize', 16);
c.Label.String = 'Porosity';
axis image
axis off