The Source for Java Technology Collaboration

Home » java.net Forums » Java Desktop Technologies » Java 2D

Thread: Sub pixel sampling of Raster or DataBuffer in BufferedImage.

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 2 - Last Post: Feb 24, 2007 5:27 AM by: fred34
Ken Warner
Sub pixel sampling of Raster or DataBuffer in BufferedImage.
Posted: Feb 22, 2007 5:52 PM
  Click to reply to this thread Reply

Hi,

I'm writing an applet to show slightly distorted images. The applet it to apply
small corrective mapping to straighten out the image for better viewing.

The problem is that the corrections on a small image can be less than a pixel. It
would be real handy if I could do sub-pixel averaging to interpolate an average pixel
in between the four nearest neighbors. Pretty typical bi-linear interpolation.

I can do this when I draw the image using RenderHints. But I want to do it as I
access the source image. I lose too much information doing the interpolation
at render time.

What would be insanely great is if I could do a getPixel() using doubles or floats as
the pixel address -- like getPixel(4.321, 5.749 ....

Now that would be something!

Am I being clear -- as mud?

Does any one have a pointer to documentation or code that does sub-pixel sampling from
either a Raster or DataBuffer in a BufferedImage? It would be a useful thing
to review. Maybe I could get a better idea how to proceed with out losing the utility
of BufferedImages.

Ken Warner

===========================================================================
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".


ewin

Posts: 39
Re: Sub pixel sampling of Raster or DataBuffer in BufferedImage.
Posted: Feb 23, 2007 1:54 PM   in response to: Ken Warner
  Click to reply to this thread Reply

The Java 2D image structure is mind-boggling, and I don't claim I understand all the dragons hidden inside, but I am sure that there is no get-half-of-a-pixel method somewhere in the API. Not even in the darkest corner.

If I get you right. you need to do some image processing. You know the algorithm, but for whatever reason you don't want to get it done during rendering, but earlier.

It sounds like you want an AffineTransformOp. The AffineTransform for that AffineTransformOp should be a two times scale, and the interpolation type set to bilinear. You would then, after some ado, use the AffineTransformOp to create a new BufferedImage two times wider and two times higher than your original, where the new pixels are bilinear interpolated. You could still have keep original image for other evaluation.

If the AffineTransformOp doesn't do what you want, consider implementing your own BufferedImageOp. While implementing the BufferedImageOp interface is really not necessary (you could place all the image handling code in methods in your own classes) it makes sense because it is a standard interface which can be used in a few places in the Java 2D image API.

fred34

Posts: 128
Re: Sub pixel sampling of Raster or DataBuffer in BufferedImage.
Posted: Feb 24, 2007 5:27 AM   in response to: ewin
  Click to reply to this thread Reply

Implementing a whole load of image processing stuff is a bit overkill, not to mention creating an entirely new Image for each one you want to subsample is going to be very memory wasteful and slow. You would be much better just writing a couple of utility methods that take a bufferedImage and doing pixel sub sampling on the fly, unless you want to do several thousand subsamples per image in which case it would be better. Use the getpixels method of raster to grab the small neighbourhood around the pixel your after, do a quick convolution on it and that should be it!




 XML java.net RSS