I have been trying to restore an image that was blurred with a known Point Spreading Function and corrupted with noise using a kalman filter. I have looked at theory and have a basic understanding of how kalman filters work. But I can't find any good material on how I can use it to restore an image. I have tried a method where I considered that the image was the state to be predicted with no control signal and a observation model equal to the blur function with a known measurement noise i.e,
$$X(k+1) = X(k)$$ $$Z(k) = H*X(k) + R$$ where,
X(k) is the 2D image
Z(k) is the observed noisy blurred image
H is the PSF
R is the noise
here is the code is used,
I = im2double(imread('E:\Wallpapers\2.jpg'));
I = I(:,:,1);
LEN = 2;
THETA = 5;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
SNR = 20;
noisy = awgn1(blurred,SNR);
noise = noisy - blurred;
R = cov(noise);
H = fft2(PSF,size(I,1),size(I,2));
K = 1e5*eye(size(I));
P = 1e5*eye(size(I));
X = zeros(size(I));
S = zeros(size(I));
for i = 1 : 1000
S = R + H*P*H';
K = P*H'/S;
X = X + K*(noisy - H*X);
P = (I - K*H)*P*(I - K*H)' + K*R*K';
end
MSE_noise = sum(sum((noisy-I).^2));
MSE1_restored = sum(sum((X-I).^2));
The image is filled with NaNs which is because of K = P*H'/S
being badly scaled.
Where am I going wrong? Is there a problem with the code or am I supposed to change the model to restore the image?