栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从Python的修补程序中恢复3D图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从Python的修补程序中恢复3D图像?

但是,这样做会相反,因为您的补丁重叠,只有当它们的值在重叠的地方一致时,才能很好地定义

def stuff_patches_3D(out_shape,patches,xstep=12,ystep=12,zstep=12):    out = np.zeros(out_shape, patches.dtype)    patch_shape = patches.shape[-3:]    patches_6D = np.lib.stride_tricks.as_strided(out, ((out.shape[0] - patch_shape[0] + 1) // xstep, (out.shape[1] - patch_shape[1] + 1) // ystep,      (out.shape[2] - patch_shape[2] + 1) // zstep, patch_shape[0], patch_shape[1], patch_shape[2]),      (out.strides[0] * xstep, out.strides[1] * ystep,out.strides[2] * zstep, out.strides[0], out.strides[1],out.strides[2]))    patches_6D[...] = patches.reshape(patches_6D.shape)    return out

更新:这是平均重叠像素的更安全版本:

def stuff_patches_3D(out_shape,patches,xstep=12,ystep=12,zstep=12):    out = np.zeros(out_shape, patches.dtype)    denom = np.zeros(out_shape, patches.dtype)    patch_shape = patches.shape[-3:]    patches_6D = np.lib.stride_tricks.as_strided(out, ((out.shape[0] - patch_shape[0] + 1) // xstep, (out.shape[1] - patch_shape[1] + 1) // ystep,      (out.shape[2] - patch_shape[2] + 1) // zstep, patch_shape[0], patch_shape[1], patch_shape[2]),      (out.strides[0] * xstep, out.strides[1] * ystep,out.strides[2] * zstep, out.strides[0], out.strides[1],out.strides[2]))    denom_6D = np.lib.stride_tricks.as_strided(denom, ((denom.shape[0] - patch_shape[0] + 1) // xstep, (denom.shape[1] - patch_shape[1] + 1) // ystep,      (denom.shape[2] - patch_shape[2] + 1) // zstep, patch_shape[0], patch_shape[1], patch_shape[2]),      (denom.strides[0] * xstep, denom.strides[1] * ystep,denom.strides[2] * zstep, denom.strides[0], denom.strides[1],denom.strides[2]))    np.add.at(patches_6D, tuple(x.ravel() for x in np.indices(patches_6D.shape)), patches.ravel())    np.add.at(denom_6D, tuple(x.ravel() for x in np.indices(patches_6D.shape)), 1)    return out/denom


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661508.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号