hi, i am able to get 2 dim arrays of the red, green and blue values for each pixel in an image.
how can i calculate the average intensity of the image from these arrays?
The mean intensity in each of the colour channels is a simple average: loop through each array, add up the values and divide by the number of elements (= no of pixels). However you must be careful that the sums do not overflow. Think carefully about the data type for each sum. If the image has only 8 bits per channel then you might get away with int as the type for the sum, but it will also depend on the number of pixels being summed. You need to estimate the maximum value the sum could possibly have in order to decide what its data type should be. Remember that no exception occurs in Java integer arithmetic when a sum overflows. Also don't forget that the top bit of the sum is used for the sign, otherwise overflow will occur at half the value you expected.
Then an interesting question is what you mean by the mean intensity of a multi-channel image. Is the mean intensity of each colour sufficient or do you need to combine them? You then get into considerations of how much weight to give to each channel and whether you want to mimic the spectral response of the eye. And that depends on what kind of camera the image came from originally: what is its spectral response for each channel? In the absence of any specification about wavelengths the simplest thing is to add the 3 mean intensities.
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.