A comparison of Java image thumbnailing techniques
Lately, I have been re-implementing most of our Web Album/Gallery software in Java and in search of the ideal method for scaling down images for thumbnailing.
So far, I have tried three methods: JAI, AWT and Jimi. Of the three, I have found the AWT method to produce the best quality, while JAI offers the best speed performance. JAI especially excels when it comes to rescaling an image multiple times, subsequent scalings take only milliseconds to execute.
These images below have been generated according to the settings noted with them from this source image.
JAI BILINEAR, generated in 2226ms. Of the JAI scaling filters, this
appears to perform best for downscaling. The coat pattern is ok, but
the railings show a fair amount of aliasing.
JAI BICUBIC, generated in 587ms. Subsequent calls with the same original
BufferedImage results in extremely fast processing time. If this were
a first-run scale, the generation time would be similar to the BILINEAR
time above. This thumbnail suffers from very harsh contrast in the coat
pattern, aliasing on the rails and a square-shaped artifact in the empty
sky background.
JAI BICUBIC2, generated in 562ms. This is also a subsequent scaling
of the original image and also produced very fast results, the comment
about first-run scaling applies here as well. The downfall of this
thumbnail is similar to the BICUBIC image above, except this doesn't
show the square-shape artifact in the background sky.
AWT SCALE_FAST, generated in 2356ms. The FAST scaling hint renders
results similar to BICUBIC2, but with slower performance.
AWT SCALE_SMOOTH, generated in 2955ms. The slowest processing of the
bunch, however, notice the photographic quality of the image, the facial
detail, and smoothness of the railings and coat pattern. This is what
I will be using to generate thumbnails from now on.
Jimi AreaAverageScaleFilter, generated in 1861ms. Jimi is an old image
processing library to be used with Java 1.1, however it still works on
modern VMs. The API is rather clunky, and the code hasn't been updated
in years. I definitely will not be using this one in the future.
All time benchmarks are according to my Pentium III 1200MHz running with java.awt.headless=true and with JAI running in pure-Java mode. The benchmarks do not take into account HotSpot optimization and the performance of any of these algorithms can be much different after JIT compilation.
These comparisons do not include ImageMagick and JMagick because of the fact that it is not obvious how to create a BufferedImage from a MagickImage and vice versa by reading through the API documentation. I would venture to guess the quality of SCALE_SMOOTH and the default scale filter of ImageMagick to be comparable, except ImageMagick should do it much faster.
The next page includes the source code used to generate these images.
3