Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a TIFF file by tiles with Java?

Let's say I have a very large TIFF image as input. I am not able to load this image entirely because of memory specification I must comply with. So the following is not an option :

BufferedImage data = ImageIO.read(image);

Is there any Java library allowing to read a specific part of the image without buffering the whole image ? Or some ways to get TIFF tiles from a stream ?

like image 340
Pierre Villard Avatar asked Oct 01 '14 10:10

Pierre Villard


People also ask

How read TIF file in Java?

How to read a TIFF image in Java with ImageIO. Step 1 Download TwelveMonkeys plugin and add to your class path. Step 2 Create a File handle, InputStream, or URL pointing to the raw TIFF image. Step 3 ImageIO will now be able to read a TIFF file into a BufferedImage.

Can ImageJ open TIF?

Introduction. The ImageJ software (https://imagej.nih.gov/ij/) is a widely-used image viewing and processing software, particularly popular in microscopy and life sciences. It supports the TIFF image format (and many others).

What program can view TIFF files?

Open your TIF file in any standard image viewer and editor program such as Adobe Photoshop, CorelDRAW, MS-Paint, etc., that supports the TIF file.


2 Answers

ImageIO can provide you an ImageReader for Tiff, and then you can use readTile. ImageIO has several getImageReadersBy... methods.

I am not aware whether tiff is supported by ImageIO, but ImageIO uses java SPI so one may plug-in ImageReaders and ImageWriters.

In fact this is a short-cut for read with ImageReadParam configured for tiles.

Never used tiles, but seeing the prior answer, I wanted to point this option out.

like image 98
Joop Eggen Avatar answered Sep 19 '22 22:09

Joop Eggen


There is no way in the native Java libraries that's able to read a Tiff file in it's components.... so, you are stuck with either using an external library, or building your own.

@Joop has provided a link in to the native Java library I was not aware of (know your tools!) If you cannot find the full support you need there, you may find the following useful:

The specification for Tiff files is not hugely complicated. I would consider writing my own file reader for it.

  • Wiki page
  • File specification (pdf)
  • Java Advanced Imaging API (JAI)

The Java JAI looks like it has signifciantly extended support for reading and parsing TIFF files. Consider:

  • Documentation index
  • Javadoc
  • TiffDescriptor
like image 34
rolfl Avatar answered Sep 20 '22 22:09

rolfl