Bizarre result in manual image filtering
Show older comments
Hello,
I have a code for manual 2D image filter. You need a 512 by 512 image to execute the code.
xx=-255:256;
[X, Y]=(meshgrid(xx,xx));
psf=exp(-(X.^2/1+Y.^2/1).^0.5);
psf2=fft2(psf);
testimage2fft=ifft2(fft2(testimage2));%same with original.
testimage2psf=(ifft2(fft2(testimage2).*(psf2)));% complex valued, fftshifted, filtered image
testimage2psf2=(ifft2(fft2(testimage2).*abs(psf2)));% complex valued, original, filtered image
This code is meant to be a low pass filter.
As you expect,
testimage2fft=ifft2(fft2(testimage2));%same with original
is real value, and same with testimage2.
What about below?
testimage2psf=(ifft2(fft2(testimage2).*(psf2)));% complex valued, fftshifted, filtered image
figure;imagesc(abs(testimage2psf));
It is complex valued, that deserves. I expected to see the filtered image, but it is fftshifted.
The last one is as follow,
testimage2psf2=(ifft2(fft2(testimage2).*abs(psf2)));% complex valued, original, filtered image
figure;imagesc(abs(testimage2psf2));
Yes, it shows the filtered image, and not shifted, what I expected.
What am I missing here? How does the '.*psf2' give shifted result while '.*abs(psf2)' give correct result?
1 Comment
Adam
on 4 Nov 2016
The second one is multiplying two complex-valued results together so the two imaginary terms will become real and the imaginary will be a combination of the real part of each with the imaginary part of the other. That will clearly give a different result than just multiplying by an absolute envelope result as you are in the last of your solutions.
Accepted Answer
More Answers (0)
Categories
Find more on Image Category Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!