|
zoom, by Paul HeckbertPaul Heckbert's zoom (user's manual) is a great little program that implements a variety of separable antialiased filters for resizing and resampling images. You can use it to blur images, to shrink images, to enlarge images, or perform any of these operations on one axis of an image. Zoom implements the filter kernel convolution entirely in integer arithmetic and uses separable filters to keep the intermediate memory requirements reasonable. Rich didn't write zoom, but he did add some file format support to it because he's such a big fan of its filter implementation. File formats supported: PBM/PGM/PPM, uncompressed BMP, TIFF, GIF, JPEG, PNG and raw "dump" format. I don't guarantee that the file I/O code that I added will support every possible variation (TIFF has many variations), but I try to test with a variety of input files. Files and Filters SupportedThis 1.3 release contains everything needed to build zoom from MS VC++ 6, including TIFF via libtiff, PBM/PGM/PPM via netpbm, PNG via libpng, raw dump, GIF and BMP via C code, and JPEG via IJG's libjpeg.
picture devices/file formats known: dump pnm jpg png gif tif bmp filt -? reports:
point 0.00 box 0.50 triangle 1.00 quadratic 1.50 cubic 2.00 catrom 2.00 mitchell 2.00 mitchell: p0=0.888889 p2=-2 p3=1.16667 q0=1.77778 q1=-3.33333 q2=2 q3=-0.388889 gaussian 1.25 sinc 4.00 (windowed by default) bessel 3.24 (windowed by default) hanning 1.00 hamming 1.00 blackman 1.00 kaiser 1.00 kaiser: a=6.5 i0a=0.00940797
Why Proper Filtering MattersYou may be wondering why you should go to all the trouble of selecting a filter when resizing an image and doing all this stuff. Here is a visual example illustrating the difference. The following two images went through the same scaling code in zoom. The first image uses a 'mitchell' filter which trades ringing for smoothing to try and get a generic catch all filter. (There are images for which you might want to use a sharper filter and others for which you might want a smoother filter.) The second image uses the filter 'point' which just point samples the source image no filtering at all. The source image of Visual C++ 6 debugging zoom still has a recognizable font on the filtered image, but the aliased image looks horrible. (Win32's StretchBlt is more likely to give you something more like the point-sampled image, depending on your GDI display driver.)
My favorite aliasing artifact in the above is how the scroll bars have turned into alternating bands of white and gray! Other artifacts you can see: thin lines on the tree view control are missing, braces in the C code shown in the source view are missing, the colored text is now faded and in some cases difficult to see that its colored and you can no longer read the text displayed anywhere. Making It Fit, Pt. 2
Here's another example. Ever find some really nice image on the net, but its too big for your screen? Maybe you found a way to squish it into your available screen space, but it didn't come out looking as nice? Chances are that aliasing was introduced when the image was rescaled. I like to browse lots of space sites like NASA's image archives and find big astronomy images for my PC's desktop. Zoom is great for resampling those images to fit nicely on your desktop. I found this HUGE NASA radar image of Salt Lake City, at 1494 by 2500 pixels. Using zoom I filtered it down to fit in a 1280x1024 screen and converted it to JPEG. Now normally JPEG would be horrible on this kind of image because it would ditch all the high frequencies and introduce artifacts. When we downsample (reduce in resolution) a digital image with zoom, we do the minimal amount of smoothing that digital signal processing theory will let us get away with. Because we are downsampling, the filter will smooth out the high frequency components that will give JPEG trouble, so when we convert to JPEG, the fine detail of the streets and causeways in the Great Salt Lake are preserved as best they can. Filtering Without Resizing
These three images are all from the same source, just blurred differently with zoom. You can also use zoom to apply some smoothing to an image without changing its size. This can be useful for smoothing a poorly scanned half-tone image, where the half-tone pattern is causing artifacts. By applying a little smoothing to the image, we smear out the half-tone dots and averaging them together. When you look at a half-tone original from far away it appears continuous because your eye does this sort of averaging. |