【发布时间】:2018-07-18 08:50:41
【问题描述】:
我正在尝试使两个 .tif 图像的图像形状匹配。
我的方法是在较小图像的底部添加空白切片,直到它们的 Z 轴堆栈编号匹配(假设两个图像的 X 和 Y 具有形状)。我首先将图像转换为 numpy 数组,然后使用 np.concatenate 将一个带有零的数组添加到数组的末尾。
我的代码如下所示:
x = 0
difference = model.shape[1] - image.shape[1]
# This line takes the difference between the larger image's Z stack
# slice number with the smaller image and get the difference between
# their z stack slice number.
while x <= difference:
new_np_array = np.concatenate((the_image_np_array, zeros_np_array), axis=0)
x += 1
但是,这行不通,因为程序基本上定义了相同的变量 3 次。我的问题是,如何在同一个数组上重复函数(np.concatenate)X 次?
【问题讨论】: