Skip to content

Commit f80c38e

Browse files
author
Usseglio-Viretta
committed
Update microstructure characterization module to v0.91
1 parent caa10d7 commit f80c38e

10 files changed

+308
-73
lines changed

src/Microstructure_characterization/Function_Connectivity_Algorithm.m

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
unique_cluster = unique(Clusters_tmp); % Unique cluster
1717
unique_cluster(unique_cluster==0)=[]; % Remove background (0) if any
1818
number_cluster = length(unique_cluster); % Number of cluster
19-
cluster_size = zeros(number_cluster,12); % Initialise
19+
cluster_size = zeros(number_cluster,17); % Initialise
2020
% Column
2121
% 1 : cluster number of voxel
2222
% 2 : cluster volume in um3
@@ -29,6 +29,13 @@
2929
% 9 : 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 1)
3030
% 10: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 2)
3131
% 11: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 3)
32+
% 12 : 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face connection 1)
33+
% 13: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face connection 1)
34+
% 14: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face connection 1)
35+
% 15 : 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 1)
36+
% 16: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 2)
37+
% 17: 1= connected cluster, 2=unknown cluster, 3=isolated cluster (face2face connection direction 3)
38+
3239
Connectivity_structure.connected_id=connected_id;
3340
Connectivity_structure.unknown_id=unknown_id;
3441
Connectivity_structure.isolated_id=isolated_id;
@@ -79,6 +86,8 @@
7986
% Cluster does not connect the faces, and do not touch the domain's boundaryies: =3
8087
for current_direction=1:1:3 % Loop on every direction
8188
Clusters_TransportFace2Face.direction(current_direction).array = zeros(Domain_size,'uint8'); % Initialise
89+
Clusters_TransportFromFace1.direction(current_direction).array = zeros(Domain_size,'uint8'); % Initialise
90+
Clusters_TransportFromFace2.direction(current_direction).array = zeros(Domain_size,'uint8'); % Initialise
8291
end
8392

8493
Clusters_LargestIsolatedUnknown.array(Clusters_==1)=connected_id; % Main (largest) cluster
@@ -139,6 +148,77 @@
139148
end
140149
Clusters_TransportFace2Face.direction(3).array(I) = connectivity_id_3;
141150
cluster_size(k,11)=connectivity_id_3;
151+
152+
153+
% % Check if cluster connect to one face
154+
% Along direction 1
155+
if x_min==1
156+
connectivity_id_1 = connected_id; % Connect
157+
elseif y_min==1 || z_min==1 || y_max==Domain_size(2) || z_max==Domain_size(3)
158+
connectivity_id_1 = unknown_id; % Does not connect, but connection actually unknown due to limited field of view
159+
else
160+
connectivity_id_1 = isolated_id; % Does not connect (true isolated cluster)
161+
end
162+
Clusters_TransportFromFace1.direction(1).array(I) = connectivity_id_1;
163+
cluster_size(k,12)=connectivity_id_1;
164+
165+
% Along direction 2
166+
if y_min==1
167+
connectivity_id_2 = 1; % Connect
168+
elseif x_min==1 || z_min==1 || x_max==Domain_size(1) || z_max==Domain_size(3)
169+
connectivity_id_2 = unknown_id; % Does not connect, but connection actually unknown due to limited field of view
170+
else
171+
connectivity_id_2 = isolated_id; % Does not connect (true isolated cluster)
172+
end
173+
Clusters_TransportFromFace1.direction(2).array(I) = connectivity_id_2;
174+
cluster_size(k,13)=connectivity_id_2;
175+
176+
% Along direction 3
177+
if z_min==1
178+
connectivity_id_3 = 1; % Does not connect (true isolated cluster)
179+
elseif y_min==1 || x_min==1 || y_max==Domain_size(2) || x_max==Domain_size(1)
180+
connectivity_id_3 = unknown_id; % Does not connect (true isolated cluster)
181+
else
182+
connectivity_id_3 = isolated_id; % Does not connect (true isolated cluster)
183+
end
184+
Clusters_TransportFromFace1.direction(3).array(I) = connectivity_id_3;
185+
cluster_size(k,14)=connectivity_id_3;
186+
187+
% % Check if cluster connect to one face
188+
% Along direction 1
189+
if x_max==Domain_size(1)
190+
connectivity_id_1 = connected_id; % Connect
191+
elseif y_min==1 || z_min==1 || y_max==Domain_size(2) || z_max==Domain_size(3)
192+
connectivity_id_1 = unknown_id; % Does not connect, but connection actually unknown due to limited field of view
193+
else
194+
connectivity_id_1 = isolated_id; % Does not connect (true isolated cluster)
195+
end
196+
Clusters_TransportFromFace2.direction(1).array(I) = connectivity_id_1;
197+
cluster_size(k,15)=connectivity_id_1;
198+
199+
% Along direction 2
200+
if y_max==Domain_size(2)
201+
connectivity_id_2 = 1; % Connect
202+
elseif x_min==1 || z_min==1 || x_max==Domain_size(1) || z_max==Domain_size(3)
203+
connectivity_id_2 = unknown_id; % Does not connect, but connection actually unknown due to limited field of view
204+
else
205+
connectivity_id_2 = isolated_id; % Does not connect (true isolated cluster)
206+
end
207+
Clusters_TransportFromFace2.direction(2).array(I) = connectivity_id_2;
208+
cluster_size(k,16)=connectivity_id_2;
209+
210+
% Along direction 3
211+
if z_max==Domain_size(3)
212+
connectivity_id_3 = 1; % Does not connect (true isolated cluster)
213+
elseif y_min==1 || x_min==1 || y_max==Domain_size(2) || x_max==Domain_size(1)
214+
connectivity_id_3 = unknown_id; % Does not connect (true isolated cluster)
215+
else
216+
connectivity_id_3 = isolated_id; % Does not connect (true isolated cluster)
217+
end
218+
Clusters_TransportFromFace2.direction(3).array(I) = connectivity_id_3;
219+
cluster_size(k,17)=connectivity_id_3;
220+
221+
142222
end
143223

144224
% Save results in structure
@@ -156,10 +236,20 @@
156236
Clusters_TransportFace2Face.direction(current_direction).connected_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFace2Face.direction(current_direction).array==connected_id))) / Numbervoxel_phase;
157237
Clusters_TransportFace2Face.direction(current_direction).unknown_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFace2Face.direction(current_direction).array==unknown_id))) / Numbervoxel_phase;
158238
Clusters_TransportFace2Face.direction(current_direction).isolated_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFace2Face.direction(current_direction).array==isolated_id))) / Numbervoxel_phase;
239+
240+
Clusters_TransportFromFace1.direction(current_direction).connected_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace1.direction(current_direction).array==connected_id))) / Numbervoxel_phase;
241+
Clusters_TransportFromFace1.direction(current_direction).unknown_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace1.direction(current_direction).array==unknown_id))) / Numbervoxel_phase;
242+
Clusters_TransportFromFace1.direction(current_direction).isolated_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace1.direction(current_direction).array==isolated_id))) / Numbervoxel_phase;
243+
244+
Clusters_TransportFromFace2.direction(current_direction).connected_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace2.direction(current_direction).array==connected_id))) / Numbervoxel_phase;
245+
Clusters_TransportFromFace2.direction(current_direction).unknown_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace2.direction(current_direction).array==unknown_id))) / Numbervoxel_phase;
246+
Clusters_TransportFromFace2.direction(current_direction).isolated_cluster_phasefraction = 100 * sum(sum(sum( Clusters_TransportFromFace2.direction(current_direction).array==isolated_id))) / Numbervoxel_phase;
247+
159248
end
160249
% Save results in structure
161250
Connectivity_structure.Clusters_LargestIsolatedUnknown = Clusters_LargestIsolatedUnknown;
162251
Connectivity_structure.Clusters_TransportFace2Face = Clusters_TransportFace2Face;
163-
252+
Connectivity_structure.Clusters_TransportFromFace1 = Clusters_TransportFromFace1;
253+
Connectivity_structure.Clusters_TransportFromFace2 = Clusters_TransportFromFace2;
164254

165255
end

src/Microstructure_characterization/Function_Discrete_particle_size_PCRF.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
density_fct_parameters.round_value = 3;
145145
density_fct_parameters.smooth_cumulative_fct = true;
146146

147+
% Edge detection
148+
background = 0;
149+
edgewithbackground = false;
150+
147151
for current_phase=1:1:number_phase % Loop over all phases
148152
fprintf ('Current phase calculated: %s\n',INFO.phase(current_phase).name)
149153
code_tmp = INFO.phase(current_phase).code;
@@ -155,7 +159,7 @@
155159

156160
% Edge, watershed
157161
[index_border_phase,~,~,~] = Function_identify_edges(binary_phase);
158-
[index_border_label,~,~,~] = Function_identify_labelsedges(Particle_label_tmp, 0);
162+
[index_border_label,~,~,~] = Function_identify_labelsedges(Particle_label_tmp, background, edgewithbackground);
159163
index_(current_phase).border_phase = index_border_phase;
160164
index_(current_phase).border_label = index_border_label;
161165

src/Microstructure_characterization/Function_Discrete_particle_size_watershed_immersion.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
density_fct_parameters.round_value = 3;
143143
density_fct_parameters.smooth_cumulative_fct = true;
144144

145+
% Edge detection
146+
background = 0;
147+
edgewithbackground = false;
148+
145149
for current_phase=1:1:number_phase % Loop over all phases
146150
fprintf ('Current phase calculated: %s\n',INFO.phase(current_phase).name)
147151
code_tmp = INFO.phase(current_phase).code;
@@ -153,7 +157,7 @@
153157

