Issue with scale operator

View: New views
3 Messages — Rating Filter:   Alert me  

Issue with scale operator

by jai-interest-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I use JAI to make thumbnails of images. There are 2 issues I face:

1) It is very slow (and it shouldn't): around 4 to 5 seconds per thumbnail
2) Anti-aliasing does not work

The second issue is the one that bothers me the most as my thumbnails come out with a very poor quality. Here is a shortened version of the code I use (which also performs a rotation) :

        Dimension clip = ClipUtil.clip(srcImageSize, frameSize);
        float heightScale = clip.height / (float)srcImageSize.height;
        float widthScale = clip.width / (float)srcImageSize.width;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(srcImage);
        pb.add(widthScale);
        pb.add(heightScale);
        pb.add(0.0f);
        pb.add(0.0f);
        pb.add(new InterpolationNearest());
        RenderingHints antialising = new RenderingHints(
                        RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
        PlanarImage scaledImage = JAI.create("scale", pb, antialising);

        log.trace("Rotate image if necessary");
        // rotate image if necessary
        if(orientation == null || orientation == Orientation.TOP_LEFT){
                resultImage = scaledImage.getAsBufferedImage();
        } else {
                pb = new ParameterBlock();
                pb.addSource(scaledImage);
                TransposeType rotation = null;
                if(orientation == Orientation.LEFT_BOTTOM){
                        rotation = TransposeDescriptor.ROTATE_270;
                } else if(orientation == Orientation.TOP_RIGHT){
                        rotation = TransposeDescriptor.ROTATE_90;
                } else if(orientation == Orientation.RIGHT_BOTTOM){
                        rotation = TransposeDescriptor.ROTATE_180;
                }
                pb.add(rotation);
                PlanarImage rotatedImage = (PlanarImage)JAI.create("transpose", pb);
                resultImage = rotatedImage.getAsBufferedImage();
        }

I use JAI 1.1.3 with Sun's Java6 jvm on Linux.

Thanks!
Math
[Message sent by forum member 'avoinemt' (avoinemt@...)]

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

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Issue with scale operator

by jai-interest-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Math,
as mentioned in earlier threads you should use "filteredsubsample" instead of “scale” for downsampling.
http://www.j2ee.me/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/FilteredSubsampleDescriptor.html

or just "subsampleaverage"
http://www.j2ee.me/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/SubsampleAverageDescriptor.html

e.g.
ParameterBlock pb = new ParameterBlock();
pb.addSource(pi);

pb.add(x); //x... integer downsample factor
pb.add(y); //y... integer downsample factor
pb.add(new float[] {1.0f});  //A quadrant symmetric filter generated from a Gaussian kernel
pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
//or
//pb.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
//pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC));
//pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2));
PlanarImage thumb = JAI.create("filteredsubsample", pb);
                               
//or
pb.add(x));//x... double downsample factor
pb.add(y); //y... double downsample factor
PlanarImage thumb  = JAI.create("subsampleaverage", pb);

Hope this helps,
Helmut
[Message sent by forum member 'helaha' (e288cc@...)]

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

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: Issue with scale operator

by jai-interest-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried both solutions and the latter (using "subsampleaverage") seems to do the trick. I could not make the first solution work, either because I don't understand how it works, or it is not possible to scale the src image by a fraction (downsample factor is an Integer??).

Thanks for answering my question!
Math
[Message sent by forum member 'avoinemt' (avoinemt@...)]

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

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...