Skip to main content

Filtered subsampling

1 reply [Last post]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Chris Nokleberg

[I sent this earlier to but it didn't show up
anywhere AFAICT]

I read Chris Campbell's article on image scaling the other day:

In the comments Chris mentioned that for very large images it is
better to first use ImageIO subsampling to reduce the image first, and
then use traditional scaling methods to reduce it further.

In my own applications I use subsampling quite heavily (we often have
5000x5000 images which only need to be 100x100 on the screen). The
problem has always been that the subsampling in ImageIO is really
crude--it actually just picks out every Nth column/row and tosses all
the rest. After reading much too much about sampling theory it was
revealed that the solution is to use a low pass filter on the original
image before downscaling, for example a Gaussian blur. If you combine
this with the subsampling algorithm it isn't even terribly expensive,
because you only have to calculate the blur for each of the output

This inspired me to add this feature to my PNG decoder library
( To subsample every 4th row/column the sample
code would be something like:

PngConfig config = new PngConfig.Builder()
.sourceSubsampling(4, 4, 0, 0)
BufferedImage image = new PngImage(config).read(new File("test.png"));

I've tested the result on the demo image from Chris' article and the
result is on par with the best of the scaling algorithms shown there
(arguably better).

Now, besides being an infomercial the real reason for this message is
to plead for a similar feature in ImageIO, if only for JPEG images. I
just don't have it in me to write a JPEG decoder too :-) Maybe there
is already a third-party library that does this? Does a RFE have any


p.s. In case anyone is listening the bugs I reported in the PNG
metadata spec are now over five years old:

To unsubscribe, send email to and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to and include in the body of the message "help".