The script is to calculate the global void ratio of the sample based on the voxel calculation

%%%%%%%%%%%%%%%%%%%%%%%

clc
clear all

tic

% Read different images to stack
listOfimages=dir('eight_spheres\*.tif');
numberOftifs=numel(listOfimages);

for i=1:numberOftifs
     imageName=strcat('eight_spheres\','data',num2str(i),'r.tif');
     I{i}=imread(imageName);
end

% 2D stacks to 3D array
threeDarray=cat(3,I{1,1},I{1,2});

for i=3:numberOftifs
     threeDarray=cat(3,threeDarray,I{1,i});
end

[A,B,C]=size(threeDarray);

threeDarray = logical(threeDarray);

% GLOBAL VIOD RATIO CALCULATION

sliceImage=I{1,1};
Row=numel(sliceImage(:,1));
Column=numel(sliceImage(1,:));

% Find n = 0 values which consist of void space.
n=length(find(threeDarray==0));
% Void ratio
GVR = n/(A*B*C-n);

fprintf('The void ratio of the whole sample is: %.4g \n',GVR);
toc