suda FollowSuda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions.
He is a keen science-fiction fan in his spare time.

Lanczos3 algorithm as a way to produce better image downscaling

January 5, 2016 1 min read

Image scaling options

At IDR Solutions recently, I have been looking for ways to provide higher quality image quality when down-sampling images in Java with our image library, JDeli. I stumbled across Lanczos3 and this gives really good results. So the purpose of this article is to introduce the algorithm and show the better results you can obtain.

By default Java offers a choice of algorithms to use when scaling down an image. The default ImageIO library in Java uses the image scaling algorithms nearest neighbour, bilinear and bicubic to scale images (with a trade off between speed and quality).

Of these bicubic scaling (which takes into account other rows and colums) is the best (and slowest!) option. But over 200% of the generated results are not good enough to maintain image clarity and essential details start to disappear. So I looked further afield and decided to use the Lanczos3 filtering algorithm. This is not available in ImageIO so I have had to implement it in our own Java image library, JDeli, to show you the results.

So let us look at some examples of all these scaling algorithms so you can see why I am such a fan of Lanczos3.

Image scaling examples

[click on the image above to view the original image (2048×2048) ]

Let us consider the image above which is created in simple paint application on windows and we resized the image into 128×128 dimension with several algorithms

With all of these algorithms, there is a trade off between time and quality. The best results (BiCubic and Lanczos3) require the slightly more processing time than bicubic but produces the best results. Only Lanczos3 retains the key details of the image as we make is smaller.

The only downside with Lanczos3 is that it is not implemented in Java as a default option. You will either need to implement it yourself (details on wikipedia) or use a third party library such as our commercial JDeli Image Library.

suda FollowSuda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions.
He is a keen science-fiction fan in his spare time.