Exemplo n.º 1
0
def evaluate_identity_shape_loc_isomorphism(u1, u2, u3):
    u1_coms, _, _ = utils.decompose(u1, 8, trim=False)
    u2_coms, _, _ = utils.decompose(u2, 8, trim=False)
    u3_coms, _, _ = utils.decompose(u3, 8, trim=False)

    if len(u1_coms) == len(u3_coms):

        sjm_u1_com_ids, sjm_u2_com_ids, sjm_score = map.soft_jaccard_map(
            u1_coms, u2_coms)
        lcm_u1_com_ids, lcm_u2_com_ids, lcm_score = map.location_map(
            u1_coms, u2_coms)

        if map.same_mappings(list(range(len(u1_coms))),
                             list(range(len(u2_coms))), sjm_u1_com_ids,
                             sjm_u2_com_ids, lcm_u1_com_ids, lcm_u2_com_ids):
            mat_score = (sjm_score + lcm_score) / 2
            u1_com_ids = sjm_u1_com_ids
            u2_com_ids = sjm_u2_com_ids
            stub = utils.make_stub(u1_coms, u2_coms, u3_coms, u1_com_ids,
                                   u2_com_ids)
            return mat_score, stub

    mat_score = 0
    u1_com_ids = []
    u2_com_ids = []
    stub = utils.make_stub(u1_coms, u2_coms, u3_coms, u1_com_ids, u2_com_ids)
    return mat_score, stub
Exemplo n.º 2
0
def evaluate_shape_texture_transfer(u1, u2, u3):
    u1_filled = utils.fill_holes(u1)
    u2_filled = utils.fill_holes(u2)
    u3_filled = utils.fill_holes(u3)

    # old_u1_u3_shape_index = jaccard.jaccard_coef(u1_filled, u3_filled)[0]
    #
    # u1_u3_shape_index = soft_jaccard.soft_jaccard(u1_filled, u3_filled)[0]

    u1_texture_index = np.logical_and(
        u1_filled, np.logical_not(u1)).sum() / u1_filled.sum()
    u2_texture_index = np.logical_and(
        u2_filled, np.logical_not(u2)).sum() / u2_filled.sum()
    u3_texture_index = np.logical_and(
        u3_filled, np.logical_not(u3)).sum() / u3_filled.sum()
    u1_u2_texture_index = u1_texture_index - u2_texture_index
    u1_u3_texture_index = u1_texture_index - u3_texture_index

    # _, u1_to_u3_x, u1_to_u3_y = jaccard.jaccard_coef(u1, u3)
    # u1_texture_index, u3_texture_index = utils.texture_index(u1, u3, u1_filled, u3_filled, u1_to_u3_x, u1_to_u3_y)
    # texture_score = 1 - abs(u1_texture_index - u3_texture_index)

    # mat_score = (1 - abs(u1_u3_texture_index) + abs(u1_u2_texture_index) + u1_u3_shape_index) / 3
    mat_score = (1 - abs(u1_u3_texture_index) + abs(u1_u2_texture_index)) / 2

    stub = utils.make_stub(u2_texture_index, u1_u2_texture_index, u3_filled,
                           u2_filled, u1_filled)

    return mat_score, stub
Exemplo n.º 3
0
def evaluate_shape_topo_mapping(u1, u2, u3):
    """
    1) horizontally, u1 and u2 have some common (or very similar)components such that
    an injective mapping exists by the correspondence of similar pairs.
    2) vertically, u1 and u3 share the same topological structure by considering
    two relations, "inside" and "outside".
    :param u1: an binary image
    :param u2: a binary iamge
    :param u3: a binary image
    :return: MAT score
    """

    u1_coms, _, _ = utils.decompose(u1, 8, trim=False)
    u2_coms, _, _ = utils.decompose(u2, 8, trim=False)
    u3_coms, _, _ = utils.decompose(u3, 8, trim=False)

    old_jcm_u1_com_ids, old_jcm_u2_com_ids, old_jcm_score = map.jaccard_map(
        u1_coms, u2_coms)

    jcm_u1_com_ids, jcm_u2_com_ids, jcm_score = map.soft_jaccard_map(
        u1_coms, u2_coms)

    tpm_u1_com_ids, tpm_u3_com_ids, tpm_score = map.topological_map(
        u1_coms, u3_coms)

    mat_score = (jcm_score + tpm_score) / 2

    stub = utils.make_stub(u1_coms, u2_coms, u3_coms, jcm_u1_com_ids,
                           jcm_u2_com_ids, tpm_u1_com_ids, tpm_u3_com_ids)

    return mat_score, stub
Exemplo n.º 4
0
def evaluate_topo_delta_shape_isomorphism(u1, u2, u3):
    u1_coms, _, _ = utils.decompose(u1, 8, trim=False)
    u2_coms, _, _ = utils.decompose(u2, 8, trim=False)
    u3_coms, _, _ = utils.decompose(u3, 8, trim=False)

    tpm_u1_com_ids, tpm_u2_com_ids, tpm_score = map.topological_map(
        u1_coms, u2_coms)

    if 1 == len(tpm_u1_com_ids):
        mat_score = 0
    else:
        mat_score = tpm_score

    stub = utils.make_stub(u1_coms, u2_coms, u3_coms, tpm_u1_com_ids,
                           tpm_u2_com_ids)

    return mat_score, stub
