[英]how to extract a cube from a 3D volume having a centre point and lengths of X, Y, Z in MATLAB?
In MATLAB, if we assume the starting point of a cube is up-left corner, 在MATLAB中,如果我们假设立方体的起点是左上角,
3D_vol(Start_x : Start_x + SizeX-1, Start_y : Start_y + SizeY-1, Start_z : Start_z + SizeZ-1);
gets a cube having starting points of X, Y, Z and size of each. 得到一个具有X,Y,Z和每个大小的起点的立方体。 Now, if the starting point is the center of the cube, how can I get the cube?
现在,如果起始点是多维数据集的中心 ,我如何获得该多维数据集?
I tried the following, but it is not correct when the size of X/Y/Z is even. 我尝试了以下操作,但是当X / Y / Z的大小为偶数时,这是不正确的。
3D_vol(start_x - (SizeX/2) - 1 : Start_x + (SizeX/2) - 1, ......
3D_vol is a 3d matrix. 3D_vol是3d矩阵。
I am assuming the start points are integers. 我假设起点是整数。
If SizeX
is odd it is easier. 如果
SizeX
为奇数, SizeX
容易。 You have you centre point and (SizeX-1)/2
in each side: 您有中心点,每边都有
(SizeX-1)/2
:
start_x + (-(SizeX-1)/2:(SizeX-1)/2)
That would give you a total of 1+2*(SizeX-1)/2 = SizeX
points. 这将使您总共获得
1+2*(SizeX-1)/2 = SizeX
点。
In case SizeX
is even, your start_x is not actually the centre but one of the closest points to it. 如果
SizeX
是偶数,则start_x实际上不是中心,而是最接近它的点之一。 You should decide if its left or right of centre. 您应该确定它是居中还是居中。 Let's assume left.
让我们假设离开。 Then, on the left side you need the start_x point and
SizeX/2-1
more points. 然后,在左侧,您需要start_x点和
SizeX/2-1
更多点。 the rest would be on the right: 其余的将在右边:
start_x + (-(SizeX/2-1):SizeX/2)
That would give you a total of 1+(SizeX-1)/2-1+SizeX/2 = SizeX
points. 这将使您总共获得
1+(SizeX-1)/2-1+SizeX/2 = SizeX
点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.