Skip to main content

A warped image rendering experiment, enlightenment wanted

6 replies [Last post]
plastilino
Offline
Joined: 2010-05-17

Hi everyone, I'm pretty new with JAI but not with Graphics2D.

I would like to explain to you a performance problem with WarpAffine I don't know how to interpret, I'll try to pose it as clear as possible.

Until now I been using the Graphics2D package to display graphics in my application. The application transform an imagen using a series of affine transforms to allow calibration, and interactive draging and zooming. Until now my approach was to calculate the totalTransform and then render it with:

g2d.drawRenderedImage(image,totalTrf)

It works fine and its fast enough.

Now I need to introduce nonlinear transforms in the image, so I came to JAI. My first approach is being to reproduce the affine case with the new methodolgy. So I define a WarpAffine transform, not worryng by the moment on pre and post scales, just keep them as 1. Then I calulate the transformed image:

trfImage=JAI.create("warp", pb);

To make clear where the problem is, I make the following experiment: I include these TWO LINES when rendering

--------------------------------------
trfImage=JAI.create("warp", pb);
g2d.drawRenderedImage(image,totalTrf);
--------------------------------------

I mean, I DO CALCULATE the transformed image, but DON'T USE IT for rendering, I keep rendering in the old way. In this situation I can't observe differences with the previous metodology. So I would conclude that creating the transformed image DO NOT pose an appreciable penalization in my application.

The follwing step is using the trasfored image for rendering:

------------------------------------------------------
trfImage=JAI.create("warp", pb);
g2d.drawRenderedImage(trfImage,new AffineTransform());
----------------------------------------------------

Now paning and zooming is much slower than before, there is an important performance penalization in this case.

So it seems that this issue has nothing to do with the creationn of the warped image by JAI, but is a consequence of the implementation of the drawRenderedImage method.

I would appreciate any clue from the experts about this behaviour.

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
plastilino
Offline
Joined: 2010-05-17

Please, look at this, here is the problem:

---------------
scale 1.0552906373046231
width 512
---------------
scale 0.9497615735741608
width 9993
---------------

When crossing the frontier

scale=1

a big discontiniuty happens in the JAI internals: class WarpOpImage start asking for enormous amount of cells to the Warp class -WarpAffine in my case- and the image freezes.

Aclaration:

- scale: the X scale of the inverse mapping
- width: number of Xcells asked by the system in the key method of any Warp class:

warpRect(int x0, int y0, int width, int heigth, float[] destRect)

As far as I understand this would affect anyone using a Warp class an zooming in a picture too much.

I'm marking this thread as answered, going further would imply diging in the heart of JAI, a task for experts only.

I hope some of them will have a look at this.

plastilino
Offline
Joined: 2010-05-17

It seems I came to the wrong place. I checked out the CVS repositiry and the last updated file of jai-core is form August 2007.

Only a blind authomatic system keeps on producing daily builds of the same sally thing, over and over. They abandoded the room in a rush, no time even to switch off the light.

JAI is dead, have fun

plastilino
Offline
Joined: 2010-05-17

While trying to find out what makes WarpAffine so slow I tested the pre and post scale factors of the constructor and found that they are not working. I mean, any value other that 1 produces resized images.

I have been having a look on the WarpAffine code and I see this class extends WarpPolynomial.

Pre and post scale factors are ussefull for building an interpolation polynomial that fits a set of control points, as the ones used for calibrating maps.

You can choose any value you want for the pre and post scale factors, but the JAI documentation says that you better select those that makes the polymomial to work on the [0,1] interval. If you change the values of the pre and post scale factors, then another polynomial is obtaiend. The point is that the total transform:

preScale Polynomial postScale
------------> --------------> ------------>

keep rougly the same, as it is constrained by the control points.

So pre and post scale factors are well suited for interpolation problems. But affine transforms in the JAI package not seems been focused on solving interpolation problems.

