I have a BufferedImage of type TYPE_INT_BGR. I need to do a phased comparison with another BufferedImage in order to calculate the “distance” between two images. I have something that works, but slow. I get a pixel from a “reference” image, split it into RGB bytes with:
int pixel = referenceImage.getRGB(col, row); int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff;
I compare the r / g / b values with the corresponding pixel of the candidate image and summarize the difference squares.
Is there a faster way to make such a comparison? Looking at the source of the JRE, I see that BufferedImage.getRGB () is actually ORing the RGB values from the raster together, which is useless for my purposes, since I just split it into bytes again.
I will try to do this directly, but I wonder if there is a better way to do this, either using the Java API or a third-party API that I could skip.
java rgb bufferedimage java-2d
George Armhold
source share