Skip to main content

"Error Diffusion" ArrayIndexOutOfBoundsException

1 reply [Last post]
smackdown33
Offline
Joined: 2006-08-04

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)

Can someone please help me with this problem?

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 was edited by: smackdown33

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cafeanimal
Offline
Joined: 2008-04-29

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.


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

Michael