我试图提取以某个给定位置(x,y,z)为中心的固定大小的补丁。代码如下:
x = np.random.randint(0,99,(150, 80, 50, 3))
patch_size = 32
half = int(patch_size//2)
indices = np.array([[40, 20, 30], [60, 30, 27], [20, 18, 21]])
n_patches = indices.shape[0]
patches = np.empty((n_patches, patch_size, patch_size,patch_size, x.shape[-1]))
for ix,_ in enumerate(indices):
patches[ix, ...] = x[indices[ix, 0]-half:indices[ix, 0]+half,
indices[ix, 1]-half:indices[ix, 1]+half,
indices[ix, 2]-half:indices[ix, 2]+half, ...]
有谁能告诉我如何使这个工作更快?或者任何其他的选择,如果你能建议它会有很大的帮助。我见过类似的问题在https://stackoverflow.com/a/37901746/4296850中得到了解决,但只适用于2D图像。有人能帮我概括一下这个解决办法吗?你知道吗
我们可以利用基于^{} 的^{} 来获得滑动窗口。More info on use of ^{} based ^{} 。你知道吗
相关问题 更多 >
编程相关推荐