繁体   English   中英

沿 z 轴的中位数堆叠两个 3D numpy 数组并保持较小数组的大小

[英]Stacking two 3D numpy arrays along the median of the z-axis and keep the size of the smaller array

我想根据 z 轴的中位数堆叠两组图像(im-series1 = 32x32x16 和 im_series2 = 32x32x21),并保持相对于 im-series1 1形状的相邻值。

在此处输入图片说明

你应该做的是先裁剪im_series2,然后堆叠。 请注意,有两种方法可以裁剪 im_series 以适合 im_series1,两者都是“中位数”。

import numpy as np
im_series2 = np.ones((32, 32, n)) # this is im_series2 as an example
mid = n // 2
im_series2 = im_series2[:, :, mid-8:mid+8] # this is the cropping. [:,:,2:-3] is also valid
print(im_series2.shape)
im_series1 = np.ones((32, 32, 16)) # this is im_series1 as an example
print(im_series1 .shape)
c = np.concatenate((im_series1 , im_series2), axis=-1) # this concatenates them on the z_axis
print(c.shape)

这输出:

(32, 32, 16)
(32, 32, 16)
(32, 32, 32)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM