Login  Register

Re: Group 4 fax tiff ?

Posted by Johannes Hermen on Jan 21, 2008; 7:07am
URL: http://imagej.273.s1.nabble.com/Group-4-fax-tiff-tp3697509p3697510.html

> Hi
> I was trying to load a Group 4 fax tiff file in IJ but this does not
seem to
> be supported either natively nor with the LOCI importer.

It is not directly ImageJ, but we open G4 TIFF files in Java using JAI.

        /**
         * converts the TIFF's from the byte[] to buffered images
         * @param bArr
         * @return
         */
        private Vector<BufferedImage> getAsBufferedImages(byte[] bArr) {
                Vector<BufferedImage> v = new Vector<BufferedImage>();
                ByteArraySeekableStream stream = null;
        try {
            stream = new ByteArraySeekableStream(bArr);
        } catch (IOException e) {
            e.printStackTrace();
        }
        TIFFDecodeParam decodeParam = new TIFFDecodeParam();
        decodeParam.setDecodePaletteAsShorts(true);
        try {
                BufferedImage bi = null;

                ImageDecoder dec = ImageCodec.createImageDecoder("tiff",
stream, decodeParam);
                for (int i = 0; i < dec.getNumPages(); i++) {
                        RenderedImageAdapter ria = new
RenderedImageAdapter(dec.decodeAsRenderedImage(i));
                        bi = ria.getAsBufferedImage();
                        v.add(bi);
                        }
        } catch (IOException e) {
                logger.log(Level.WARNING, "Error converting TIFFs", e);
                }
                return v;
        }

This returns a Vector of Buffered Images, as the TIFF can contain multiple
pages.

Hope this helps.

        Johannes

-----------------------------------------------------------------
Johannes Hermen  -  Ingenieur de Recherche
[hidden email]
-----------------------------------------------------------------
CRP Henri Tudor  http://www.santec.tudor.lu
29, Avenue John F. Kennedy
L-1855 Luxembourg
-----------------------------------------------------------------