def generate_contrast_plus_test(path, base_path):
    loadfile = load.LoadData('D:\\pythonProject\\image_data_map.csv')
    pf, dict_index = loadfile.get_pixel_data()
    image_path_set = os.listdir(path)
    for label in image_path_set:
        image_name_set = os.listdir(osp.join(path, label))
        num = random.randint(400, 700)
        image_name1 = image_name_set[0]
        temp_label_set = list(image_name_set)
        temp_label_set.remove(image_name1)
        for i in range(num):
            image_name2 = temp_label_set[random.randint(
                0,
                len(temp_label_set) - 1)]
            index_1 = dict_index.get(image_name1)
            index_2 = dict_index.get(image_name2)
            print('index_1: ' + str(index_1) + ', index_2: ' + str(index_2))
            if index_1 is None or index_2 is None:
                continue
            x_1, f_1 = load.get_pixel_by_index(index_1, pf)
            x_2, f_2 = load.get_pixel_by_index(index_2, pf)
            pre1 = image_name1.replace('.png', '')
            pre2 = image_name2.replace('.png', '')
            save_path = osp.join(base_path,
                                 pre1 + '~' + pre2 + '~' + str(i) + 'tp.png')
            generate_origin.process_contrast(x_1, f_1, x_2, f_2, save_path)
def generate_contrast_minus_train(img_path, base_path):
    image_path_set = os.listdir(img_path)
    label_cnt = len(image_path_set)
    print(img_path + ' has ' + str(label_cnt) + ' labels ')
    loadfile = load.LoadData('D:\\pythonProject\\image_data_map.csv')
    pf, dict_index = loadfile.get_pixel_data()
    for label in image_path_set:
        temp_label_set = list(image_path_set)
        temp_label_set.remove(label)
        image_name_set = os.listdir(osp.join(img_path, label))
        for image_name in image_name_set:
            minus_label = temp_label_set[random.randint(
                0,
                len(temp_label_set) - 1)]
            minus_name_set = os.listdir(img_path + '\\' + minus_label)
            minus_name = minus_name_set[random.randint(0,
                                                       len(minus_name_set) -
                                                       1)]
            index_1 = dict_index.get(image_name)
            index_2 = dict_index.get(minus_name)
            print('index_1: ' + str(index_1) + ', index_2: ' + str(index_2))
            if index_1 is None or index_2 is None:
                continue
            print(label + ': generate ' + image_name + ' with ' + minus_name)
            x_1, f_1 = load.get_pixel_by_index(index_1, pf)
            x_2, f_2 = load.get_pixel_by_index(index_2, pf)
            pre = image_name.replace('.png', '')
            save_path = osp.join(base_path, pre + 'tm.png')
            generate_origin.process_contrast(x_1, f_1, x_2, f_2, save_path)
def generate_contrast_plus_train(img_path, base_path):
    image_path_set = os.listdir(img_path)
    print(img_path + ' has ' + str(len(image_path_set)) + ' labels ')
    loadfile = load.LoadData('D:\\pythonProject\\image_data_map.csv')
    pf, dict_index = loadfile.get_pixel_data()
    for label in image_path_set:
        image_name_set = os.listdir(osp.join(img_path, label))
        label_num = len(image_name_set)
        # choose first image as standard image todo standard image is not static
        standard_image = image_name_set[0]
        print(label + ' has ' + str(label_num) +
              ' images, standard image is ' + standard_image)
        index_standard = dict_index.get(standard_image)
        temp_image_set = list(image_name_set)
        temp_image_set.remove(standard_image)
        for image_name in temp_image_set:
            index_image = dict_index.get(image_name)
            print('index_1: ' + str(index_standard) + ', index_2: ' +
                  str(index_image))
            if index_standard is None or index_image is None:
                continue
            print(label + ': generate ' + image_name + ' with ' +
                  standard_image)
            x_1, f_1 = load.get_pixel_by_index(index_standard, pf)
            x_2, f_2 = load.get_pixel_by_index(index_image, pf)
            pre = image_name.replace('.png', '')
            save_path = osp.join(base_path, pre + 'tp.png')
            generate_origin.process_contrast(x_1, f_1, x_2, f_2, save_path)
def generate_single_contrast_by_name(image_name1, image_name2, base_path):
    loadfile = load.LoadData('D:\\pythonProject\\image_data_map.csv')
    pf, dict_index = loadfile.get_pixel_data()
    # file = open('D:\\graduationproject\\ver3\\similarity\\cbir\\error.txt')
    # for line in file:
    #     content = line.split(' ')
    #     image_name1 = content[0]
    #     image_name2 = content[1]
    #     label = content[2].replace('\n', '')
    index_1 = dict_index.get(image_name1)
    index_2 = dict_index.get(image_name2)
    print(str(index_1) + ';' + str(index_2))
    # if index_1 is None or index_2 is None:
    #     continue
    x_1, f_1 = load.get_pixel_by_index(index_1, pf)
    x_2, f_2 = load.get_pixel_by_index(index_2, pf)
    save_path = osp.join(base_path, image_name1 + '~' + image_name2 + '.png')
    generate_origin.process_contrast(x_2, f_2, x_1, f_1, save_path)
def generate_contrast_minus_test(image_name, path, base_path):
    loadfile = load.LoadData('D:\\pythonProject\\image_data_map.csv')
    pf, dict_index = loadfile.get_pixel_data()
    image_path_set = os.listdir(path)
    num = random.randint(800, 1000)
    for i in range(num):
        minus_label = image_path_set[random.randint(0,
                                                    len(image_path_set) - 1)]
        minus_name_set = os.listdir(osp.join(path, minus_label))
        minus_name = minus_name_set[random.randint(0, len(minus_name_set) - 1)]
        index_1 = dict_index.get(image_name)
        index_2 = dict_index.get(minus_name)
        print('index_1: ' + str(index_1) + ', index_2: ' + str(index_2))
        if index_1 is None or index_2 is None:
            continue
        x_1, f_1 = load.get_pixel_by_index(index_1, pf)
        x_2, f_2 = load.get_pixel_by_index(index_2, pf)
        pre1 = image_name.replace('.png', '')
        pre2 = minus_name.replace('.png', '')
        save_path = osp.join(base_path,
                             pre1 + '~' + pre2 + '~' + str(i) + 'tm.png')
        generate_origin.process_contrast(x_1, f_1, x_2, f_2, save_path)