merger.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:LabelsManager 作者: SebastianoF 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号