Java Image Processing Query

COBOL

Active Member
Joined
Jan 16, 2012
Messages
69
Reaction score
0
Hi Everyone

I've just recently started my honours degree and I'm new to both Image Processing and Image Processing in Java. I'm writing a program that so far, just opens an image, and obtains an array of integers representing the RED, GREEN, BLUE, and ALPHA values - so far I managed to obtain those values when opening a colour image.

Here is the code I am using to open the image and obtain the RGB values:

try {
img = ImageIO.read(new File(path));
}
catch (IOException e) {
}

int[][] r = new int[img.getWidth()][img.getHeight()];
int[][] g = new int[img.getWidth()][img.getHeight()];
int[][] b = new int[img.getWidth()][img.getHeight()];
int[][] a = new int[img.getWidth()][img.getHeight()];

for( int i = 0; i < img.getWidth(); i++ ) {
for( int j = 0; j < img.getHeight(); j++ ) {
int color = img.getRGB(i,j);
a[j] = color >> 24 & 0xff;
r[j] = color >> 16 & 0xff;
g[j] = color >> 8 & 0xff;
b[j] = color & 0xff;
}
}

Now, when opening a Grayscale image, how to I do obtain a matrix of integers representing the grayscale values?
 
A grayscale image should be just a matrix of integers (1 integer per pixel) the value of the integer determines the scale of how gray the pixel is so eg 0 would be black and 255 would be white assuming 8bit integers per pixel.

im not sure if ImageIO supports this but it should otherwise you should bitbash :D
 
Top
Sign up to the MyBroadband newsletter
X