コード例 #1
0
ファイル: comparison.py プロジェクト: logeyG/7637project
def compare_rows_or_cols(scores, init_set, solution_set, solutions):

    abc_pixel_count = algorithm.fill_ratio(init_set[0]) + algorithm.fill_ratio(init_set[1]) \
                      + algorithm.fill_ratio(init_set[2])

    abc_shape_count = algorithm.find_regions(init_set[0]) + algorithm.find_regions(init_set[1]) \
                        + algorithm.find_regions(init_set[2])

    gh_pixel_count = algorithm.fill_ratio(solution_set[0]) + algorithm.fill_ratio(solution_set[1])
    gh_shape_count = algorithm.find_regions(solution_set[0]) + algorithm.find_regions(solution_set[1])

    possible_answers = []
    for i, score in enumerate(scores):
        if score != 0.0:
            possible_answers.append( (i, solutions[i]))

    comparisons = []
    for answer in possible_answers:
        x = (gh_pixel_count + algorithm.fill_ratio(answer[1]), len(gh_shape_count) + len(algorithm.find_regions(answer[1])) )
        comparisons.append(x)

    x = (abc_pixel_count, len(abc_shape_count))

    closest = utility.closest_node(x, comparisons)

    return (possible_answers[closest][0], possible_answers[closest][1])
コード例 #2
0
def compare_top_bottom(scores, figures, solutions, problem):

    if not scores:
        scores = [.125, .125, .125, .125, .125, .125, .125, .125]

    g_blobs = algorithm.get_blobs(algorithm.find_regions(figures[6]))
    h_blobs = algorithm.get_blobs(algorithm.find_regions(figures[7]))

    top_g = g_blobs[algorithm.get_top(g_blobs)]
    bottom_h = h_blobs[algorithm.get_bottom(h_blobs)]

    possible_answers = []
    for i, score in enumerate(scores):
        if score != 0.0:
            possible_answers.append((i, solutions[i]))

    comparisons = []
    for answer in possible_answers:

        solution_blobs = algorithm.get_blobs(algorithm.find_regions(answer[1]))
        top_solution = solution_blobs[algorithm.get_top(solution_blobs)]
        bottom_solution = solution_blobs[algorithm.get_bottom(solution_blobs)]

        x = (answer[0], algorithm.calc_rms(top_g, top_solution) +
             algorithm.calc_rms(bottom_h, bottom_solution))
        comparisons.append(x)

    m = min(comparisons, key=lambda t: t[1])

    return m
コード例 #3
0
ファイル: comparison.py プロジェクト: logeyG/7637project
def compare_top_bottom(scores, figures, solutions, problem):

    if not scores:
        scores = [.125, .125, .125, .125, .125, .125, .125, .125]

    g_blobs = algorithm.get_blobs(algorithm.find_regions(figures[6]))
    h_blobs = algorithm.get_blobs(algorithm.find_regions(figures[7]))

    top_g = g_blobs[algorithm.get_top(g_blobs)]
    bottom_h = h_blobs[algorithm.get_bottom(h_blobs)]

    possible_answers = []
    for i, score in enumerate(scores):
        if score != 0.0:
            possible_answers.append( (i, solutions[i]))

    comparisons = []
    for answer in possible_answers:

        solution_blobs = algorithm.get_blobs(algorithm.find_regions(answer[1]))
        top_solution = solution_blobs[algorithm.get_top(solution_blobs)]
        bottom_solution = solution_blobs[algorithm.get_bottom(solution_blobs)]

        x = ( answer[0], algorithm.calc_rms(top_g, top_solution) + algorithm.calc_rms(bottom_h, bottom_solution))
        comparisons.append(x)

    m = min(comparisons, key=lambda t: t[1])

    return m
コード例 #4
0
ファイル: transformation.py プロジェクト: logeyG/7637project
def inner_shape(source, compare):

    source_blobs = algorithm.get_blobs(algorithm.find_regions(source))
    compare_blobs = algorithm.get_blobs(algorithm.find_regions(compare))

    source_inner = source_blobs[algorithm.get_center(source_blobs)]
    compare_inner = compare_blobs[algorithm.get_center(compare_blobs)]

    return equality(source_inner, compare_inner)
コード例 #5
0
ファイル: transformation.py プロジェクト: logeyG/7637project
def shape_delta(source, compare):

    source_count = len(algorithm.find_regions(source))
    compare_count = len(algorithm.find_regions(compare))

    if source_count < compare_count:
        return 'added'  # + str(compare_count - source_count)
    elif source_count > compare_count:
        return 'removed'  # + str(source_count - compare_count)
    else:
        return 'unchanged'
コード例 #6
0
ファイル: comparison.py プロジェクト: logeyG/7637project
def compare_top_corners(figures):

    a_blobs = algorithm.get_blobs(algorithm.find_regions(figures[0]))
    c_blobs = algorithm.get_blobs(algorithm.find_regions(figures[2]))

    d_blobs = algorithm.get_blobs(algorithm.find_regions(figures[3]))
    f_blobs = algorithm.get_blobs(algorithm.find_regions(figures[5]))

    if len(a_blobs) < 2 or len(c_blobs) < 2 or len(d_blobs) < 2 or len(f_blobs) < 2:
        return False

    if transformation.strict_equality(a_blobs[algorithm.get_top(a_blobs)], c_blobs[algorithm.get_top(c_blobs)]) \
        and transformation.strict_equality(d_blobs[algorithm.get_top(d_blobs)], f_blobs[algorithm.get_top(f_blobs)]):
        return True
    else:
        return False
