Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Embedded Image Resizing using FFT
Date: Fri, 21 Nov 2008 15:29:02 +0000 (UTC)
Organization: Xoran Technologies
Lines: 38
Message-ID: <gg6k3u$ea4$1@fred.mathworks.com>
References: <gg4co5$2cu$1@fred.mathworks.com> <gg4jc2$bck$1@fred.mathworks.com> <gg4kn6$2va$1@fred.mathworks.com> <gg4mdj$sjg$1@fred.mathworks.com> <gg4o3u$qfh$1@fred.mathworks.com> <gg4pkl$h47$1@fred.mathworks.com> <gg53fl$f0n$1@fred.mathworks.com> <gg56bi$fe6$1@fred.mathworks.com> <gg64up$sn8$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227281342 14660 172.30.248.38 (21 Nov 2008 15:29:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Nov 2008 15:29:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:502310


"Oliver Woodford" <o.j.woodford.98@cantab.net> wrote in message <gg64up$sn8$1@fred.mathworks.com>...
> > I don't think so. As far as I can tell, cropping frequencies (say by an integer factor 2) is equivalent to decimating the image by the same factor f(n,m)-->f(2n,2m).
> > This is known to give bad results.
> 
> We don't agree so we should do it and see.
> 
> I've found something that seems to work:
> 
> >> A = imread('cameraman.tif');
> >> subplot(121); imshow(A);
> >> B = fftshift(fft2(im2double(A)));
> >> B = ifft2(ifftshift(B(71:end-70,71:end-70)));
> >> subplot(122); imagesc(real(B)); colormap(gray(255)); axis image off
> 
> It reduces the image by 140 pixels in each dimension. You can enlarge by padding with zeros. You can avoid the shifts by working out what they do and cropping the correct regions directly.

> You'll note that I take the real component - the output is complex, which is a bad sign. I also use imagesc to display the output image, as it isn't scaled in the [0, 1] range any more, again a bad sign.
> 

I don't have the Image Processing Toolbox, so I can't try this myself.

However, I take it that the dimensions of A are even? If so, the reason you are getting a complex output is because you are not truncating frequencies symmetrically. To get symmetry in an even-sized array, you have to truncate the upper range of the array by 1 less than the lower.

 B = ifft2(ifftshift(B(71:end-69,71:end-69)));

My guess is that if you fix this, the scaling issue will go away too, because you'll no longer have to throw away imaginary components.


> Looking at image quality, it is clear cropping high frequencies doesn't simply subsample the image (i.e. take every ith pixel). 

Yes, I agree I was wrong about that. It should, however, end up being nearly equivalent to subsampling a filtered version of the image. 

When you throw away high frequencies, it is equivalent to first doing low pass rect-windowing of the spectrum, or equivalently of convolving the image with an (aliased) sinc kernel. Perhaps this is what you were refering to earlier by frequency-preservation... 

When you then throw away the components outside the rect-window, that is the frequency-domain dual of subsampling the sinc filtered image.

So, anyway, I'm becoming more convinced of the image-quality potential of the technique. Computationally, however, I still wonder if you could find more efficient image-domain equivalents. Sinc-filtering for example can be approximated very cheaply in the non-Fourier domain with cubic B-splines.