Exemplo n.º 5
0
def evaluate_shape_delta_loc_isomorphism(u1, u2, u3):
    u1_coms, _, _ = utils.decompose(u1, 8, trim=False)
    u2_coms, _, _ = utils.decompose(u2, 8, trim=False)
    u3_coms, _, _ = utils.decompose(u3, 8, trim=False)

    # old_jcm_u1_com_ids, old_jcm_u2_com_ids, old_jcm_score = map.jaccard_map(u1_coms, u2_coms)
    jcm_u1_com_ids, jcm_u2_com_ids, jcm_score = map.soft_jaccard_map(
        u1_coms, u2_coms)

    if 1 == len(jcm_u1_com_ids):
        mat_score = 0
    else:
        mat_score = jcm_score

    stub = utils.make_stub(u1_coms, u2_coms, u3_coms, jcm_u1_com_ids,
                           jcm_u2_com_ids)

    return mat_score, stub
Exemplo n.º 6
0
def evaluate_duplicate(u1, u2):
    scores = []
    u1_to_u2_xs = []
    u1_to_u2_ys = []
    current = u2.copy()
    current_to_u2_x = 0
    current_to_u2_y = 0
    u1_tr = utils.trim_binary_image(u1)
    while current.sum():
        old_score_tmp, old_diff_tmp_to_u1_x, old_diff_tmp_to_u1_y, old_diff_tmp_to_current_x, old_diff_tmp_to_current_y, old_diff_tmp = \
            asymmetric_jaccard.asymmetric_jaccard_coef(u1, current)

        score_tmp, diff_tmp_to_u1_x, diff_tmp_to_u1_y, diff_tmp_to_current_x, diff_tmp_to_current_y, diff_tmp = \
            soft_jaccard.soft_jaccard(u1, current, asymmetric = True)

        if score_tmp < 0.9:
            break

        scores.append(score_tmp)
        u1_to_current_x = (-diff_tmp_to_u1_x) - (-diff_tmp_to_current_x)
        u1_to_current_y = (-diff_tmp_to_u1_y) - (-diff_tmp_to_current_y)
        u1_to_u2_x = u1_to_current_x + current_to_u2_x
        u1_to_u2_y = u1_to_current_y + current_to_u2_y
        u1_to_u2_xs.append(u1_to_u2_x)
        u1_to_u2_ys.append(u1_to_u2_y)

        current = diff_tmp
        current_to_u2_x = diff_tmp_to_current_x + current_to_u2_x
        current_to_u2_y = diff_tmp_to_current_y + current_to_u2_y

    if 1 >= len(scores):
        mat_score = 0
        u1_to_u2_locs = []
    else:
        mat_score = np.mean(scores)
        u1_to_u2_xs = ((np.array(u1_to_u2_xs) - min(u1_to_u2_xs)) /
                       u1_tr.shape[1]).tolist()
        u1_to_u2_ys = ((np.array(u1_to_u2_ys) - min(u1_to_u2_ys)) /
                       u1_tr.shape[0]).tolist()
        u1_to_u2_locs = np.array(list(zip(u1_to_u2_xs, u1_to_u2_ys)))

    stub = utils.make_stub(u1_to_u2_locs)

    return mat_score, stub
Exemplo n.º 7
0
def evaluate_shape_loc_isomorphism(u1, u2, u3):
    """
    1) horizontally, u1 and u2 have some components that are located at the same (or close)
    positions such that an injective mapping can be formed by location correspondence.
    2) horizontally, u1 and u2 have some components that have the same or similar shape such aht
    and injective mapping can be found by shape correspondence.
    3) vertically, u1 and u3 forms a placeholder mapping that requires only that u1 and u3 have the same number
    of components. The placeholder mapping will be initiated by one or more mappings that express the isomorphism
    between (u1, u2) and (u3, opt), where (u1, u2) represents the mappings btw components in u1 and u2 and (u3, opt)
    represents the mappings btw components in u3 and opt.
    :param u1: an binary image
    :param u2: a binary iamge
    :param u3: a binary image
    :return: MAT score
    """

    u1_coms, _, _ = utils.decompose(u1, 8, trim=False)
    u2_coms, _, _ = utils.decompose(u2, 8, trim=False)
    u3_coms, _, _ = utils.decompose(u3, 8, trim=False)

    lcm_u1_com_ids, lcm_u2_com_ids, lcm_score = map.location_map(
        u1_coms, u2_coms)
    # old_jcm_u1_com_ids, old_jcm_u2_com_ids, old_jcm_score = map.jaccard_map(u1_coms, u2_coms)
    jcm_u1_com_ids, jcm_u2_com_ids, jcm_score = map.soft_jaccard_map(
        u1_coms, u2_coms)
    if 1 != len(lcm_u1_com_ids) and \
            len(lcm_u1_com_ids) == len(jcm_u1_com_ids) and \
            len(lcm_u2_com_ids) == len(jcm_u2_com_ids) and \
            (np.unique(lcm_u1_com_ids) == np.unique(jcm_u1_com_ids)).all() and \
            (np.unique(lcm_u2_com_ids) == np.unique(jcm_u2_com_ids)).all():
        phm_u1_com_ids, phm_u3_com_ids, phm_score = map.placeholder_map(
            u1_coms, u3_coms)
    else:
        phm_u1_com_ids, phm_u3_com_ids, phm_score = (None, None, 0)

    mat_score = min((lcm_score + jcm_score) / 2, phm_score)

    stub = utils.make_stub(u1_coms, u2_coms, u3_coms, lcm_u1_com_ids,
                           lcm_u2_com_ids, jcm_u1_com_ids, jcm_u2_com_ids,
                           phm_u1_com_ids, phm_u3_com_ids)

    return mat_score, stub