コード例 #7
0
ファイル: comparison.py プロジェクト: logeyG/7637project
def compare_bottom_bc_ef(figures):

    b_blobs = algorithm.get_blobs(algorithm.find_regions(figures[1]))
    c_blobs = algorithm.get_blobs(algorithm.find_regions(figures[2]))

    e_blobs = algorithm.get_blobs(algorithm.find_regions(figures[4]))
    f_blobs = algorithm.get_blobs(algorithm.find_regions(figures[5]))

    if len(b_blobs) < 2 or len(c_blobs) < 2 or len(e_blobs) < 2 or len(f_blobs) < 2:
        return False

    if transformation.strict_equality(b_blobs[algorithm.get_bottom(b_blobs)], c_blobs[algorithm.get_bottom(c_blobs)]) \
        and transformation.strict_equality(e_blobs[algorithm.get_bottom(e_blobs)], f_blobs[algorithm.get_bottom(f_blobs)]):
        return True
    else:
        return False
コード例 #8
0
def compare_top_corners(figures):

    a_blobs = algorithm.get_blobs(algorithm.find_regions(figures[0]))
    c_blobs = algorithm.get_blobs(algorithm.find_regions(figures[2]))

    d_blobs = algorithm.get_blobs(algorithm.find_regions(figures[3]))
    f_blobs = algorithm.get_blobs(algorithm.find_regions(figures[5]))

    if len(a_blobs) < 2 or len(c_blobs) < 2 or len(d_blobs) < 2 or len(
            f_blobs) < 2:
        return False

    if transformation.strict_equality(a_blobs[algorithm.get_top(a_blobs)], c_blobs[algorithm.get_top(c_blobs)]) \
        and transformation.strict_equality(d_blobs[algorithm.get_top(d_blobs)], f_blobs[algorithm.get_top(f_blobs)]):
        return True
    else:
        return False
コード例 #9
0
def compare_bottom_bc_ef(figures):

    b_blobs = algorithm.get_blobs(algorithm.find_regions(figures[1]))
    c_blobs = algorithm.get_blobs(algorithm.find_regions(figures[2]))

    e_blobs = algorithm.get_blobs(algorithm.find_regions(figures[4]))
    f_blobs = algorithm.get_blobs(algorithm.find_regions(figures[5]))

    if len(b_blobs) < 2 or len(c_blobs) < 2 or len(e_blobs) < 2 or len(
            f_blobs) < 2:
        return False

    if transformation.strict_equality(b_blobs[algorithm.get_bottom(b_blobs)], c_blobs[algorithm.get_bottom(c_blobs)]) \
        and transformation.strict_equality(e_blobs[algorithm.get_bottom(e_blobs)], f_blobs[algorithm.get_bottom(f_blobs)]):
        return True
    else:
        return False
コード例 #10
0
ファイル: transformation.py プロジェクト: logeyG/7637project
def outer_shape(source, compare):

    source_blobs = algorithm.get_blobs(algorithm.find_regions(source))
    compare_blobs = algorithm.get_blobs(algorithm.find_regions(compare))

    if len(source_blobs) < 2 or len(compare_blobs) < 2:
        return None
    else:
        source_inner = algorithm.get_center(source_blobs)
        compare_inner = algorithm.get_center(compare_blobs)

        source_blobs.pop(source_inner)
        compare_blobs.pop(compare_inner)

        source_outer = algorithm.write_blobs(source_blobs)
        compare_outer = algorithm.write_blobs(compare_blobs)

        return equality(source_outer, compare_outer)
コード例 #11
0
def compare_rows_or_cols(scores, init_set, solution_set, solutions):

    abc_pixel_count = algorithm.fill_ratio(init_set[0]) + algorithm.fill_ratio(init_set[1]) \
                      + algorithm.fill_ratio(init_set[2])

    abc_shape_count = algorithm.find_regions(init_set[0]) + algorithm.find_regions(init_set[1]) \
                        + algorithm.find_regions(init_set[2])

    gh_pixel_count = algorithm.fill_ratio(
        solution_set[0]) + algorithm.fill_ratio(solution_set[1])
    gh_shape_count = algorithm.find_regions(
        solution_set[0]) + algorithm.find_regions(solution_set[1])

    possible_answers = []
    for i, score in enumerate(scores):
        if score != 0.0:
            possible_answers.append((i, solutions[i]))

    comparisons = []
    for answer in possible_answers:
        x = (gh_pixel_count + algorithm.fill_ratio(answer[1]),
             len(gh_shape_count) + len(algorithm.find_regions(answer[1])))
        comparisons.append(x)

    x = (abc_pixel_count, len(abc_shape_count))

    closest = utility.closest_node(x, comparisons)

    return (possible_answers[closest][0], possible_answers[closest][1])