Example #1
0
def example_use_descrs():
    print("Example usage of descriptors...")

    patch_size = 16
    image = imageio.imread('images/Lenna.png')
    image = image / 255.
    x_coord = 26
    y_coord = 473
    patch = image[x_coord:x_coord + patch_size,
                  y_coord:y_coord + patch_size, :]

    encoder = init_descr_32(patch_size=patch_size)
    patch_descr1 = compute_descriptor(patch, encoder)

    print("patch descr shape", patch_descr1.shape)
    print("patch descr:")
    print_descr_3dims(patch_descr1)

    encoder_IR, encoder_mp = init_IR(image.shape[0], image.shape[1],
                                     patch_size)
    image_IR = compute_IR(image, encoder_IR)
    print("patch IR")
    print_descr_3dims(image_IR[x_coord:x_coord + patch_size,
                               y_coord:y_coord + patch_size, :])
    patch_descr2 = compute_descriptor_from_IR(image_IR, x_coord, y_coord,
                                              patch_size, encoder_mp)

    print("patch descr shape", patch_descr2.shape)
    print("patch descr from IR:")
    print_descr_3dims(patch_descr2)

    print("diff")
    print(patch_descr1 - patch_descr2)
    print("print descr")
    print_descr_3dims(patch_descr1 - patch_descr2)
def main():

    x_queries = [118]
    y_queries = [351]

    image_path = '/home/niaki/Downloads/baboon.png'  #'/home/niaki/Downloads/barbara.bmp'

    patch_size = 16
    patch_width = patch_size
    patch_height = patch_size

    nr_similar_patches = 5
    query_stride = 100
    compare_stride = 3
    eps = 0.0001

    image = imageio.imread(image_path)
    image_height = image.shape[0]
    image_width = image.shape[1]
    image = image / 255.

    encoder32 = init_descr_32(16)
    encoder128 = init_descr(
        model_version='16_alex_layer1finetuned_2_finetuned_3conv3mp_lamb',
        nr_feature_maps_layer1=32,
        nr_feature_maps_layer23=32,
        patch_height=patch_height,
        patch_width=patch_width)

    mask_path = "/home/niaki/Downloads/mask_16"
    with open(mask_path, 'rb') as f:
        mask = pickle.load(f)

    results_patches_x_coords_0, results_patches_y_coords_0 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        1,
        image_path,
        mask,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)

    results_patches_x_coords_1, results_patches_y_coords_1 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        2,
        image_path,
        mask,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)
    results_patches_x_coords_2, results_patches_y_coords_2 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        3,
        image_path,
        mask,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)

    pickle_vars_for_visualisation(
        x_queries, y_queries, results_patches_x_coords_0,
        results_patches_y_coords_0, results_patches_x_coords_1,
        results_patches_y_coords_1, results_patches_x_coords_2,
        results_patches_y_coords_2, image_path, mask_path, patch_size,
        nr_similar_patches)

    ##### (comment EITHER: everything above here in main(), OR the unpickling line just bellow

    # x_queries, y_queries, results_patches_x_coords_0, results_patches_y_coords_0, results_patches_x_coords_1, \
    #     results_patches_y_coords_1, results_patches_x_coords_2, results_patches_y_coords_2, image_path, mask_path, \
    #     patch_size, nr_similar_patches = \
    #     unpickle_vars("../zimnica/visualisation_445_88_missing21_20191215_140006.pickle")

    with open(mask_path, 'rb') as f:
        mask = pickle.load(f)

    generate_visualisation_for_3_descrs(x_queries,
                                        y_queries,
                                        results_patches_x_coords_0,
                                        results_patches_y_coords_0,
                                        results_patches_x_coords_1,
                                        results_patches_y_coords_1,
                                        results_patches_x_coords_2,
                                        results_patches_y_coords_2,
                                        image_path,
                                        mask,
                                        patch_size=patch_size,
                                        nr_similar_patches=nr_similar_patches)
Example #3
0
import matplotlib

image_path = '/home/niaki/PycharmProjects/patch-desc-ae/images/Lenna.png'
patch_size = 16
nr_similar_patches = 40
query_stride = 32
compare_stride = 8
eps = 0.0001
results_dir = '/home/niaki/PycharmProjects/patch-desc-ae/results'
results_version = '4'

image = imageio.imread(image_path)
image_height = image.shape[0]
image_width = image.shape[1]

encoder32 = init_descr_32(16)
encoder128 = init_descr_128(16)

total_nr_query_patches = len(
    range(0, image_width - patch_size + 1, query_stride)) * len(
        range(0, image_height - patch_size + 1, query_stride))

#TODO add function calculate_ssd/calculate_psnr as a parameter to this function


def calculate_SSDs_for_desc_and_noise_level(which_desc, noise_level):

    image_noisy = add_gaussian_noise(image, sigma=noise_level)

    query_x_coords = []
    query_y_coords = []
Example #4
0
def main():
    x_queries = [124]
    y_queries = [359]

    image_path = '/home/niaki/Downloads/monarch_cropped_mirrored.png'

    patch_size = 16
    patch_width = patch_size
    patch_height = patch_size

    nr_similar_patches = 5
    query_stride = 100
    compare_stride = 2
    eps = 0.0001

    image = imageio.imread(image_path)
    image_height = image.shape[0]
    image_width = image.shape[1]
    image = image / 255.

    encoder32 = init_descr_32(16)
    encoder128 = init_descr(
        model_version='16_alex_layer1finetuned_2_finetuned_3conv3mp_lamb',
        nr_feature_maps_layer1=32,
        nr_feature_maps_layer23=32,
        patch_height=patch_height,
        patch_width=patch_width)

    random_seed = 124
    noise_level = 0

    results_patches_x_coords_0, results_patches_y_coords_0 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        1,
        image_path,
        random_seed,
        noise_level,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)
    results_patches_x_coords_1, results_patches_y_coords_1 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        2,
        image_path,
        random_seed,
        noise_level,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)
    results_patches_x_coords_2, results_patches_y_coords_2 = retrieve_patches_for_queries_and_descr(
        x_queries,
        y_queries,
        3,
        image_path,
        random_seed,
        noise_level,
        encoder32,
        encoder128,
        patch_size=patch_size,
        compare_stride=compare_stride,
        nr_similar_patches=nr_similar_patches)

    pickle_vars_for_visualisation(
        x_queries, y_queries, results_patches_x_coords_0,
        results_patches_y_coords_0, results_patches_x_coords_1,
        results_patches_y_coords_1, results_patches_x_coords_2,
        results_patches_y_coords_2, image_path, random_seed, noise_level,
        patch_size, nr_similar_patches)

    ##### (comment EITHER: everything above here in main(), OR the unpickling line just bellow

    # x_queries, y_queries, results_patches_x_coords_0, results_patches_y_coords_0, results_patches_x_coords_1, \
    #     results_patches_y_coords_1, results_patches_x_coords_2, results_patches_y_coords_2, image_path, random_seed, noise_level, \
    #     patch_size, nr_similar_patches = \
    #     unpickle_vars("../zimnica/somethingsomething.pickle")

    generate_visualisation_for_3_descrs(x_queries,
                                        y_queries,
                                        results_patches_x_coords_0,
                                        results_patches_y_coords_0,
                                        results_patches_x_coords_1,
                                        results_patches_y_coords_1,
                                        results_patches_x_coords_2,
                                        results_patches_y_coords_2,
                                        image_path,
                                        random_seed,
                                        noise_level,
                                        patch_size=patch_size,
                                        nr_similar_patches=nr_similar_patches)