cutter.py 文件源码

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

项目:LabelsManager 作者: SebastianoF 项目源码 文件源码
def apply_a_mask_path(pfi_input, pfi_mask, pfi_output):
    # TODO expose in facade
    """
    Adaptative - if the mask is 3D and the image is 4D, will create a temporary mask,
    generate the stack of masks, and apply the stacks to the image.
    :param pfi_input: path to file 3d x T image
    :param pfi_mask: 3d mask same dimension as the 3d of the pfi_input
    :param pfi_output: apply the mask to each time point T in the fourth dimension if any.
    :return: None, save the output in pfi_output.
    """
    im_input = nib.load(pfi_input)
    im_mask = nib.load(pfi_mask)

    assert len(im_mask.shape) == 3

    if not im_mask.shape == im_input.shape[:3]:
        msg = 'Mask {0} and image {1} does not have compatible dimension: {2} and {3}'.format(
            pfi_input, pfi_mask, im_input, im_mask.shape)
        raise IOError(msg)

    if len(im_input.shape) == 3:
        new_data = im_input.get_data() * im_mask.get_data().astype(np.bool)
    else:
        new_data = np.zeros_like(im_input.get_data())
        for t in range(im_input.shape[3]):
            new_data[..., t] = im_input.get_data()[..., t] * im_mask.get_data().astype(np.bool)

    new_im = set_new_data(image=im_input, new_data=new_data)

    nib.save(new_im, filename=pfi_output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号