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.

/~pfnguyen/java_image_comparison/bilinear.png 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.

/~pfnguyen/java_image_comparison/bicubic.png 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.

/~pfnguyen/java_image_comparison/bicubic2.png 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.

/~pfnguyen/java_image_comparison/scaleFast.png AWT SCALE_FAST, generated in 2356ms. The FAST scaling hint renders results similar to BICUBIC2, but with slower performance.

/~pfnguyen/java_image_comparison/scaleSmooth.png 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.

/~pfnguyen/java_image_comparison/jimiAreaAverage.png 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.

Comments: 3

#3 Sergio wrote on Thursday, June 16, 2011 at 8:13 AM

I'm working in creation of thumbnails and I've seen results better than mine in other softwares (java), is there any new library better?

#2 jay p wrote on Sunday, January 9, 2011 at 8:48 AM

Thanks I'll be trying this out soon

#1 jens wrote on Tuesday, December 15, 2009 at 5:09 AM


thanks for you effort putting this together. this was a great help ans very well done! thank you very much!



No HTML is allowed. Numeric entity refs (&#nnnn;) are supported. Use {{{ and }}} to delimited preformatted sections. Items noted by * are mandatory.

Identify yourself

All new comments are moderated for spam protection. Email addresses are visible only to the entry owner and administrators.

  • Use AccessKey-P to Preview and AccessKey-S to Post