Show HN: Resize images using the FFT
code.google.com
code.google.com
convert -filter Sinc -resize 200% input.png output.png
However, as pointed out by other commenters, sinc by itself isn't the greatest support function for enlargement due to the ringing artifacts [0]. Which are pretty visible in your example image [1].ImageMagick has way more documentation on the choice of resize filter than you'll ever need [2]. But it's interesting reading nonetheless; they settled on different default filters for shrinking (Lanczos) and enlargement (Mitchell).
[0] http://www.imagemagick.org/Usage/filter/#ringing
Source: I once maintained a small C library to do this, but eventually gave it up when it became clear how similar it was to the many existing sinc resampling implementations out there. That said, never stop experimenting.
Anyhow, I ran something like the following in Matlab for testing upsampling 4 pixels to 8 pixels:
fft_mx = fft( eye(4) ); #forward FFT transform matrix
fft_mx = padarray( fft_mx, [2 0], 0, 'both' ); #pads result vector with zeroes
fft_iv = ifft( eye(8) ); #inverse FFT matrix
abs( fft_iv * fft_mx ) * 2
The result is: 1.0000 0 0 0
0.6533 0.6533 0.2706 0.2706
0 1.0000 0 0
0.2706 0.6533 0.6533 0.2706
0 0 1.0000 0
0.2706 0.2706 0.6533 0.6533
0 0 0 1.0000
0.6533 0.2706 0.2706 0.6533
Basically, your idea (which boils down to an FIR scaler) samples the entire image when resampling. That isn't a very good behavior, IMHO.EDIT: fixed math
Bandlimited interpolation is "correct" in some technical sense for sampled signals and images, making some assumptions about the sampling procedure. That doesn't imply it's perceptually optimal, though. If your goal is "best approximation of what I sampled given the available data", then bandlimited interpolation is good. If your goal is "image that looks good", it probably isn't.
I'm not crapping on this contribution, though, it's always cool to see more signals stuff open sourced.
Edit: It looks like that function only works with one-dimensional data (along a single axis): https://github.com/scipy/scipy/blob/v0.13.0/scipy/signal/sig...
Also it would be nice to include all the docs (hah, minimal as they are) in the repo.
The dependencies are: Python 2, NumPy and matplotlib. The script can't really be installed at the moment, use it like so:
git clone https://code.google.com/p/fftresize
cd fftresize
python fftresize.py /path/to/image.jpg 2.0
Edit: It's on PyPI now! https://pypi.python.org/pypi/FFTresizeHere is the image interpolated 4X: http://imgur.com/a/8YrxG
Gray cats are somewhat smooth from a signal standpoint.
Edit: I'll be adding a window function soon to attenuate the ringing, it'll be interesting to see the difference that makes.
git clone https://code.google.com/p/fftresize/