Search code examples
javargbpixelbufferedimagecovariance

Get bits per pixel of a BufferedImage


I'm currently working on comparing a filtered image to its original (unfiltered) image using the SSIM (Structural similarity) index using Java.

My research brought me to a mathematical formula where the average, variance, covariance and the dynamic range of the two BufferedImages are needed.

Getting to calculate the average and the variance was not a big problem for me, however I can't figure out a way to get the number of bits per pixel needed to calculate the dynamic range, and the covariance value, is this something I can obtain from the BufferedImage.


Solution

  • BufferedImage has a getColorModel() method, and in the returned ColorModel object there is a getPixelSize() method which returns the number of bits per pixel described by that ColorModel.