"Error Diffusion" ArrayIndexOutOfBoundsException

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

"Error Diffusion" ArrayIndexOutOfBoundsException

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

Reply to Author | View Threaded | Show Only this Message

Hi, Im pretty new to the Java but I was wondering can somebody please help me with this problem.

Im trying to perform "Error Diffusion" on an image, providing my own lookup table of RGB values. However the operation seems to work correctly but when i try to display the image to check the output i get the following

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3
        at javax.media.jai.LookupTableJAI.findNearestEntry(LookupTableJAI.java:2023)
        at com.sun.media.jai.opimage.ErrorDiffusionOpImage.computeImageDefault(ErrorDiffusionOpImage.java:545)
        at com.sun.media.jai.opimage.ErrorDiffusionOpImage.computeImage(ErrorDiffusionOpImage.java:471)
        at javax.media.jai.UntiledOpImage.computeTile(UntiledOpImage.java:216)
        at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
        at javax.media.jai.OpImage.getTile(OpImage.java:1129)
        at javax.media.jai.PlanarImage.copyData(PlanarImage.java:2343)
        at javax.media.jai.RenderedOp.copyData(RenderedOp.java:2299)
        at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2525)
        at javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)

Please find my code snippet below:

int numbands = 3;
            byte[][] clusteredPixelsVals = new byte[5][numbands];

            clusteredPixelsVals[0][0] = (byte)224;
            clusteredPixelsVals[0][1] = (byte)225;
            clusteredPixelsVals[0][2] = (byte)224;
            clusteredPixelsVals[1][0] = (byte)269;
            clusteredPixelsVals[1][1] = (byte)170;
            clusteredPixelsVals[1][2] = (byte)169;
            clusteredPixelsVals[2][0] = (byte)124;
            clusteredPixelsVals[2][1] = (byte)123;
            clusteredPixelsVals[2][2] = (byte)116;
            clusteredPixelsVals[3][0] = (byte)33;
            clusteredPixelsVals[3][1] = (byte)30;
            clusteredPixelsVals[3][2] = (byte)28;
            clusteredPixelsVals[4][0] = (byte)84;
            clusteredPixelsVals[4][1] = (byte)78;
            clusteredPixelsVals[4][2] = (byte)70;

            LookupTableJAI LUT = new LookupTableJAI(clusteredPixelsVals);

            ParameterBlock pb = new ParameterBlock();
            pb.addSource(this.bufImage);
            pb.add(LUT);
            pb.add(KernelJAI.ERROR_FILTER_FLOYD_STEINBERG);
         
            this.srcPlanarImage = JAI.create("ErrorDiffusion", pb);

            MyInternalFrame frame = new MyInternalFrame(this.srcPlanarImage.getAsBufferedImage());
            frame.setVisible(true);
            desktop.add(frame);

Thanks in advance for any advice given.
[Message sent by forum member 'smackdown33' (smackdown33)]

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

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


Re: "Error Diffusion" ArrayIndexOutOfBoundsException

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

Reply to Author | View Threaded | Show Only this Message

Hi,

It looks like you've got the indices the wrong way round in your array for the lookup table.

It should be:
byte[][] clusteredPixelsVals = new byte[numbands][5];

with the other lines swapped to match.

<shameless plug>
In case it's of use, there is also an extension of the Lookup operator that can work with ranges of input values in the jai-tools project:

http://code.google.com/p/jai-tools/wiki/RangeLookup

</shameless plug>

Michael
[Message sent by forum member 'cafeanimal' (cafeanimal)]

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

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