-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresize.m
30 lines (23 loc) · 903 Bytes
/
resize.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
function res_vol3d = resize(vol3d, flag)
% Updated 28/09/2024
% By Shokoufeh Golshani
% =========================================================================
% This function reduces the size of the Field matrix by a factor of 3 by
% averaging every group of three adjacent voxels. This process combines
% smaller neighboring voxels into a single larger voxel, effectively
% downscaling the matrix while preserving the overall data structure.
% =========================================================================
if flag == 0
res_vol3d = vol3d;
else
for r1 = 1:fix(size(vol3d, 3)/3)
r1_vol3d(:,:,r1) = sum(vol3d(:,:,r1*3-2:r1*3), 3);
end
for r2 = 1:fix(size(vol3d,2)/3)
r2_vol3d(:,r2,:) = sum(r1_vol3d(:,r2*3-2:r2*3,:), 2);
end
for r3 = 1:fix(size(vol3d,1)/3)
res_vol3d(r3,:,:) = sum(r2_vol3d(r3*3-2:r3*3,:,:), 1)/27;
end
end
end