Sinc filtering of an image
16 views (last 30 days)
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
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.
Matt J
on 10 Dec 2012
Edited: Matt J
on 10 Dec 2012
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
Image Analyst
on 10 Dec 2012
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. Try widening your sinc.
8 Comments
Image Analyst
on 11 Dec 2012
No, don't convert to double. The reason is that your image is 16 bit so the image display range is 0 to 65535 by default. But your brightest pixel is only 2540 - way less than 65535 - so it looks very dark. You can do this to scale it automatically so that 2540 becomes 255 instead of 65535 becoming 255:
imshow(myImage, []);
The double became all white because if the class is double, it expects it to be in the range zero to one. Zero goes to 0 and 1 goes to 255. Anything greater than 1 is treated like it's 1 - it gets clipped. Since all your pixels were greater than 1, they got clipped to the max display intensity of 255.
More Answers (1)
Matt J
on 10 Dec 2012
Edited: Matt J
on 10 Dec 2012
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.
0 Comments
See Also
Categories
Find more on Image Processing Toolbox 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!