Skip to main content

RGB TIFF to bi-level TIFF

3 replies [Last post]
davenatx512
Offline
Joined: 2007-04-11

Let me preface this post by saying I’m new to JAI Imageio.

I’m processing several TIFF images that are Black and White scans of legal documents. The images are compressed with LZW and I’m recompressing them with Group 4. This piece is working fine however I’ve discovered some of these images are RGB for an unknown reason. Obviously because it’s not bi-level the Group 4 compression fails.

I’ve been doing some research however I can’t figure out how to convert a RGB image to a bi-level image. Does anyone know of a post or any documentation that addresses this subject?

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

Please see this example

https://jai-demos.dev.java.net/source/browse/jai-demos/jai-samples/src/R...

in the jai-demos project.

On Wed, 11 Apr 2007, jai-imageio@javadesktop.org wrote:

> Let me preface this post by saying Iÿÿm new to JAI Imageio.
>
> Iÿÿm processing several TIFF images that are Black and White scans of legal documents. The images are compressed with LZW and Iÿÿm recompressing them with Group 4. This piece is working fine however Iÿÿve discovered some of these images are RGB for an unknown reason. Obviously because itÿÿs not bi-level the Group 4 compression fails.
>
> Iÿÿve been doing some research however I canÿÿt figure out how to convert a RGB image to a bi-level image. Does anyone know of a post or any documentation that addresses this subject?
>
> Thanks!
> [Message sent by forum member 'davenatx512' (davenatx512)]
>
> http://forums.java.net/jive/thread.jspa?messageID=211971
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

davenatx512
Offline
Joined: 2007-04-11

After doing some more research this is what I've come up with so far. To place credit where it's due I borrowed most of it from an example by Michael Pedersen on another forum. It seems to work however I'm still to new to JAI to know the best practices and most efficient ways of accomplishing things. Basically I'm getting the BufferedImage from the ImageReader and calling this method.

public BufferedImage toBilevel(BufferedImage src) {
// Combine the bands
double[][] matrix = { {0.114D, 0.587D, 0.299D, 0.0D} };
ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(matrix);
RenderedOp dst = JAI.create("bandcombine", pb, null);
// Take the combined image and create a bilevel Image
dst = JAI.create("binarize", dst, new Double(200));
BufferedImage bi = dst.getAsBufferedImage();

return bi;
}

Brian Burkhalter

That'll work too. I think it assumes that the input RGB is linear?

On Wed, 11 Apr 2007, jai-imageio@javadesktop.org wrote:

> After doing some more research this is what I've come up with so far. To place credit where it's due I borrowed most of it from an example by Michael Pedersen on another forum. It seems to work however I'm still to new to JAI to know the best practices and most efficient ways of accomplishing things. Basically I'm getting the BufferedImage from the ImageReader and calling this method.
>
> public BufferedImage toBilevel(BufferedImage src) {
> // Combine the bands
> double[][] matrix = { {0.114D, 0.587D, 0.299D, 0.0D} };
> ParameterBlock pb = new ParameterBlock();
> pb.addSource(src);
> pb.add(matrix);
> RenderedOp dst = JAI.create("bandcombine", pb, null);
> // Take the combined image and create a bilevel Image
> dst = JAI.create("binarize", dst, new Double(200));
> BufferedImage bi = dst.getAsBufferedImage();
>
> return bi;
> }
> [Message sent by forum member 'davenatx512' (davenatx512)]
>
> http://forums.java.net/jive/thread.jspa?messageID=211992
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net