Sinc filtering of an image
Show older comments
Hi,
I want to use a sinc filter to interpolate an image. Unfortunately theres no difference between the orginal image and the new image. Could somebody help me? I don't find the mistake :-( Thanks!
function SincFilter
%read image
A = imread('example.bmp');
x1 = -20:1:20;
x = abs(x1);
org_image = A(:,:);
figure(1); clf; hold on;
imshow(org_image,'DisplayRange',[])
M = size(org_image, 1);
N = size(org_image, 2);
y(:,:) = fft(A);
% % sinc(x) = (sin(pi*x))/(pi*x);
C = (1).*(x==0)+ ((sin(pi.*x))/(pi.*x)).*(x~=0);
B = conv2(y(:,:),C, 'same');
figure(2); clf; hold on;
imshow(B,'DisplayRange',[])
new_image(:,:) = ifft(B);
figure(3); clf; hold on;
imshow(new_image,'DisplayRange',[])
5 Comments
Matt J
on 10 Dec 2012
Convolving the spectrum y with a sinc is the Fourier dual of multiplying A by a rect window. There's no reason to expect it to implement sinc interpolation.
BTW, using the expression y(:,:) instead of just y is inefficient. It forces MATLAB to create a copy of y unnecessarily.
Image Analyst
on 10 Dec 2012
Is convolution what he was talking about? I had no idea since I've never heard the term sinc interpolation that I can recall.
Image Analyst
on 10 Dec 2012
Because that's not interpolation. That's filtering. Interpolation is figuring out what values lie in between other values. You're not doing that.
I haven't run your case but it's possible that your sinc is so narrow that it's basically a delta function and so your output image would look virtually identical to your input image.
The image must be smoothed by convolving the image with the sinc function(kernel) or muliplying the fft of the image with the fft of the sinc function(kernel)
You're doing neither. You are convolving the fft of the image with a sinc, not multiplying it with one.
Also, as ImageAnalyst points out, smoothing and interpolation are different things, so your goals are not clear.
Accepted Answer
More Answers (1)
The Fourier dual of sinc filtering by multiplication in the frequency domain is rect filtering by convolution in the space domain. If that is your goal, then it would be much simpler (2 lines of code) to work in the space domain instead,
rect1D=ones(1,n);
new_image = conv2(rect1D,rect1D,org_image, 'same');
It is also more efficient computationally to do it this way, assuming the rect window width n is not too large, which is usually the case in practice.. If you intend n to be large, you're going to destroy the image no matter which domain you work in.
Categories
Find more on Matched Filter and Ambiguity Function 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!