As a preliminary step we load our FRAME module.
from util.image_processing_tools import *
from main.parameter_search import *
from main.feature import *
from setup import *
In this first section we present spots used in the ADSN model.
n_ADSN = 64
g = np.zeros((n_ADSN, n_ADSN))
g[0:3, 0:3] = 1
g_inv = fourier_inv(g)
A_g, A_g_inv = [autocorrelation(x) for x in [g,g_inv]]
s_g_inv = spectral_density(g_inv)
Usually the ADSN model is defined with a spot whose autocorrelation gives the covariance matrix of the corresponding ADSN model, i.e a symmetric circulant matrix. In order to express the ADSN model as an exponential model we need the precision matrix, the inverse of the covariance matrix, which can be expressed using the autocorrelation of some spot, the precision spot.
show_img([fft.fftshift(g),fft.fftshift(g_inv)], ['Precision spot', 'ADSN spot'])
Here we fix the precision spot. Please note that the precision spot (or the spot) should verify the following condition: \begin{equation} \forall x \in \Omega, \ \hat{f}(x) \neq 0. \end{equation} Doing so we can be defined the precision spot from the spot and vice-versa. The following images present the autocorrelation of the precision spot (respectively the autocorrelation of spot) related to the precision matrix (respectively to the precision matrix). We also display the spot spectral density, i.e the Fourier transform of the autocorrelation of the spot.
show_img([fft.fftshift(A_g),fft.fftshift(A_g_inv),s_g_inv], ['Precision spot correlation', 'Spot correlation','Spot spectral density'])
To conclude, we display one ADSN realization with this spot. In the following sections we will aim at reproducing such texture using a FRAME model.
show_img([ADSN(g_inv)], ['ADSN realization'])
In this section we set the parameters used in the FRAME algorithm. For more information about these parameters we refer to our code and especially to the $\texttt{setup}$ file.
""" FEATURE PARAMETERS """
f = feature_param()
f.feature_type = 'ADSN'
init = f.feature_init()
mask, feat_init = init(g)
f.mask = mask
#f.weight = autocorrelation(g) #final solution start
f.weight = np.zeros((n_ADSN, n_ADSN))
f.convex_cone_bound = np.min(np.real(fft.fft2(autocorrelation(g))))
""" LANGEVIN PARAMETERS """
l = langevin_param()
l.input_im = np.random.randn(n_ADSN, n_ADSN)
# l.input_im = precision_ADSN(g)*n_ADSN #ADSN start
l.step_decrease_rate = 0
l.jac_normalization_type = 'coordinate_wise'
l.step_init = 10 ** -2
l.step_init0 = 10 ** -2
l.langevin_it = 10 ** 3
l.langevin_it0 = 10 ** 3
l.stride = 10 ** 3
l.long_run = 'n'
""" WEIGHT PARAMETERS """
w = weight_param()
w.feat_init = feat_init
w.weight_it = 10 ** 1
w.langevin_it_increase_rate = 0.5
w.langevin_decrease_rate = 0.5
w.step_decrease_rate = 0
w.step_init = 10 ** -6
""" SAVE PARAMETERS """
s = save_param()
s.ground_truth = g
s.save_autocorrelation = 'y'
s.save_weight = 'y'
s.save_ground_truth = 'y'
s.folder_name = 'FRAME_test'
s.langevin_stride = l.stride
Now we run the FRAME algorithm according to the parameters. By default we keep the number of gradient descent iterations to ten so the computation is reasonable. However, in order to get better results we suggest to run at least one hundred iterations.
w_list, grad_w_list, x_list, grad_x_list, delta_t, log_s, n_img = weight_search(w, l, f)
print('elapsed time: ' + '{0:.2f}'.format(delta_t) + 's')
s.w_list = w_list
s.grad_w_list = grad_w_list
s.x_list = x_list
s.grad_x_list = grad_x_list
s.time_elapsed = delta_t
s.log_s = log_s
s.stride = 1
s.n_img = n_img
In this section we display the different results we obtained. Note that by using $\texttt{save_info(s,w,l,f)}$ you can save the data displayed here in a local repository. Note that, you might want to change the $\texttt{save_param.start_path}$ and $\texttt{save_param.folder_name}$ fields.
show_img([x_list[-1], ADSN(g_inv)], ['Final iteration', 'ADSN'])
show_img([autocorrelation(x_list[-1]), autocorrelation(g_inv)], ['Final autocorrelation', 'True autocorrelation'])
show_img([spectral_density(x_list[-1]), spectral_density(g_inv)], ['Final spectral density', 'True spectral density'])
autocorrelation_list = list_operation(x_list, autocorrelation)
easy_plot([relative_error_list(autocorrelation_list, autocorrelation(g_inv) * g_inv.size)], title='Autocorrelation relative error', stride=l.stride * 100)
easy_plot([relative_error_list(w_list, g)], title='Weight relative error')