def atlas_statistics(file_list, atlas_list):
    """
    For each atlas name provided it Ć’calculates for the input image the mean for each region in the atlas and saves it to a TSV file.
    :param in_image: A Nifti image
    :param in_atlas_list: List of names of atlas to be applied
    :return: List of paths to tsv files
    """
    from os import getcwd
    from os.path import abspath, join
    from nipype.utils.filemanip import split_filename
    from clinica.utils.atlas import AtlasAbstract
    from clinica.utils.statistics import statistics_on_atlas
    from clinica.utils.stream import cprint

    orig_dir, base, ext = split_filename(file_list)
    atlas_classes = AtlasAbstract.__subclasses__()
    atlas_statistics_list = []
    for atlas in atlas_list:
        for atlas_class in atlas_classes:
            if atlas_class.get_name_atlas() == atlas:
                #out_atlas_statistics = abspath(join(getcwd(), base + '_space-' + atlas + '_map-graymatter_statistics.tsv'))
                out_atlas_statistics = abspath(
                    join('./' + base + '_space-' + atlas +
                         '_map-graymatter_statistics.tsv'))
                cprint(out_atlas_statistics)
                statistics_on_atlas(file_list, atlas_class(),
                                    out_atlas_statistics)
                atlas_statistics_list.append(out_atlas_statistics)

                break

    return atlas_statistics_list
Example #2
0
def weights_to_nifti(weights, atlas, output_filename):
    """

    Args:
        atlas:
        weights:
        output_filename:

    Returns:

    """
    from clinica.utils.atlas import AtlasAbstract

    atlas_path = None
    atlas_classes = AtlasAbstract.__subclasses__()
    for atlas_class in atlas_classes:
        if atlas_class.get_name_atlas() == atlas:
            atlas_path = atlas_class.get_atlas_labels()

    if not atlas_path:
        raise ValueError("Atlas path not found for atlas name " + atlas)

    atlas_image = nib.load(atlas_path)
    atlas_data = atlas_image.get_fdata(dtype="float32")
    labels = list(set(atlas_data.ravel()))
    output_image_weights = np.array(atlas_data, dtype="f")
    for i, n in enumerate(labels):
        index = np.array(np.where(atlas_data == n))
        output_image_weights[index[0, :], index[1, :],
                             index[2, :]] = weights[i]

    affine = atlas_image.get_affine()
    header = atlas_image.get_header()
    output_image = nib.Nifti1Image(output_image_weights, affine, header)
    nib.save(output_image, output_filename)
Example #3
0
def atlas_statistics(in_image, atlas_list):
    """
    For each atlas name provided it calculates for the input image the mean for each region in the atlas and saves it to a TSV file.

    Args:
        in_image: A Nifti image
        atlas_list: List of names of atlas to be applied

    Returns:
        List of paths to TSV files
    """
    from os.path import abspath, join
    from nipype.utils.filemanip import split_filename
    from clinica.utils.atlas import AtlasAbstract
    from clinica.utils.statistics import statistics_on_atlas
    from clinica.utils.filemanip import get_subject_id
    from clinica.utils.ux import print_end_image
    subject_id = get_subject_id(in_image)

    orig_dir, base, ext = split_filename(in_image)
    atlas_classes = AtlasAbstract.__subclasses__()
    atlas_statistics_list = []
    for atlas in atlas_list:
        for atlas_class in atlas_classes:
            if atlas_class.get_name_atlas() == atlas:
                out_atlas_statistics = abspath(
                    join('./' + base + '_space-' + atlas +
                         '_map-graymatter_statistics.tsv'))
                statistics_on_atlas(in_image, atlas_class(),
                                    out_atlas_statistics)
                atlas_statistics_list.append(out_atlas_statistics)
    print_end_image(subject_id)
    return atlas_statistics_list
Example #4
0
def atlas_statistics(in_image, in_atlas_list):
    """Generate regional measure from atlas_list in TSV files.

    For each atlas name provided it calculates for the input image the mean
    for each region in the atlas and saves it to a TSV file.

    Args:
        in_image: A Nifti image
        in_atlas_list: List of names of atlas to be applied

    Returns:
        List of paths to TSV files
    """
    from os import getcwd
    from os.path import abspath, join

    from nipype.utils.filemanip import split_filename

    from clinica.utils.atlas import AtlasAbstract
    from clinica.utils.statistics import statistics_on_atlas

    orig_dir, base, ext = split_filename(in_image)
    atlas_classes = AtlasAbstract.__subclasses__()
    atlas_statistics_list = []
    for atlas in in_atlas_list:
        for atlas_class in atlas_classes:
            if atlas_class.get_name_atlas() == atlas:
                out_atlas_statistics = abspath(
                    join(getcwd(),
                         base + "_space-" + atlas + "_statistics.tsv"))
                statistics_on_atlas(in_image, atlas_class(),
                                    out_atlas_statistics)
                atlas_statistics_list.append(out_atlas_statistics)
                break

    return atlas_statistics_list