154158
% Edge, watershed
155159
[index_border_phase,~,~,~] = Function_identify_edges(binary_phase);
156-
[index_border_label,~,~,~] = Function_identify_labelsedges(Particle_label_tmp, 0);
160+
[index_border_label,~,~,~] = Function_identify_labelsedges(Particle_label_tmp, background, edgewithbackground);
157161
index_(current_phase).border_phase = index_border_phase;
158162
index_(current_phase).border_label = index_border_label;
159163

src/Microstructure_characterization/Function_Discrete_particle_size_watershed_immersion_algorithm.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@
329329
if visualize_2D
330330
close(video_handle) % Close video
331331

332+
background = 0;
333+
edgewithbackground = false;
334+
332335
sub_axes_illustration(3).s=subplot(2,2,3,'Parent',Fig_illustration); % Create axes
333336
hold(sub_axes_illustration(3).s,'on'); % Active subplot
334337
slice_image = image(slice_color,'parent',sub_axes_illustration(3).s); % Display the slice
@@ -343,7 +346,7 @@
343346
hold(sub_axes_illustration(3).s,'off'); % Active subplot
344347

345348
% Find watershedlines
346-
[index_border_label,~,~,~] = Function_identify_labelsedges(Label_lake, 0);
349+
[index_border_label,~,~,~] = Function_identify_labelsedges(Label_lake, background, edgewithbackground);
347350
sub_axes_illustration(4).s=subplot(2,2,4,'Parent',Fig_illustration); % Create axes
348351
hold(sub_axes_illustration(4).s,'on'); % Active subplot
349352
tmp = slice_grey; tmp(index_border_label) = 1;

src/Microstructure_characterization/Function_along_direction.m

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,39 @@
2727
for k=1:1:length(p.ignore_value)
2828
different_values(different_values==p.ignore_value(k)) = [];
2929
end
30-
31-
% Minimum
32-
Alongdirection.phase(current_phase).direction(current_direction).val(position,2) = min(different_values);
33-
34-
% Maximum
35-
Alongdirection.phase(current_phase).direction(current_direction).val(position,4) = max(different_values);
3630

37-
% Weighed values
38-
% Initialisation
39-
values=zeros(length(different_values),2);
40-
for current_val=1:1:length(different_values)
41-
values(current_val,1)=different_values(current_val);
42-
values(current_val,2)=sum(sum( slice_== different_values(current_val)));
31+
if ~isempty(different_values)
32+
% Minimum
33+
Alongdirection.phase(current_phase).direction(current_direction).val(position,2) = min(different_values);
34+
35+
% Maximum
36+
Alongdirection.phase(current_phase).direction(current_direction).val(position,4) = max(different_values);
37+
38+
% Weighed values
39+
% Initialisation
40+
values=zeros(length(different_values),2);
41+
for current_val=1:1:length(different_values)
42+
values(current_val,1)=different_values(current_val);
43+
values(current_val,2)=sum(sum( slice_== different_values(current_val)));
44+
end
45+
% Mean
46+
Alongdirection.phase(current_phase).direction(current_direction).val(position,3) = sum(values(:,1).*values(:,2))/sum(values(:,2));
47+
48+
% Standard deviation
49+
% The weighted starndard deviation formula is
50+
% sqrt( sum(wi((xi-<x>)^2) / ( (n-1)/n * sum wi ) )
51+
% With wi the weight of the xi, and <x> the weighted mean (mean_size)
52+
wi = values(:,2);
53+
xi = values(:,1);
54+
n = length(xi);
55+
mean_ = Alongdirection.phase(current_phase).direction(current_direction).val(position,3);
56+
Alongdirection.phase(current_phase).direction(current_direction).val(position,5) = sqrt( sum( wi.*((xi-mean_).^2)) / ( (n-1)/n * sum(wi) ));
57+
else
58+
Alongdirection.phase(current_phase).direction(current_direction).val(position,2) = NaN;
59+
Alongdirection.phase(current_phase).direction(current_direction).val(position,3) = NaN;
60+
Alongdirection.phase(current_phase).direction(current_direction).val(position,4) = NaN;
61+
Alongdirection.phase(current_phase).direction(current_direction).val(position,5) = NaN;
4362
end
44-
% Mean
45-
Alongdirection.phase(current_phase).direction(current_direction).val(position,3) = sum(values(:,1).*values(:,2))/sum(values(:,2));
46-
47-
% Standard deviation
48-
% The weighted starndard deviation formula is
49-
% sqrt( sum(wi((xi-<x>)^2) / ( (n-1)/n * sum wi ) )
50-
% With wi the weight of the xi, and <x> the weighted mean (mean_size)
51-
wi = values(:,2);
52-
xi = values(:,1);
53-
n = length(xi);
54-
mean_ = Alongdirection.phase(current_phase).direction(current_direction).val(position,3);
55-
Alongdirection.phase(current_phase).direction(current_direction).val(position,5) = sqrt( sum( wi.*((xi-mean_).^2)) / ( (n-1)/n * sum(wi) ));
5663

5764
end
5865
end

0 commit comments

Comments
 (0)