Skip to main content

Set Up COMPRESSION_CCITT_T_4 for TIFF

6 replies [Last post]
jack987
Offline
Joined: 2009-01-06
Points: 0

Hi,

Does someone know how to set up the COMPRESSION_CCITT_T_4 when writting a TIFF file please?

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
marcojacob
Offline
Joined: 2006-07-10
Points: 0

You can give a TIFFImageWriteParam for writing with ImageIO and set the compression
to COMPRESSION_CCITT_T_4. Be aware that TIFF support is in the separate lib
jai_imageio.jar .

jack987
Offline
Joined: 2009-01-06
Points: 0

Hi marcojacob,

Thank your for your answer.

Here is the code I use :

// paramétrage du Tiff Writer
ios = ImageIO.createImageOutputStream(tiffFile);
writer.setOutput(ios);
TIFFImageWriteParam writeParam = new TIFFImageWriteParam(Locale.ENGLISH);
writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setCompressionType("CCITT T.6");

I tested it on 1 document scanned with my applet and I have 2 problems on the returned TIFF:
- I have the scanned document, but like if I had apply an invert (inversion?) filter (please excuse my English I'm French!)
- The file size seems to big : 171ko

Then, I opened the returned TIFF in Gimp and saved it in TIF choosing CCITT Group 4 and the new file has no inversion effect and its size is 52ko.

Can someone help me correct these problems please?

Thanks

marcojacob
Offline
Joined: 2006-07-10
Points: 0

I guess you need to convert the ColorSpace of the image to bilevel with JAI.
It depends on the kind of file you get. I don't know the best solution to
convert grayscale or color images to bilevel. You may ask at JAI forum.

----- copy from TIFFImageWriteParam javadoc -----
"The CCITT compression types are applicable to bilevel (1-bit) images only"
----- end copy from TIFFImageWriteParam javadoc -----

jack987
Offline
Joined: 2009-01-06
Points: 0

I thing my image is already in bilevel ; if it was not may be I would get an error telling me it can not be compressed as the image is not bilevel?

This is my code to convert the image I get from the scanner to a PlanarImage

protected PlanarImage MorenaImageToPlanarImage(MorenaImage morenaImage)
{
Image image = Toolkit.getDefaultToolkit().createImage(morenaImage);
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);
bufferedImage.createGraphics().drawImage(image, 0, 0, null);
PlanarImage planarImage = PlanarImage.wrapRenderedImage(bufferedImage);

return planarImage;
}

Does this line set up the image to bilevel? BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_BYTE_BINARY);

Thanks

jack987
Offline
Joined: 2009-01-06
Points: 0

I opened my TIFF in a real Tiff viewer called XnView and in fact the TIFF I get has no invert effect.

When I displayed the parameter of the TIFF I saw : Photometric Interpretation: Black=0

So I solved the problem of invert effect by setting up the TAG_PHOTOMETRIC_INTERPRETATION with the BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO constant.

But I am still having the file length to big (about 156ko). I expect to have a file about 50 ko. Any idea please?

Thanks.

Message was edited by: jack987

marcojacob
Offline
Joined: 2006-07-10
Points: 0

There are several factors that can impact on the size.
Maybe the conversion to bilevel has a different result.
Maybe the other software does some more work to the image to improve the quality
without mention it.