Beispiel #1
0
def calculate_distance_matrix(app, all_imgs):
	hist_img = read_hist_img(app)
	distance_matrix = [([0] * len(all_imgs)) for i in range(len(all_imgs))]
	for i in range(len(all_imgs)):
		for j in range(len(all_imgs)):
			img_i = all_imgs[i]
			img_j = all_imgs[j]
			distance_matrix[i][j] = distance_euclidean_img(app, hist_img, img_i, img_j)
	return distance_matrix
Beispiel #2
0
def distance_img(app, img_name_a, img_name_b):
    hist_img = read_hist_img(app)

    index_a = get_img_pos(img_name_a)
    index_b = get_img_pos(img_name_b)

    img_a = hist_img[index_a]
    img_b = hist_img[index_b]

    dis = distance.euclidean(img_a, img_b)
    return dis
Beispiel #3
0
def is_same_img(app, img_name_a, img_name_b):
	hist_img = read_hist_img(app)

	index_a = get_img_pos(img_name_a)
	index_b = get_img_pos(img_name_b)

	img_a = hist_img[index_a]
	img_b = hist_img[index_b]
	dis = distance.euclidean(img_a, img_b)
	if dis <= img_similar_threshold:
		return True
	return False
Beispiel #4
0
def calculate_distance(app):
    if not os.path.exists('/'.join([DISTANCE_BASE_PATH, app])):
        os.makedirs('/'.join([DISTANCE_BASE_PATH, app]))

    all_reports = get_all_reports(app)
    hist_txt = read_hist_txt(app)
    hist_img = read_hist_img(app)

    distance_matrix_txt = [([0] * len(all_reports))
                           for i in range(len(all_reports))]
    distance_matrix_img = [([0] * len(all_reports))
                           for i in range(len(all_reports))]
    distance_matrix_report = [([0] * len(all_reports))
                              for i in range(len(all_reports))]

    # preprocess the hist in a dict to improve the efficiency
    hist_txt_dict = {}
    hist_img_dict = {}
    for i in range(len(all_reports)):
        report = all_reports[i]
        hist_txt_dict[report] = get_hist_txt(app, hist_txt, report)
        hist_img_dict[report] = get_hist_img(app, hist_img, report)

    for i in range(len(all_reports)):
        for j in range(len(all_reports)):
            report_a = all_reports[i]
            report_b = all_reports[j]

            hist_txt_a = hist_txt_dict[report_a]
            hist_txt_b = hist_txt_dict[report_b]

            hist_img_a = hist_img_dict[report_a]
            hist_img_b = hist_img_dict[report_b]

            distance_txt = distance_txt_jaccard(hist_txt_a, hist_txt_b)
            distance_imgset = distance_imgset_jaccard(hist_img_a, hist_img_b)
            distance_report = distance_report_harmonic(distance_txt,
                                                       distance_imgset,
                                                       hist_img_a, hist_img_b)

            distance_matrix_txt[i][j] = distance_txt
            distance_matrix_img[i][j] = distance_imgset
            distance_matrix_report[i][j] = distance_report

    # save all distance
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_txt.npy']),
            distance_matrix_txt)
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_img.npy']),
            distance_matrix_img)
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_harmonic.npy']),
            distance_matrix_report)
Beispiel #5
0
def calculate_distance(app):
    if not os.path.exists('/'.join([DISTANCE_BASE_PATH, app])):
        os.makedirs('/'.join([DISTANCE_BASE_PATH, app]))

    all_reports = get_all_reports(app)
    hist_txt = read_hist_txt(app)
    hist_img = read_hist_img(app)

    distance_matrix_txt = [([0] * len(all_reports))
                           for i in range(len(all_reports))]
    distance_matrix_img = [([0] * len(all_reports))
                           for i in range(len(all_reports))]
    distance_matrix_report = [([0] * len(all_reports))
                              for i in range(len(all_reports))]

    for i in range(len(all_reports)):
        for j in range(len(all_reports)):
            report_a = all_reports[i]
            report_b = all_reports[j]

            hist_txt_a = get_hist_txt(app, hist_txt, report_a)
            hist_txt_b = get_hist_txt(app, hist_txt, report_b)

            hist_img_a = get_hist_img(app, hist_img, report_a)
            hist_img_b = get_hist_img(app, hist_img, report_b)

            distance_txt = distance_txt_jaccard(hist_txt_a, hist_txt_b)
            distance_imgset = distance_imgset_jaccard(hist_img_a, hist_img_b)
            distance_report = distance_report_harmonic(distance_txt,
                                                       distance_imgset,
                                                       hist_img_a, hist_img_b)

            distance_matrix_txt[i][j] = distance_txt
            distance_matrix_img[i][j] = distance_imgset
            distance_matrix_report[i][j] = distance_report

    # save all distance
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_txt.npy']),
            distance_matrix_txt)
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_img.npy']),
            distance_matrix_img)
    np.save('/'.join([DISTANCE_BASE_PATH, app, 'distance_harmonic.npy']),
            distance_matrix_report)