In fact nowhere in the code of the WarpAffine class you'll see that changing the pre and post scale factors will affect the parameters of the affine transform. As a result you'll get a complete different total transform if you select values other than one, and the image won't shows properly.

Marco Sambin - NeoLogica

Hi.

I've never done direct experiments with the "warp" operator, hence I cannot say how fast it should be.
Nevertheless, what I would like to underline is that JAI's rendering model is a "pull" rendering model: this means that operators in the rendering chain are actually computed ONLY when a rendering is required.

Hence, as long as you have a line like this in your code:

trfImage=JAI.create("warp", pb);

but then you don't use "trfImage", then the "warp" operator will actually do nothing, since no rendering of the trfImage node is required. This explains why you do not have any performance penalty in your first test scenario.
Hope it helps.

Best regards,

Marco

-----Original Message-----
From: jai-interest@javadesktop.org [mailto:jai-interest@javadesktop.org]
Sent: lunedì 17 maggio 2010 10:29
To: interest@jai.dev.java.net
Subject: [JAI] A warped image rendering experiment, enlightenment wanted

Hi everyone, I'm pretty new with JAI but not with Graphics2D.

I would like to explain to you a performance problem with WarpAffine I don't know how to interpret, I'll try to pose it as clear as possible.

Until now I been using the Graphics2D package to display graphics in my application. The application transform an imagen using a series of affine transforms to allow calibration, and interactive draging and zooming. Until now my approach was to calculate the totalTransform and then render it with:

g2d.drawRenderedImage(image,totalTrf)

It works fine and its fast enough.

Now I need to introduce nonlinear transforms in the image, so I came to JAI. My first approach is being to reproduce the affine case with the new methodolgy. So I define a WarpAffine transform, not worryng by the moment on pre and post scales, just keep them as 1. Then I calulate the transformed image:

trfImage=JAI.create("warp", pb);

To make clear where the problem is, I make the following experiment: I include these TWO LINES when rendering

--------------------------------------
trfImage=JAI.create("warp", pb);
g2d.drawRenderedImage(image,totalTrf);
--------------------------------------

I mean, I DO CALCULATE the transformed image, but DON'T USE IT for rendering, I keep rendering in the old way. In this situation I can't observe differences with the previous metodology. So I would conclude that creating the transformed image DO NOT pose an appreciable penalization in my application.

The follwing step is using the trasfored image for rendering:

------------------------------------------------------
trfImage=JAI.create("warp", pb);
g2d.drawRenderedImage(trfImage,new AffineTransform());
----------------------------------------------------

Now paning and zooming is much slower than before, there is an important performance penalization in this case.

So it seems that this issue has nothing to do with the creationn of the warped image by JAI, but is a consequence of the implementation of the drawRenderedImage method.

I would appreciate any clue from the experts about this behaviour.

Thanks
[Message sent by forum member 'plastilino']

http://forums.java.net/jive/thread.jspa?messageID=470111

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

plastilino
Offline
Joined: 2010-05-17

HI Marco,

Thanks for your clever explanation, I had readed about the pull mechanism in the documentation, but didn't figure out how it worked, I mostly learn by example.

So I see I can't exlude the affine warping as the cause of the performance degradation. I will make some more tests knowing the new facts, but I will keep the thread as unanswered for now, for if someone can tell someting about what causes the differences beteween both procedures.

One thing I forgot to mention is that the total affine transform embedes the source image in a much bigger canvas. The source images are regional maps, and the target space is the world canvas.

The transformed image living in the target space, it is much bigger than the source image. But it seems it shoud not pose a big problem, as the image is defiend only in a small region of the world canvas. The WarpAffine class has a method:

mapSourceRect

to skip the no significant regions of the target space. I already debuggged to ensure that this method was working properly at rendering time.

plastilino
Offline
Joined: 2010-05-17

A couple of observations

- Using the affine transform in JAI gives me the same old good performance. Is WarpAffine that produces that slow paning and zooming.

- Things are worse when zooming in (oversampling)

Interpolation is always nearest, maybe I'm missing some other paramenter...