enclume42 <> wrote:
> I need to process scientific images within a Java program.
> I have to have simultaneously 2 images of 4400x8618 pixels
> (coded in 16-bits greylevels) in memory, to be loaded from
> an about 80 MB TIFF file. (The process later involves working
> on the DataBuffer obtained from the Raster of the BufferedImage,
> which works well with smaller images.)
>
> Unfortunately, when I try to load the image, the line
> image = ImageIO.read(file);
> of my code yields the following exception:
> Exception in thread "main" java.lang.OutOfMemoryError
>
> This is on a 1 GB RAM, 2 GB swap box.
>
> Questions:
> - Given the data about my images given above, is there a rule
> which allows the calculation a the memory required to load
> these images ?
I think it'll depend on how will ImageIO handles different formats - it
may well be that it takes 4 bytes per pixel, if it converts everything
into ARGB.
> - What about the memory required to extract the DataBuffer
> and work with it ?
>
> - Any idea on how I could decrease the amount of memory needed ?
> (I could load partial-image DataBuffer, but the bottleneck now
> is the image loading...)
Do you definitely need to decrease the amount of memory needed? If the
problem is that your app is failing, the first thing to do is
*increase* the amount of memory available to the JVM. By default it's
only 64Mb. You can increase this using command-line parameters when
starting the JVM. For instance:
java -Xmx768M mypackage.MyClass
would start the JVM with a maximum heap size of 768Mb, which may well
be somewhat better for you...
--
Jon Skeet - <>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too