Java - I need a very fast image scaling algorithm

25,004

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.

Share:
25,004
Hunsu
Author by

Hunsu

SOreadytohelp

Updated on July 09, 2022

Comments

  • Hunsu
    Hunsu almost 2 years

    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.

    • SirDarius
      SirDarius over 12 years
      what sizes are you talking about? is the % change arbitrary or some simple multiple (like 2x)?
    • appas
      appas over 12 years
      one way to optimize is to use mipmapping: 3drender.com/glossary/mipmapping.htm
    • Admin
      Admin over 12 years
      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.
    • mevatron
      mevatron over 12 years
      @Tony What libraries can you use, or does this have to be home grown?
  • Admin
    Admin over 12 years
    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.