# Additional Material

### CG and PCG for denoising

Here is the code for the numerical examples presented in the lecture on October 12:

- CG method: anisofilteringcg.m
- PCG method: anisofilteringpcg.m
- Implementation of the numerical gradient: num_grad.m
- Implementation of the numerical divergence: num_divergence.m

The code implements the numerical solution of the PDE \(u-\lambda\textrm{div}(a \nabla u) = f\), where \(a\) is some edge indicator function, which is small near edges of the image \(f\), and large in homogeneous regions of \(f\).

The input for both the CG and PCG implementation should be a colour image, that is, a 3d array of size \(m \times n \times 3\) (the noisy image). The first output is again a 3d array of the same size (the denoised imaged), and the second output is a vector containing the sizes of the residuals in each step (if one is interested in checking how the methods behave). Note that the code won't work on gray scale images!

All parameters (computation of the edge indicator, amount of smoothing, stopping criteria for the iterations) can be set directly in the files. In particular the amount of smoothing (the parameter lambda) should be adapted to the amount of noise in the image.

The code is by no means optimised, and it should be easily possible to decrease the computation time by improving the implementation of the differential operator. Also, it should be possible to decrease the computation time by simply solving the PDE separately for each colour channel instead of solving all the channels at once.

The parrot test image I have presented in the lecture is taken from http://r0k.us/graphics/kodak/.