# Black-box solution for image deblurring

This demo demonstrates how an unregularized solution can be computed using the toolbox.

It starts with the operator created by the demo bbdemo_deblur1, so please start with that.

To start it directly, use: playshow bbdemo_deblur2

## Contents

## Get the operator

The operator created in the first part of the demo, and the test image, is available in a separate script that does not produce
graphical figures.

bbdemo_deblurop;

## Get right-hand-side

Since this is an artifical example, our right-hand-side, B, of the equation system A*X=B will come from the known ground-truth,
which is the masked test image.

b=A*img1;
bbimagein(reshape(Mo'*b,dim3));
axis image off;

## Solve the system

The simplest way to solve the system is to use BBSOLVE(A,B). In reality, this is just a short-hand for BBPRESOLVE followed
by BBSOLVE.

While BBPRESOLVE may take several minutes (even on a relatively fast computer), BBSOLVE is extremely fast.

S=bbpresolve(A,b);
xh=bbsolve(S);
bbimagein(reshape(Mi'*xh,dim1));
axis image off;
title('Computed solution');

Iteration: 4, residual: 9.5333e-04
Iteration: 8, residual: 3.9364e-04
Iteration: 12, residual: 2.0660e-04
Iteration: 16, residual: 1.5136e-04
Iteration: 20, residual: 9.3723e-05
Iteration: 24, residual: 7.4836e-05
Iteration: 28, residual: 6.0091e-05
Halting: max. number of iterations reached.
(Increase rmaxi or rkeep to improve the solution.)
Residual norm: 4.8952e-05

## Compare solution with ground truth

One may be disappointed that an exact solution was not found. Unfortunately this is typical for severely ill-conditioned problems
like the one we have at hand.

One way to get closer approximations is to precondition the problem, such that it is easier to solve. Such preconditioning
is normally domain-specific, and is outside the scope if this demo.

Instead, we simply compare the known truth to the computed solution. It should be quite evident that most of the interesting
part of the solution have been captured.

dif=reshape(Mi'*(img1-xh),dim1);
lim=max(abs(dif(:)));
bbimagein(dif,[-lim,0,lim,lim])
axis image off;
title('Difference between computed solution and ground truth');