What is the best way to get the pixel brightness
I have a gray-scale .png image. The pixel brightness is used to communicate the information that i need in my application. Note that i do not show this image in my application, the png file is only used to communicate data. Since this data is being collected as an image at the source we are using a png file to pass around this data. The code is given below
JarEntry entry = m_jarFile.getJarEntry("imageFile.png");
InputStream stream = m_jarFile.getInputStream(entry);
BufferedImage image = ImageIO.read(overlayImageFileStream);
int cols = overlayImage.getWidth();
int rows = overlayImage.getHeight();
short[][] m_pixelBrightnessValues =newshort[cols][rows];
for (int i=0; i<cols; i++){
for (int j=0; j><rows; j++){
/** BEGIN: Takes too much time */
int rgb = overlayImage.getRGB(i, j);
// convert to HSB values.
int red = (rgb>>16)&0xFF;
int green = (rgb>>8)&0xFF;
int blue = rgb&0xFF;
float[] inputHSB =newfloat[3];
inputHSB = Color.RGBtoHSB(red, green, blue, inputHSB);
/** END: Takes too much time */
float brightness = inputHSB[2];
m_pixelBrightnessValues[i][j]= (short)Math.round(brightness * MAX_BRIGHTNESS_VALUE);
}
}
Some portion of the code above takes too much time. I have been tinkering with the following approaches:
1). I can parse the png file myself and extract the brightness information thus bypassing the creation of the BufferedImage altogether.
2). I can continue to create BufferedImage but find out a way to grab brightness directly from the buffered image.
I prefer option 2, since option 1 will require that I figure out png format and then write custom png parsing logic. I have explored all the methods of BufferedImage and it seems there is no way of getting the HSB directly, the only thing readily availabe is RGB values.
I would really appreciate any pointers (e.g. is there something in the Raster that can let me access the brightness data directly ?)
-kashif

