#!/usr/bin/env python
import numpy as np
import scipy
import linear_operators as lo

# Load the infamous Lena image from scipy
im = scipy.lena()
im = im[::4, ::4]
# Generate a convolution model with a 7x7 uniform kernel
model = lo.convolve_fftw3(im.shape, np.ones((7, 7)))
# convolve the original image
data = model * im.ravel()
# add noise to the convolved data
data += 1e0 * np.random.randn(*data.shape)
# define smoothness prior
#prior = lo.concatenate([lo.diff(im.shape, axis=i) for i in xrange(im.ndim)])
prior = lo.concatenate([lo.diff(im.shape, axis=i) for i in xrange(im.ndim)]
                       + [lo.wavelet2(im.shape, "haar"),])
# generate algorithm
algo = lo.DoubleLoopAlgorithm(model, data, prior)
# start the estimation algorithm
xe = algo()
# reshape the output as the algorithm only handles vectors
xe.resize(im.shape)
Example #2
0
 def __call__(self, data, state):
     map_shape = state['map_shape']
     ndim = len(map_shape)
     Ds = [lo.diff(map_shape, axis=i) for i in xrange(ndim)]
     state['prior_models'] = Ds
     return data
Example #3
0
#!/usr/bin/env python
import numpy as np
import scipy
import linear_operators as lo

# Load the infamous Lena image from scipy
im = scipy.lena()
# Generate a convolution model with a 3x3 uniform kernel
kernel = np.ones((5, 5))
model = lo.convolve_ndimage(im.shape, kernel)
# convolve the original image
data = model(im)
# add noise to the convolved data
noise = 1e1 * np.random.randn(*data.shape)
data += noise
# define smoothness priors
prior = [lo.diff(im.shape, axis=i) for i in xrange(im.ndim)]
hypers = (1e1, 1e1)
# generate an conjugate gradient algorithm from model, data and priors
algo = lo.QuadraticConjugateGradient(model, data, prior, hypers,
                                     stop_condition=lo.StopCondition(gtol=1e-5))
# start the estimation algorithm
xe = algo()
# reshape the output as the algorithm only handles vectors
xe.resize(im.shape)