我有一个三维图像,形状是DxHxW
。我成功地将图像提取成补丁pdxphxpw
(重叠的补丁)。对于每个补丁,我都会做一些处理。现在,我想从处理过的补丁生成图像,这样新的图像必须与原始图像的形状相同。你能帮我做这件事吗。在
这是我提取补丁的代码
def patch_extract_3D(input,patch_shape,xstep=1,ystep=1,zstep=1):
patches_3D = np.lib.stride_tricks.as_strided(input, ((input.shape[0] - patch_shape[0] + 1) / xstep, (input.shape[1] - patch_shape[1] + 1) / ystep,
(input.shape[2] - patch_shape[2] + 1) / zstep, patch_shape[0], patch_shape[1], patch_shape[2]),
(input.strides[0] * xstep, input.strides[1] * ystep,input.strides[2] * zstep, input.strides[0], input.strides[1],input.strides[2]))
patches_3D= patches_3D.reshape(patches_3D.shape[0]*patches_3D.shape[1]*patches_3D.shape[2], patch_shape[0],patch_shape[1],patch_shape[2])
return patches_3D
这是处理补丁(简单的多个2
^{pr2}$现在,我需要的是从patches_3D,我想把它重塑成原始图像。谢谢
这是示例代码
patch_shape=[2, 2, 2]
input=np.arange(4*4*6).reshape(4,4,6)
patches_3D=patch_extract_3D(input,patch_shape)
print patches_3D.shape
for i in range(patches_3D.shape[0]):
patches_3D[i]=patches_3D[i]*2
print patches_3D.shape
但是,这将反过来,因为您的面片重叠,只有当它们的值在重叠的地方一致时,才会定义良好
更新:这里是一个更安全的版本,平均重叠像素:
^{pr2}$相关问题 更多 >
编程相关推荐