I implemented a Wiener filter using Matlab and i noticed that both functions(mine and matlabs) are creating an image with shifted pixels on the edges. Class teacher said it will happen. Is there a simple explanation to that?
Code:
%open image
I = imread('pout.tif');
%sigma for gaussian
sigma = 1.2;
%gaussian kernel max width/height
N = 2*ceil(3*sigma)+1;
%gaussian PSF(point spread function)
PSF = fspecial('gaussian',N,sigma);
%Noise
NSR = 0.05;
%Matlab's Wiener function.
I1 = deconvwnr(I,PSF,NSR);
%New PSF for my implementation
PSF1 = zeros(N,N);
%loop to create the 2D gaussian psf.
x = (N/2)-0.5;
for i = -x:x
for j = -x:x
%gaussian
PSF1(i+x+1,j+x+1) = exp( -( ( (i^2) + (j^2) ) / ( 2 * (sigma^2) ) ) );
end
end
%normalization
PSF1=PSF1/sum(sum(PSF1));
%fourier transformation of PSF1.
fouri = zeros(size(I,1),size(I,2));
fouri(1:N,1:N)= PSF1;
H = fft2(fouri);
%uint8 to double of the original image.
I = double(I);
%fourier transformation of the image
Y = fft2(I);
%Wiener function.
X = conj(H)./ ( abs(H).^2 + NSR ).* Y;
%exit from fourier transformation.
I2 = real(ifft2(X));
%go back to uint8 for both images.
I2 = uint8(I2);
I = uint8(I);
%Results.
subplot(1,3,1); imshow(I); title('Original');
subplot(1,3,2); imshow(I1); title('Matlab function');
subplot(1,3,3); imshow(I2); title('My implementation');
Output: