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?
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?