JAI Image Scaling Yields Poor, Aliased Results

I'm writing a program against JAI which performs some image scaling from JPEG and PNG source images.

At any rate, the scalingdown of images yields very poor results. I am performing the downscale with the following code:

privatestatic RenderedOp scaleImage(RenderedOp originalImage,float scaleFactor){

Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);

ParameterBlock params =new ParameterBlock();

params.addSource(originalImage);

params.add(scaleFactor);// x scale factor

params.add(scaleFactor);// y scale factor

params.add(0.0F);// x translate

params.add(0.0F);// y translate

params.add(interp);// interpolation method

return JAI.create("scale", params);

}

When I compare the results against a photoshop image size manipulation they are very poor.

When I compare results of java.awt.Image:getScaledInstance(x, y, java.awt.Image.SCALE_AREA_AVERAGING)

against photoshop, they are almost identical. Is there any way to use the area averaging algorithm with JAI? Has anyone implemented it under the javax.media.jai.Interpolation interface?

Thanks for any help!

-matt

[1666 byte] By [mmeadgoof] at [2007-9-26 6:22:41]
# 1
Did you ever resolve this problem? Mike Y.
myaco at 2007-7-1 15:23:11 > top of Java-index,Security,Cryptography...
# 2
I'm still having the same problem as you guys are, and I'm using the 1.4.1 JRE. Anyone have a solution that can still use the native libraries to do fast, high quality scaling?
dfortae at 2007-7-1 15:23:12 > top of Java-index,Security,Cryptography...
# 3

I figured out how to get binary images to scale down very crisp. Instead of using a scale algorithm directly, use the 'SubsampleBinaryToGray' function and scale it on the fly that way. Then you will get super fast scaling and it will use an algorithm just like the Area Averaging. This will obviously only work for binary and gray scale images. Color images would get scaled to gray and loose their color. Hope this helps.

Darrell

dfortae at 2007-7-1 15:23:12 > top of Java-index,Security,Cryptography...
# 4

I'm still trying to get this to work. I've found that if you scale using Image.getScaledInstance(), and then use a softening pass, the image is indistinguishable from those created by PhotoShop.

However, running the algorithm repeatedly on WinXP causes horizontal noise. This must be an error in the API.

Code and discussion here:

http://forum.java.sun.com/thread.jsp?forum=20&thread=223186

Drew Noakes

drewnoakes at 2007-7-1 15:23:12 > top of Java-index,Security,Cryptography...