# Examples

##
Using SVD for restorations.

If a blurring function is separable, then it is feasible to
use methods based on the singular value decomposition (SVD). Although
RestoreTools includes some of these capabilities, we are still in the
process of making improvements.
In any case, if you want to try some SVD based methods, the examples
below show some things you can do.
These instructions assume:
- You have a blurred image array called b.
- You have an image array containing the PSF.

The example data Text.mat can be used to try this; simply
load the data first:

>> load Text

Note though, that if your PSF is not separable,
then a separable approximation is constructed. The quality of the
restorations will depend in part on how close the PSF is to being
separable. The blur in Text.mat is separable, so the approaches
outlined below should work well.
You can also use different boundary conditions as well, such as
'periodic' or 'reflexive', when construction A (see
paper
for some examples).

** Truncated SVD Example. **

Once b and PSF are available, you can use the truncated singular
value decomposition in image restoration as follows:

>> A = psfMatrix(PSF);
>> [U,S,V] = svd(A, b);
>> tol = GCVforSVD(S, U'*b);

This will produce a plot with some information about the
truncation tolerance, tol. If it doesn't look like an
appropriate tolerance, you'll need to make another choice.
Assuming it looks okay, you can get a restoration as follows:

>> x = TSVD(U, S, V, b, tol);
>> imshow(x,[])

** Tikonov Example. **

If you want to try Tikhonov regularization (with the identity matrix
as the regularization operator), then you can use:

>> A = psfMatrix(PSF);
>> x = Tikhonov(A, b);

The Tikhonov regularization parameter is chosen using the generalized
cross validation method. If you prefer to choose your own regularization
parameter,
then you can use:

>> x = Tikhonov(A, b, alpha);