def grafting(im_hosting, im_patch, im_patch_mask=None):
"""
Take an hosting image, an image patch and a patch mask (optional) of the same dimension and in the same real space.
It crops the patch (or patch mask if present) on the hosting image, and substitute the value from the patch.
:param im_hosting:
:param im_patch:
:param im_patch_mask:
:return:
"""
np.testing.assert_array_equal(im_hosting.affine, im_patch.affine)
if im_patch_mask is not None:
np.testing.assert_array_equal(im_hosting.affine, im_patch_mask.affine)
if im_patch_mask is None:
patch_region = im_patch.get_data().astype(np.bool)
else:
patch_region = im_patch_mask.get_data().astype(np.bool)
new_data = np.copy(im_hosting.get_data())
new_data[patch_region] = im_patch.get_data()[patch_region]
# np.place(new_data, patch_region, im_patch.get_data())
return set_new_data(im_hosting, new_data)
评论列表
文章目录