Пример #1
0
    Returns
    ----------
    :return: ``SpatialImage`` instance -- output image and metadata

    Example
    -------
    >>> from timagetk.util import data_path
    >>> from timagetk.components import imread
    >>> from timagetk.algorithms import linearfilter, regionalext, connexe, watershed
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> smooth_img = linearfilter(input_image)
    >>> regext_img = regionalext(smooth_img)
    >>> conn_img = connexe(regext_img)
    >>> output_image = watershed(smooth_img, conn_img)
    """
    if isinstance(image, SpatialImage) and isinstance(seeds, SpatialImage):
        if dtype is None:
            dtype = seeds.dtype
        vt_img, vt_seeds, vt_res = vt_image(image), vt_image(seeds), new_vt_image(seeds, dtype=dtype)
        rvalue = libvtexec.API_watershed(vt_img.c_ptr, vt_seeds.c_ptr, vt_res.c_ptr,
                                         param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_img.free(), vt_seeds.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input images must be a SpatialImage')
        return
add_doc(watershed, libvtexec.API_Help_watershed)
Пример #2
0
    :param *np.dtype* dtype: optional, output image type. By default, the output type is equal to the input type.

    Returns
    ----------
    :return: ``SpatialImage`` instance -- output image and metadata

    Example
    -------
    >>> from timagetk.util import data_path
    >>> from timagetk.components import imread
    >>> from timagetk.algorithms import linearfilter
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> output_image = linearfilter(input_image)
    >>> param_str_2 = '-x 0 -y 0 -z 0 -sigma 2.0'
    >>> output_image = linearfilter(input_image, param_str_2=param_str_2)
    """
    if isinstance(image, SpatialImage):
        if dtype is None:
            dtype = image.dtype
        vt_input, vt_res = vt_image(image), new_vt_image(image, dtype=dtype)
        rvalue = libvtexec.API_linearFilter(vt_input.c_ptr, vt_res.c_ptr,
                                            param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_input.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input image must be a SpatialImage')
        return
add_doc(linearfilter, libvtexec.API_Help_linearFilter)
Пример #3
0
        sum_spatial_image_vz = np.zeros_like(spatial_image_vz[0])
        for ind, sp_img in enumerate(spatial_image_vz):
            sum_spatial_image_vz = sum_spatial_image_vz + sp_img
        mean_spatial_image_vz = sum_spatial_image_vz/len(spatial_image_vz)
        mean_spatial_image_vz = SpatialImage(mean_spatial_image_vz,
                                             voxelsize=spatial_image_vz[0].voxelsize)
        BalImage_vz = BalImage(mean_spatial_image_vz)

        out_BAL_TRSF = BAL_TRSF() #--- BALTRSF instance
        out_BAL_TRSF_ptr = pointer(out_BAL_TRSF)
        libblockmatching.BAL_AllocTransformation(out_BAL_TRSF_ptr, list_trsf[0].trsf_type,
                                                 pointer(list_trsf[0].vx.c_struct))
        out_BAL_TRSF.transformation_unit = list_trsf[0].trsf_unit
        out_BAL_TRSF.mat = list_trsf[0].mat.c_struct #--- BAL_MATRIX instance
        out_BAL_TRSF.vx = BalImage_vx.c_struct #--- BALIMAGE instance
        out_BAL_TRSF.vy = BalImage_vy.c_struct #--- BALIMAGE instance
        out_BAL_TRSF.vz = BalImage_vz.c_struct #--- BALIMAGE instance
        trsf_out = BalTransformation(trsf_type=list_trsf[0].trsf_type,
                                     c_bal_trsf=out_BAL_TRSF)
        for ind, trsf in enumerate(list_trsf):
            trsf.free()
        return trsf_out
    else:
        print('Specify a list of BalTransformation transformations')
        return


add_doc(inv_trsf, libblockmatching.API_Help_invTrsf)
add_doc(apply_trsf, libblockmatching.API_Help_applyTrsf)
add_doc(compose_trsf, libblockmatching.API_Help_composeTrsf)
add_doc(create_trsf, libblockmatching.API_Help_createTrsf)
Пример #4
0
    :param str param_str_1: CELL_FILTER_DEFAULT, by default a dilation is applied

    :param str param_str_2: optional, optional parameters

    :param *np.dtype* dtype: optional, output image type. By default, the output type is equal to the input type.

    Returns
    ----------
    :return: ``SpatialImage`` instance -- output image and metadata

    Example
    -------
    >>> output_image = cell_filter(input_image)
    """
    if isinstance(image, SpatialImage):
        if dtype is None:
            dtype = image.dtype
        if struct_elt is None:
            struct_elt = structuring_element()
        vt_input, vt_res = vt_image(image), new_vt_image(image, dtype=dtype)
        rvalue = libvp.API_cellfilter(vt_input.c_ptr, vt_res.c_ptr, pointer(struct_elt),
                                      param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_input.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input image must be a SpatialImage')
        return

add_doc(morpho, libvtexec.API_Help_morpho)
add_doc(cell_filter, libvp.API_Help_cellfilter)
Пример #5
0
    :param *np.dtype* dtype: optional, output image type. By default, the output type is equal to the input type.

    Returns
    ----------
    :return: ``SpatialImage`` instance -- output image and metadata

    Example
    -------
    >>> from timagetk.util import data_path
    >>> from timagetk.components import imread
    >>> from timagetk.algorithms import regionalext
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> output_image = regionalext(input_image)
    >>> param_str_2 = '-minima -connectivity 26 -h 5'
    >>> output_image = regionalext(input_image, param_str_2=param_str_2)
    """
    if isinstance(image, SpatialImage):
        if dtype is None:
            dtype = image.dtype
        vt_input, vt_res = vt_image(image), new_vt_image(image, dtype=dtype)
        rvalue = libvtexec.API_regionalext(vt_input.c_ptr, vt_res.c_ptr,
                                            param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_input.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input image must be a SpatialImage')
        return
add_doc(regionalext, libvtexec.API_Help_regionalext)
Пример #6
0
    Example
    -------
    >>> from timagetk.util import data_path
    >>> from timagetk.components import imread
    >>> from timagetk.algorithms import linearfilter, regionalext, connexe, watershed
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> smooth_img = linearfilter(input_image)
    >>> regext_img = regionalext(smooth_img)
    >>> conn_img = connexe(regext_img)
    >>> output_image = watershed(smooth_img, conn_img)
    """
    if isinstance(image, SpatialImage) and isinstance(seeds, SpatialImage):
        if dtype is None:
            dtype = seeds.dtype
        vt_img, vt_seeds, vt_res = vt_image(image), vt_image(
            seeds), new_vt_image(seeds, dtype=dtype)
        rvalue = libvtexec.API_watershed(vt_img.c_ptr, vt_seeds.c_ptr,
                                         vt_res.c_ptr, param_str_1,
                                         param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_img.free(), vt_seeds.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input images must be a SpatialImage')
        return


add_doc(watershed, libvtexec.API_Help_watershed)
Пример #7
0
    if False not in conds:
        dtype_list = [sp_img.dtype for ind, sp_img in enumerate(list_spatial_images)]
        comm_type = np.find_common_type(dtype_list, [])
        if list_spatial_masks is None:
            mask_ptr = None
        else:
            list_c_vt_spatial_masks = POINTER(_VT_IMAGE) * len(list_spatial_images)
            c_input_masks = []
            for ind, spatial_mask in enumerate(list_spatial_masks):
                vt_input_mask = vt_image(spatial_mask)
                c_input_masks.append(vt_input_mask.get_vt_image())
            mask_ptr = list_c_vt_spatial_masks( *[pointer(c_input_mask)
                                                for c_input_mask in c_input_masks])
        list_c_vt_images = POINTER(_VT_IMAGE) * len(list_spatial_images)
        c_input_images = []
        for ind, spatial_image in enumerate(list_spatial_images):
            vt_input = vt_image(spatial_image)
            c_input_images.append(vt_input.get_vt_image())
        sp_img_ptr = list_c_vt_images(*[pointer(c_input)
                                        for c_input in c_input_images])
        vt_res = new_vt_image(list_spatial_images[0], dtype=comm_type)
        rvalue = libvtexec.API_meanImages(sp_img_ptr, mask_ptr,
                                          len(list_spatial_images), vt_res.c_ptr,
                                          param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        return out_sp_img
    else:
        raise TypeError('Input images must be a list of SpatialImage')
        return
add_doc(mean_images, libvtexec.API_Help_meanImages)
Пример #8
0
                             np.ndarray(kwds['shape'], kwds['np_type']))
        img_res = BalImage(c_bal_image=c_img_res)

        # --- old API FRED, see plugins
        #    if transformation_type:
        #         param_str_2 = '-trsf-type '+transformation_type+' '+param_str
        #    else:
        #         param_str_2 = param_str

        trsf_out_ptr = libblockmatching.API_blockmatching(
            bal_floating_image.c_ptr, bal_reference_image.c_ptr,
            pointer(c_img_res),
            left_transformation.c_ptr if left_transformation else None,
            init_result_transformation.c_ptr
            if init_result_transformation else None, param_str_1, param_str_2)
        if init_result_transformation is not None:
            # If init_result_transformation is given, this transformation is modified
            # during registration and trsf_out is init_result_transformation
            trsf_out = init_result_transformation
        else:
            trsf_out = BalTransformation(c_bal_trsf=trsf_out_ptr.contents)
        sp_img = img_res.to_spatial_image()
        bal_floating_image.free(), bal_reference_image.free(), img_res.free()
        return trsf_out, sp_img
    else:
        raise TypeError('Input images must be SpatialImage instances')
        return


add_doc(blockmatching, libblockmatching.API_Help_blockmatching)
Пример #9
0
        c_img_res = BAL_IMAGE()
        init_c_bal_image(c_img_res, **kwds)
        allocate_c_bal_image(c_img_res, np.ndarray(kwds['shape'], kwds['np_type']))
        img_res = BalImage(c_bal_image=c_img_res)

        # --- old API FRED, see plugins
        #    if transformation_type:
        #         param_str_2 = '-trsf-type '+transformation_type+' '+param_str
        #    else:
        #         param_str_2 = param_str

        trsf_out_ptr = libblockmatching.API_blockmatching(bal_floating_image.c_ptr,
                                                          bal_reference_image.c_ptr,
                                                          pointer(c_img_res),
                                                          left_transformation.c_ptr if left_transformation else None,
                                                          init_result_transformation.c_ptr if init_result_transformation else None,
                                                          param_str_1, param_str_2)
        if init_result_transformation is not None:
            # If init_result_transformation is given, this transformation is modified
            # during registration and trsf_out is init_result_transformation
            trsf_out = init_result_transformation
        else:
            trsf_out = BalTransformation(c_bal_trsf=trsf_out_ptr.contents)
        sp_img = img_res.to_spatial_image()
        bal_floating_image.free(), bal_reference_image.free(), img_res.free()
        return trsf_out, sp_img
    else:
        raise TypeError('Input images must be SpatialImage instances')
        return
add_doc(blockmatching, libblockmatching.API_Help_blockmatching)
Пример #10
0
    >>> from timagetk.algorithms import regionalext, connexe
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> regext_img = regionalext(input_image)
    >>> output_image = connexe(regext_img)
    """
    if isinstance(image, SpatialImage):
        if dtype is None:
            dtype = image.dtype
        if seeds is None:
            pt_seeds = None
        elif seeds is not None:
            if isinstance(seeds, SpatialImage):
                vt_seeds = vt_image(seeds)
                pt_seeds = vt_seeds.c_ptr
            else:
                raise TypeError('Seeds image must be a SpatialImage')
                return
        vt_input, vt_res = vt_image(image), new_vt_image(image, dtype=dtype)
        rvalue = libvtexec.API_connexe(vt_input.c_ptr, pt_seeds, vt_res.c_ptr,
                                       param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_input.free(), vt_res.free()
        if seeds is not None and isinstance(seeds, SpatialImage):
            vt_seeds.free()
        return out_sp_img
    else:
        raise TypeError('Input image must be a SpatialImage')
        return
add_doc(connexe, libvtexec.API_Help_connexe)
Пример #11
0
    Returns
    ----------
    :return: ``SpatialImage`` instance -- output image and metadata

    Example
    -------
    >>> from timagetk.util import data_path
    >>> from timagetk.components import imread
    >>> from timagetk.algorithms import linearfilter
    >>> img_path = data_path('time_0_cut.inr')
    >>> input_image = imread(img_path)
    >>> output_image = linearfilter(input_image)
    >>> param_str_2 = '-x 0 -y 0 -z 0 -sigma 2.0'
    >>> output_image = linearfilter(input_image, param_str_2=param_str_2)
    """
    if isinstance(image, SpatialImage):
        if dtype is None:
            dtype = image.dtype
        vt_input, vt_res = vt_image(image), new_vt_image(image, dtype=dtype)
        rvalue = libvtexec.API_linearFilter(vt_input.c_ptr, vt_res.c_ptr,
                                            param_str_1, param_str_2)
        out_sp_img = return_value(vt_res.get_spatial_image(), rvalue)
        vt_input.free(), vt_res.free()
        return out_sp_img
    else:
        raise TypeError('Input image must be a SpatialImage')
        return


add_doc(linearfilter, libvtexec.API_Help_linearFilter)