Exemplo n.º 1
0
def rebuild_image(img_filename, dic_filename, output_filename, patch_size):
    D = load_dic(dic_filename)

    # Open image
    img = Image.open(img_filename)

    # Get patches from image
    patches = img_preprocessing.get_patches(img, patch_size)

    sparse_code(patches, D, atoms=3)
    n_img = img_preprocessing.build_from_patches(patches, img.size)

    n_img.save(output_filename)
Exemplo n.º 2
0
def build_dic(img_filename, dic_filename, dic_img_filename, patch_size):
    # Define parameters
    dic_size = 100  # Size of dictionary (number of atoms)
    regularization = 1.2 / dic_size  # Regularization parameter of the Lasso optimization problem
    batch_size = 5  # Size of batches
    n_iter = 5000  # Number of iterations

    # Open image
    img = Image.open(img_filename)

    # Get patches from image
    patches = img_preprocessing.get_patches(img, patch_size)

    # Learn dictionary
    D = learn_dic(patches, dic_size, T=n_iter, batch_size=batch_size, lambd=regularization)

    # Save dictionary to file
    save_dic(D, dic_filename)

    # Save dictionary as nice image
    dicimg = show_dic(D, patch_size)
    misc.imsave(dic_img_filename, dicimg)