Skip to main content

Antialiasing edges of composited images

6 replies [Last post]
javacoda
Offline
Joined: 2005-04-28

I have a tricky (but interesting) little problem regarding antiliasing & compositing of two images.

The foreground image has been PerspectiveTransformed using JAI and the result has very jagged edges even with the KEY_ANTIALIASING=VALUE_ANTIALIAS_ON rendering hint - it seems that this rendering hint applies to primitive types only (ie. lines, elipses etc)???

All I am trying to do is to superimpose this image onto a background image and smooth the jaggies at the same time.

I have come across a few articles that talk about removing jaggies using a soft clipping technique (eg. http://weblogs.java.net/blog/campbell/archive/2006/07/java_2d_tricker.html), but I can't work out how to do the same thing with pre-rendered, irregular shaped images containing transparent areas (also with jagged edges).

Any ideas would be gratefully received.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bpb
Offline
Joined: 2004-06-23

> Yes I have tried that - no difference (on Windows at
> least).

If there is no difference then something is not being done correctly. How did you do it?

jxc
Offline
Joined: 2005-02-24

To get the antialiasing effect at image edges with interpolation,
either BorderExtenderZero or BorderExtenderConstant, where
the contants are the the background color, might have to be used.

Without extending the border, JAI geometric operations render
only the pixels which (when they are backward mapped) have
enough neighbor pixels within the edges of the source image
for the specified interpolation. If the contrast at the source image
edges is high, such as a bright image on a black background,
then the interpolated pixels at the edges can be close to white
and you may see jagged edges. With BorderExtenderZero, the
interpolated pixels at the edges may have different levels of gray
depending on how far they are from the theoretical edge lines.

HTH,
-James

Nidel, Mike

did you try setting an interpolation? just a thought,
it doesn't seem like that would really solve the problem.

> -----Original Message-----
> From: jai-interest@javadesktop.org
> [mailto:jai-interest@javadesktop.org]
> Sent: Thursday, February 14, 2008 4:34 AM
> To: interest@jai.dev.java.net
> Subject: [JAI] Antialiasing edges of composited images
>
> I have a tricky (but interesting) little problem regarding
> antiliasing & compositing of two images.
>
> The foreground image has been PerspectiveTransformed using
> JAI and the result has very jagged edges even with the
> KEY_ANTIALIASING=VALUE_ANTIALIAS_ON rendering hint - it seems
> that this rendering hint applies to primitive types only (ie.
> lines, elipses etc)???
>
> All I am trying to do is to superimpose this image onto a
> background image and smooth the jaggies at the same time.
>
> I have come across a few articles that talk about removing
> jaggies using a soft clipping technique (eg.
> http://weblogs.java.net/blog/campbell/archive/2006/07/java_2d_
> tricker.html), but I can't work out how to do the same thing
> with pre-rendered, irregular shaped images containing
> transparent areas (also with jagged edges).
>
> Any ideas would be gratefully received.
> [Message sent by forum member 'javacoda' (javacoda)]
>
> http://forums.java.net/jive/thread.jspa?messageID=258899
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail: interest-help@jai.dev.java.net
>
>

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

bpb
Offline
Joined: 2004-06-23

I think Mike is correct. Try bicubic interpolation.

The hint "KEY_ANTIALIASING=VALUE_ANTIALIAS_ON" is not used by JAI and I don't believe the documentation states anything to the contrary.

> did you try setting an interpolation? just a thought,
> it doesn't seem like that would really solve the
> problem.
>
> > -----Original Message-----
> > From: jai-interest@javadesktop.org
> > [mailto:jai-interest@javadesktop.org]
> > Sent: Thursday, February 14, 2008 4:34 AM
> > To: interest@jai.dev.java.net
> > Subject: [JAI] Antialiasing edges of composited
> images
> >
> > I have a tricky (but interesting) little problem
> regarding
> > antiliasing & compositing of two images.
> >
> > The foreground image has been
> PerspectiveTransformed using
> > JAI and the result has very jagged edges even with
> the
> > KEY_ANTIALIASING=VALUE_ANTIALIAS_ON rendering hint
> - it seems
> > that this rendering hint applies to primitive types
> only (ie.
> > lines, elipses etc)???
> >
> > All I am trying to do is to superimpose this image
> onto a
> > background image and smooth the jaggies at the same
> time.
> >
> > I have come across a few articles that talk about
> removing
> > jaggies using a soft clipping technique (eg.
> >
> http://weblogs.java.net/blog/campbell/archive/2006/07/
> java_2d_
> > tricker.html), but I can't work out how to do the
> same thing
> > with pre-rendered, irregular shaped images
> containing
> > transparent areas (also with jagged edges).
> >
> > Any ideas would be gratefully received.
> > [Message sent by forum member 'javacoda'
> (javacoda)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=2588
> 99
> >
> >
> ------------------------------------------------------
> ---------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai.dev.java.net
> > For additional commands, e-mail:
> interest-help@jai.dev.java.net
> >
> >
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> interest-unsubscribe@jai.dev.java.net
> For additional commands, e-mail:
> interest-help@jai.dev.java.net

javacoda
Offline
Joined: 2005-04-28

Yes I have tried that - no difference (on Windows at least).

javacoda
Offline
Joined: 2005-04-28

I have just tried the Warp demo applet in the JAI tutorial (see http://java.sun.com/developer/onlineTraining/javaai/jai/index.html) which demonstrates exactly the same problem, so perhaps there is no simple solution to this.

Maybe I should use try using a Java2D transform instead together with the hints mentioned by the last two posters (thanks for your comments BTW)? I believe that it should be possible, but I can't find a good example of how to do this.