• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question for JAI users

 
Giorgos Christoulas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am using JAI for an image processing application. I need to open Tiff image files, process them and then save the resulting image in a TIFF file.

The code I am using just to open the pca.tif image file and save the negative image is:

import javax.media.jai.*;
import java.awt.image.*;

class Negative{

public static void main(String arg[]){

PlanarImage orIm;
SampleModel sm;
DataBuffer data;
int[][][] imageArray;
int h,w,bands;

orIm = JAI.create("fileload","C:/sample.tif");
w = orIm.getWidth();
h = orIm.getHeight();
bands = orIm.getNumBands();

sm = orIm.getSampleModel();
data = orIm.getData().getDataBuffer();
imageArray = new int[bands][w][h];
// get pixel values
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++)
imageArray[b][i][j]=sm.getSample(i,j,b,data);
}
}

// invert pixel values
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++){
imageArray[b][i][j]=255 - imageArray[b][i][j];
}
}
}

// set new pixel values to original image
for (int b=0;b<bands;b++){
for (int i=0;i<w;i++){
for (int j=0;j<h;j++)
sm.setSample(i,j,b,imageArray[b][i][j],data);
}
}

RenderedOp op = JAI.create("filestore",orIm,"negSample.tif","tiff");

}
}

So far so good, but when I am using the above code to load the negative image file in order to produce the original I get the message:

java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!

The bizarre is that if I choose to open the negSample.tif image on Photoshop and then overwrite it leaving the name unchanged my program works fine!

Any suggestions?
Thanks in advance
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!