load bacteria
load noise
[X, Y] = meshgrid(-128:1:127, -128:1:127);
ddk = X.*X + Y.*Y;

figure
subplot(1,3,1)
imagesc(bacteria); axis image
colormap gray

w = window(@gausswin, 256, 50);
w2 = fftshift(w*w');
blurred = ifft2(fft2(double(bacteria)).*fft2(w2)) + 25.*noise;
subplot(1,3,2)
imagesc(blurred); axis image

% under regularized
recft = (fft2(blurred).*conj(fft2(w2))./(fft2(w2).*conj(fft2(w2))+ (10^-5).^2.*fftshift(ddk).^2));
rec = ifft2(recft);
subplot(1,3,3)
imagesc(rec); axis image

% over regularized
recft = (fft2(blurred).*conj(fft2(w2))./(fft2(w2).*conj(fft2(w2))+ (10^-1).^2.*fftshift(ddk).^2));
rec = ifft2(recft);
subplot(1,3,3)
imagesc(rec); axis image

% properly regularized
recft = (fft2(blurred).*conj(fft2(w2))./(fft2(w2).*conj(fft2(w2))+ (10^-3.25).^2.*fftshift(ddk).^2));
rec = ifft2(recft);
subplot(1,3,3)
imagesc(rec); axis image