Java - I need a very fast image scaling algorithm

user445338 picture user445338 · Nov 23, 2011 · Viewed 24.4k times · Source

I am working on a Midlet application. I am finding myself in the need to scale images very often. This has become a problem because some phones are pretty slow and scaling takes too long.

Currently I'm using Image.createRGBImage(int, int, int, boolean) to scale the image.

I was wondering if any of you knew of a very efficient and fast way to scale an image.

Note: this is a Midlet application so only JavaME is available, meaning I don't have access to some other libraries available in the full java version.

Note2: most of my scaling is done from small to large images, although I also do scale down the image.

Answer

karlphillip picture karlphillip · Dec 3, 2011

Keep in mind that there's always a trade between speed and image quality when discussing scaling algorithms, and the ideal solution for your case might require some research and testing.

Nearest neighbor is the simplest and fastest implementation of image scaling.

There's a nice intro on image scale/resize on Coding Horror which reviews a couple of techniques and compares their quality.

I imagine you are working with a very small displaying device, so image quality doesn't really matter at the end. Some people are calling this the fastest image scaling implementation for J2ME.

But if you are willing to read some other stuff, this paper presents a low cost (meaning "very fast") algorithm for scaling that significantly improves on nearest neighbor interpolation. There's source code available, and they also present an evolution of that research here.

At last but not least, cvResize() from OpenCV (open source/cross-platform library for image processing). The folks at willow garage are pretty good at making fast procedures for image/video processing, and this function provides a couple of techniques for scaling, so it might be worth to check it's implementation.