%% Restore an degraded Image (noising and blurring) by TV method.
%% The numerical implementation is based on Roe upwind schema
clear all;
close all;
clc;
Img = imread('lenna.bmp');
Img = double(Img);
figure(1); imshow(uint8(Img));
[nrow, ncol] = size(Img);
% blurring image
Img = gauss(Img,7,3);
% add noise to the blurred image
I0=Img+10*randn([nrow, ncol]);
figure(2); imshow(uint8(I0));
lamda=0.2; % This is a important parameter to get a better result
timestep=0.01;
I_temp=I0; % Initialization
%Iteration begin
for n=1:600
Ix = 0.5*(I_temp(:,[2:ncol,ncol])-I_temp(:,[1,1:ncol-1]));
Iy = 0.5*(I_temp([2:nrow,nrow],:)-I_temp([1,1:nrow-1],:));
Ix_back = I_temp-I_temp(:,[1,1:ncol-1]);
Ix_fo