Пример #1
0
from bilevel_imaging_toolbox import solvers
from bilevel_imaging_toolbox import image_utils
from bilevel_imaging_toolbox import plot_utils

### Testing dual rof model
# Loading image
image = image_utils.load_image('../examples/images/cameraman.png')
# Convert it to grayscale
image = image_utils.convert_to_grayscale(image)
# Add gaussian noise to the image
g_image = image_utils.add_gaussian_noise(image, var=0.02)

# Parameter Definition
clambda = 0.4
tau = 0.5

# Call the l2l2 solver using Forward-Backward
(fb_image, fb_values) = solvers.forward_backward_l2_l2(g_image,
                                                       clambda,
                                                       tau,
                                                       iters=200)
# Call ROF solver using Forward-Backward
clambda = 0.1
(cp_image, cp_values) = solvers.forward_backward_ROF(g_image,
                                                     clambda,
                                                     tau,
                                                     iters=200)

# Plot resulting images
#image_utils.show_collection([image,g_image,fb_image,cp_image],["original","gaussian noise","denoised l2l2","denoised ROF"])
#plot_utils.plot_collection([fb_values],["FB"])
import numpy as np

s_image_list = [
    '../examples/images/Playing_Cards_1.png',
    '../examples/images/Playing_Cards_2.png',
    '../examples/images/Playing_Cards_3.png'
]
n_trials = 20
n_iters = 100

print('Testing CP ROF GPU')
for image_path in s_image_list:
    times = np.zeros(n_trials)
    image = image_utils.load_image(image_path)
    image = image_utils.convert_to_grayscale(image)
    g_image = image_utils.add_gaussian_noise(image)

    # Parameter Definition
    clambda = 0.2
    sigma = 1.9
    tau = 0.9 / sigma

    for k in range(n_trials):
        start_time = timeit.default_timer()
        (fb_image,
         fb_values) = cuda_solvers.chambolle_pock_ROF_CUDA(g_image,
                                                           clambda,
                                                           tau,
                                                           sigma,
                                                           iters=n_iters)
        times[k] = timeit.default_timer() - start_time