Skip to main content

Filtered subsampling

1 reply [Last post]
Anonymous

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 java2d@javadesktop.org but it didn't show up
anywhere AFAICT]

I read Chris Campbell's article on image scaling the other day:
http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledin...

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
pixels.

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

PngConfig config = new PngConfig.Builder()
.sourceSubsampling(4, 4, 0, 0)
.lowPassFilter(true)
.build();
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
chance?

Chris

p.s. In case anyone is listening the bugs I reported in the PNG
metadata spec are now over five years old:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4518989

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".