Java - I need a very fast image scaling algorithm
Asked Answered
H

1

11

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.

Huey answered 23/11, 2011 at 15:38 Comment(4)
what sizes are you talking about? is the % change arbitrary or some simple multiple (like 2x)?Sherlynsherm
one way to optimize is to use mipmapping: 3drender.com/glossary/mipmapping.htmLimited
The scale size is arbitrary. Let's say my image is 100px by 65px. I need to scale it to any size I want. Let's say 200px by 500px, or 1200px by 10px. So it needs to be scaled up or down either vertically or horizontally, and/or any combination of both.Huey
@Tony What libraries can you use, or does this have to be home grown?Monicamonie
A
35

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.

Adelia answered 3/12, 2011 at 2:36 Comment(1)
Thanks. I'm currently using the technique you describe in your link: "Some people are calling this the fastest image scaling implementation for J2ME." I will review the other techniques and do some testing and see if I get any faster scaling. Thumbs up for your excellent answer. Points go to you. Thanks Karl.Huey

© 2022 - 2024 — McMap. All rights reserved.