예제 #1
0
def compute_statistic(path_user, path_refs, path_dataset=None, path_visu=None):
    """ aggregate statistics over all his annotations

    :param str path_user: path to user annotation
    :param [str] path_refs: path to annotation of other users
    :param str path_dataset: path to image dataset
    :param str path_visu: path for visualisation (root)
    :return [{}]: list of stat. dictionaries
    """
    assert path_user and path_refs, 'missing user or reference annotation'
    lnds_user, _ = create_consensus_landmarks([path_user])
    lnds_refs, _ = create_consensus_landmarks(path_refs)

    list_stats = []
    name_set, name_user_scale = path_user.split(os.sep)[-2:]
    for csv_name in lnds_user:
        if csv_name not in lnds_refs:
            continue
        im_size = find_image_full_size(path_dataset, name_set,
                                       os.path.splitext(csv_name)[0])
        d_stat = compute_landmarks_statistic(lnds_refs[csv_name],
                                             lnds_user[csv_name],
                                             use_affine=False,
                                             im_size=im_size)
        d_stat.update({
            'name_image_set': name_set,
            'name_user': name_user_scale,
            'landmarks': csv_name
        })
        list_stats.append(d_stat)
        if path_visu is not None and os.path.isdir(path_visu):
            img_name = os.path.splitext(csv_name)[0]
            visual_coannotation(lnds_user[csv_name], lnds_refs[csv_name],
                                path_dataset, path_user, img_name, path_visu)
    return list_stats
def generate_consensus_landmarks(path_set, path_dataset):
    """ generate consensus landmarks for a particular image/landmark set

    :param str path_set: path to the set with annotations
    :param str path_dataset: output dataset path (root)
    :return {str: int}:
    """
    path_annots = list_sub_folders(path_set, '*_scale-*pc')
    logging.debug('>> found annotations: %i', len(path_annots))

    dict_lnds, dict_lens = create_consensus_landmarks(path_annots)

    path_scale = os.path.join(path_dataset, os.path.basename(path_set),
                              TEMPLATE_FOLDER_SCALE % 100)
    create_folder_path(path_scale)
    for name in dict_lnds:
        dict_lnds[name].to_csv(os.path.join(path_scale, name))

    return {os.path.basename(path_set): dict_lens}