Skip to main content

Why isn't BILINEAR scaling smarter?

5 replies [Last post]
cowwoc
Offline
Joined: 2003-08-24

There is an article that mentions that one can improve the look of downscaling using BILINEAR by downscaling multiple times (each time by half): http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledin...

The paragraph in question reads: "To combat this issue, you can use a multi-step approach when downscaling by more than two times; this helps prevent the information loss issue and produces a much higher quality result that is visually quite close to that produced by Image.SCALE_AREA_AVERAGING"

My question is, why doesn't Java do this automatically under the hood? If I request BILINEAR or BICUBIC downscaling for a factor greater than two, why doesn't Java either do multistep scaling on my behalf or why doesn't the Java2D team add a new hint (to maintain backwards compatibility) which will tell Java2D to apply these filters using the multi-step method? I would much rather have this supported by the JDK than having people reinvent the wheel over and over.

Thank you,
Gili

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

[I sent this out a few days ago, but replied to the wrong address so I
don't believe it went through - sending again...jim]

The Bilinear filtering algorithm is a well known algorithm that has a
very specific definition which we follow. If we automatically applied
multiple steps based on the scaling factor then we would violate that
definition and have to call it something else.

On a more practical note, if someone has determined that the caveats of
the bilinear algorithm are sufficient for their needs and we did perform
multiple steps instead of one step then we would reduce performance
which that particular developer might not appreciate.

On another practical note, hardware accelerators do not perform
multi-step scaling so we wouldn't be able to fire the request off to the
video card and get hardware accelerated scaling (nearly free) if we
instituted such a policy behind the scenes.

If we did provide that mechanism automatically then it would have to be
under a different name so that the developer could buy into the specific
tradeoffs that it provides (better quality for >2x downscaling at the
expense of about 7x performance).

In the meantime, we publish blogs like the one you point to in order to
educate our programmers about the definitions of the graphical terms and
processes that our APIs allow them to access and how to use those well
defined industry standard mechanisms to achieve their needs...

...jim

java2d@javadesktop.org wrote:
> There is an article that mentions that one can improve the look of downscaling using BILINEAR by downscaling multiple times (each time by half): http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledin...
>
> The paragraph in question reads: "To combat this issue, you can use a multi-step approach when downscaling by more than two times; this helps prevent the information loss issue and produces a much higher quality result that is visually quite close to that produced by Image.SCALE_AREA_AVERAGING"
>
> My question is, why doesn't Java do this automatically under the hood? If I request BILINEAR or BICUBIC downscaling for a factor greater than two, why doesn't Java either do multistep scaling on my behalf or why doesn't the Java2D team add a new hint (to maintain backwards compatibility) which will tell Java2D to apply these filters using the multi-step method? I would much rather have this supported by the JDK than having people reinvent the wheel over and over.
>
> Thank you,
> Gili
> [Message sent by forum member 'cowwoc' (cowwoc)]
>
> http://forums.java.net/jive/thread.jspa?messageID=227363
>
> ===========================================================================
> 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".

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

Ken Warner

Bilinear interpolation uses a very small 4 pixel neighborhood to interpolate.

My experience is that it works pretty good at upscaling -- maybe not so good
at downscaling. Other interpolation methods work better at down scaling because
they use a larger neighborhood. Bicubic; Lanczos etc. use a 16 pixel
neighborhood and they do better at downscaling because they take a weighted
average over a larger neighborhood.

Automatically forcing multiple interpolations might not be the best thing
to do on all images. Like for example, what if the dimensions of the image
are both prime numbers. Or what if the image is really wide and not very
high -- like a 360 degree panorama? How do you automatically apply a multi-step
downscaling interpolation?

No API can be made flexible and smart enough to
handle all possible situations. That's why programmers still have jobs.

Jim Graham wrote:
> [I sent this out a few days ago, but replied to the wrong address so I
> don't believe it went through - sending again...jim]
>
> The Bilinear filtering algorithm is a well known algorithm that has a
> very specific definition which we follow. If we automatically applied
> multiple steps based on the scaling factor then we would violate that
> definition and have to call it something else.
>
> On a more practical note, if someone has determined that the caveats of
> the bilinear algorithm are sufficient for their needs and we did perform
> multiple steps instead of one step then we would reduce performance
> which that particular developer might not appreciate.
>
> On another practical note, hardware accelerators do not perform
> multi-step scaling so we wouldn't be able to fire the request off to the
> video card and get hardware accelerated scaling (nearly free) if we
> instituted such a policy behind the scenes.
>
> If we did provide that mechanism automatically then it would have to be
> under a different name so that the developer could buy into the specific
> tradeoffs that it provides (better quality for >2x downscaling at the
> expense of about 7x performance).
>
> In the meantime, we publish blogs like the one you point to in order to
> educate our programmers about the definitions of the graphical terms and
> processes that our APIs allow them to access and how to use those well
> defined industry standard mechanisms to achieve their needs...
>
> ...jim
>
> java2d@javadesktop.org wrote:
>
>> There is an article that mentions that one can improve the look of
>> downscaling using BILINEAR by downscaling multiple times (each time by
>> half):
>> http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledin...
>>
>>
>> The paragraph in question reads: "To combat this issue, you can use a
>> multi-step approach when downscaling by more than two times; this
>> helps prevent the information loss issue and produces a much higher
>> quality result that is visually quite close to that produced by
>> Image.SCALE_AREA_AVERAGING"
>>
>> My question is, why doesn't Java do this automatically under the hood?
>> If I request BILINEAR or BICUBIC downscaling for a factor greater than
>> two, why doesn't Java either do multistep scaling on my behalf or why
>> doesn't the Java2D team add a new hint (to maintain backwards
>> compatibility) which will tell Java2D to apply these filters using the
>> multi-step method? I would much rather have this supported by the JDK
>> than having people reinvent the wheel over and over.
>>
>> Thank you,
>> Gili
>> [Message sent by forum member 'cowwoc' (cowwoc)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=227363
>>
>> ===========================================================================
>>
>> 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".
>
>
> ===========================================================================
> 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".
>
>

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

fabriziogiudici
Offline
Joined: 2006-01-04

> No API can be made flexible and smart enough to
> handle all possible situations. That's why
> programmers still have jobs.

I agree and this is especially true for image manipulation. There's no thing such a single way to do e.g. image resizing. For instance, the approach with multiple passes is good for dealing with images functional for the l&f of a desktop application, while if we'd like to do something more quality-oriented something more complex is needed (refer to this post for an example http://archives.java.sun.com/cgi-bin/wa?A2=ind0311&L=jai-interest&P=R957...).

IMHO it's correct that Java only provides low-level APIs, that is building blocks that should be put together in different ways for different needs.

PS Sorry, this is some kind of self-promotion :-) but this is related to the topic: http://mistral.tidalwave.it/infoglueDeliverLive/ViewPage.action?siteNode...

Ken Warner

Exactly! Just look at some of the various Graphics API's that have succeeded
and failed. OpenGL -- succeed -- simple, low level graphics that the programmer
put together. I think, anyway I like it.

GKS -- remember GKS? -- failed. High level display lists. Multi level and
really complicated.

How about Java3D? Anybody using that? VRML -- anybody using that?

What succeeds? Java2D. ImageIO and JAI. Simple low level stuff that the programmer
puts together.

Anyway that's the way I see things. I have a feeling that everbody will have
a different opinion....

> IMHO it's correct that Java only provides low-level APIs, that is building
> blocks that should be put together in different ways for different needs.

java2d@JAVADESKTOP.ORG wrote:
>>No API can be made flexible and smart enough to
>>handle all possible situations. That's why
>>programmers still have jobs.
>
>
> I agree and this is especially true for image manipulation. There's no thing such a single way to do e.g. image resizing. For instance, the approach with multiple passes is good for dealing with images functional for the l&f of a desktop application, while if we'd like to do something more quality-oriented something more complex is needed (refer to this post for an example http://archives.java.sun.com/cgi-bin/wa?A2=ind0311&L=jai-interest&P=R957...).
>
> IMHO it's correct that Java only provides low-level APIs, that is building blocks that should be put together in different ways for different needs.
>
> PS Sorry, this is some kind of self-promotion :-) but this is related to the topic: http://mistral.tidalwave.it/infoglueDeliverLive/ViewPage.action?siteNode...
> [Message sent by forum member 'fabriziogiudici' (fabriziogiudici)]
>
> http://forums.java.net/jive/thread.jspa?messageID=228317
>
> ===========================================================================
> 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".
>
>

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

Ken Warner

Couldn't you do this in a loop yourself and control the final interpolation just the way you want it?

What if the image isn't divisible by two in one of it's dimensions? I think that it's better to leave
the use of interpolation in the hands of the programer.

java2d@JAVADESKTOP.ORG wrote:
> There is an article that mentions that one can improve the look of downscaling using BILINEAR by downscaling multiple times (each time by half): http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledin...
>
> The paragraph in question reads: "To combat this issue, you can use a multi-step approach when downscaling by more than two times; this helps prevent the information loss issue and produces a much higher quality result that is visually quite close to that produced by Image.SCALE_AREA_AVERAGING"
>
> My question is, why doesn't Java do this automatically under the hood? If I request BILINEAR or BICUBIC downscaling for a factor greater than two, why doesn't Java either do multistep scaling on my behalf or why doesn't the Java2D team add a new hint (to maintain backwards compatibility) which will tell Java2D to apply these filters using the multi-step method? I would much rather have this supported by the JDK than having people reinvent the wheel over and over.
>
> Thank you,
> Gili
> [Message sent by forum member 'cowwoc' (cowwoc)]
>
> http://forums.java.net/jive/thread.jspa?messageID=227363
>
> ===========================================================================
> 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".
>
>

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