Could you describe the project in more detail? At least for most computers, 400,000 of anything isn't much.
You might be best off pre-processing the images. Image processing software includes a great deal of additional code that is present to get all the parts to function and provide a great user experience. A few lines of C (or Fortran, or Pascal, or any similar language) could be used to load the image into an array and then process the array. Anyone in the computer science department should be able to help with this.
Are you looking at grey scale, color, or something else? The simplest program would not even have to store the image in an array. It could read each pixel, increment a bin for tone by 1, and move to the next pixel. As a digital image the value can go from 0 to 255. If you want color, there will be more bins, though each pixel will be a mix of RGB or CYMK values.
Unfortunately, I have no idea if that even comes close to answering your question.
In my case is that I am having an output raster image whose range is suppose -2.366 to 11.45. The mean and median are different. I need to know the concentration of values of higher and lower end. And I am not able to deal with the negative values in the data.