Skip to main content

Aliasing artifacts with PerspectiveTransform

3 replies [Last post]
oldhare
Offline
Joined: 2004-06-28
Points: 0

Hello,

I've written a small JAI program that perspectively transforms an arbitrary image on the command line and makes a PNG with transparent (alpha-channel) background out of it (PerspectiveTransform -> Warp -> BufferedImage). I have two problems though:

1) There are aliasing artifacts on the borders (jagged, stair-style) despite using a KEY_ANTIALIAS_ON in RenderingHints and passing it to the Warp and everywhere else that I could think of. I.e. PovRay or AGG render the same smoothly, however both have other limitations which is why I'm trying to do it with JAI at the moment.

2) The general quality post-perspective-transform is not so good. I've tried all interpolation methods up to bicubic and there's still visible artifacts e.g. when text is contained in the image.

Has anyone had the same problems? Or any ideas that might help in this situation?

Thanks for any help,

Regards,
Sergey Alekseyev

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oldhare
Offline
Joined: 2004-06-28
Points: 0

Hello Brian,

I understand your point. I can try using a higher order interpolation kernel, i.e. quintic B-splines or something. However my chief problem isn't so much the quality inside the image, it's removing the staircase effect at the borders, and that's something where higher order interpolation probably won't help since seemingly the interpolation support doesn't extend there. From my experiments, even nearest-neighbor produces the same staircase effect there as bicubic. Erik Meijering (http://imagescience.bigr.nl//meijering/software/transformj/index.html) successfully removes it by doing some dedicated borders handling in his TransformJ package, but I don't immediately see how to apply that approach in the JAI context.

What puzzles me is - isn't this a rather common problem? I think it should occur with just about every non-isometric transform operator. I.e. even a rotated image will often have those staircase effects at the borders. Isn't there some default way to handle that with JAI?

Regards,
Sergey

Brian Burkhalter

You should be able to handle the problem at the edges by using a
BorderExtender. Just pass a RenderingHints object to JAI.create() or the
RenderedOp constructor as appropriate. The hints instance should contain a
mapping of JAI.KEY_BORDER_EXTENDER to an instance of BorderExtender.

Brian

On Wed, 8 Feb 2006, jai-interest@javadesktop.org wrote:

> Hello Brian,
>
> I understand your point. I can try using a higher order interpolation kernel, i.e. quintic B-splines or something. However my chief problem isn't so much the quality inside the image, it's removing the staircase effect at the borders, and that's something where higher order interpolation probably won't help since seemingly the interpolation support doesn't extend there. From my experiments, even nearest-neighbor produces the same staircase effect there as bicubic. Erik Meijering (http://imagescience.bigr.nl//meijering/software/transformj/index.html) successfully removes it by doing some dedicated borders handling in his TransformJ package, but I don't immediately see how to apply that approach in the JAI context.
>
> What puzzles me is - isn't this a rather common problem? I think it should occur with just about every non-isometric transform operator. I.e. even a rotated image will often have those staircase effects at the borders. Isn't there some default way to handle that with JAI?
>
> Regards,
> Sergey
> [Message sent by forum member 'mumitroll' (mumitroll)]
>
> http://forums.java.net/jive/thread.jspa?messageID=80204
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net

Brian Burkhalter

I think your running into a limiting case here, i.e., warping text is
essentially warping strong edges which are going to have very high frequency
content. Consequently my only suggestions would be to apply a low pass filter
to the image before warping it or to use a higher order interpolation kernel.
You would be able to supply such an kernel by means of an InterpolationTable
instance

http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/ja...

although you would have to determine yourself the data content of the
resampling kernel used.

The hint KEY_ANTIALIAS_ON is not honored by the JAI operation.

Brian

On Mon, 6 Feb 2006, jai-interest@javadesktop.org wrote:

> Hello,
>
> I've written a small JAI program that perspectively transforms an arbitrary image on the command line and makes a PNG with transparent (alpha-channel) background out of it (PerspectiveTransform -> Warp -> BufferedImage). I have two problems though:
>
> 1) There are aliasing artifacts on the borders (jagged, stair-style) despite using a KEY_ANTIALIAS_ON in RenderingHints and passing it to the Warp and everywhere else that I could think of. I.e. PovRay or AGG render the same smoothly, however both have other limitations which is why I'm trying to do it with JAI at the moment.
>
> 2) The general quality post-perspective-transform is not so good. I've tried all interpolation methods up to bicubic and there's still visible artifacts e.g. when text is contained in the image.
>
> Has anyone had the same problems? Or any ideas that might help in this situation?
>
> Thanks for any help,
>
> Regards,
> Sergey Alekseyev
> [Message sent by forum member 'mumitroll' (mumitroll)]
>
> http://forums.java.net/jive/thread.jspa?messageID=79259
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
For additional commands, e-mail: interest-help@jai.dev.java.net