The following exemple can be found here. It shows how simple it is using linear_operators to perform simple deconvolution using the conjugate gradient algorithm.

The first line allows to call the script from the shell as an executable:

```
#!/usr/bin/env python
```

Then, you need to import the required Python packages:

```
import numpy as np
import scipy
import linear_operators as lo
```

Scipy is used in the script only to load an exemple image:

```
im = scipy.lena()
```

```
imshow(im)
```

Now, we start to use the linear_operator package to define a convolution operator:

```
kernel = np.ones((3, 3))
model = lo.convolve_ndimage(im.shape, kernel)
```

To perform the convolution on the image, simply call the operator:

```
data = model(im)
```

```
data = model * im.ravel()
```

Adding noise to the data is quite simple thanks to numpy.random subpackage:

```
noise = 1e1 * np.random.randn(*data.shape)
data += noise
```

See how the image is blurred as compared to the original image.

Now that we have our exemple data, we want to try deconvolving the image knowing the kernel. For this, we make use of quadratic deconvolution using the conjugate gradient algorithm provided in linear_operators. First, we need to define priors to regularize the inversion. Otherwise, the result would be way too noisy.

```
prior = [lo.diff(im.shape, axis=i) for i in xrange(im.ndim)]
hypers = (1e1, 1e1)
```

Finally, we instantiate and call the conjugate gradient algorithm:

```
algo = lo.QuadraticConjugateGradient(model, data, prior, hypers)
xe = algo()
```

```
xe.resize(im.shape)
```

Now, you can take a look at the result:

This is not perfect as quadratic deconvolution is not the best algorithm to perform deconvolution. In particular you can see ripples close to the edges of the images.

However this simple exemples illustrate how easy it is with the linear_operators package to set up a simple deconvolution script in about 15 lines of code.