• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java Advanced Imaging (JAI) Question

 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My knowledge of computer graphics, especially image formats and the like, is extremely limited so I may be using terms in an incorrect context.
Please ask for clarifications if you require them.
My java application uses a third-party DLL to print images on a printer device. The image to be printed must be a black-and-white TIFF image.
My java application obtains images via different methods, including retrieving an image stored as a BLOB in an Oracle database. The image may be a color image or a grayscale image or a black-and-white (i.e. binary) image and may not be in TIFF format, for example it may be a JPEG image.
How can I determine whether the image is black-and-white ?
How can I determine if the image is in TIFF format ?
How can I convert an image to TIFF format if it is not ?
How can I convert an image to black-and-white if it is not ?
Note that the current code -- which is legacy code that was not originally written by me -- uses JAI and the image is an instance of class

Thanks (in advance),
Avi.
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.jai.media.PlanarImage is a java.awt.image.RenderedImage - so you can get its Raster object, and from that you have access to its pixel data. So:

How can I determine whether the image is black-and-white ?


An image is B&W if all its pixels are either black or white, which means their individual R, G and B components all have values of 0, or all have values of 255.

How can I determine if the image is in TIFF format ?


TIFF is a file format, but a PlanarImage is an in-memory representation, so this question does not apply.

How can I convert an image to TIFF format if it is not ?


I generally use the javax.imageio.ImageIO class to load and store images. It doesn't support TIFF out of the box, but can be made to do so easily. Search for the JAI-ImageIO package. I'm not sure where binary builds can be found, since the screwed-up move from java.net to the Kenai infrastructure lots of projects there are broken.

How can I convert an image to black-and-white if it is not ?


Devise an algorithm that reads all pixel values and -based on their R, G and B components- decides whether each pixel should be black or white.

You'll have to do some reading and learning about image processing before you're ready to tackle these, if you have never done any of this.

Also, in the long term, I advise to move away from JAI; it's been dead for years now.
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that instead of black-and-white Avi actually means grayscale. If that is the case Wikipedia suggests the following calculation:
This calculation of gray is also what javax.swing.GrayFilter uses, although it increases or decreases the gray factor a bit afterwards.
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,
Thank you for your extremely helpful reply. In it you wrote:

I advise to move away from JAI


What alternative do you recommend?
You also wrote:

You'll have to do some reading and learning about image processing before you're ready to tackle these


Please provide some recommended resources for learning about image processing.

Rob,
You wrote in your reply:

I think that instead of black-and-white Avi actually means grayscale.


No, I actually meant black-and-white. :-)

Cheers,
Avi.
 
Tim Moores
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Avi Abrami wrote:

I advise to move away from JAI


What alternative do you recommend?


I'm not up on Java image processing libraries; one that I have used to good success and which is still under active development is ImageJ.

Please provide some recommended resources for learning about image processing.


Not sure; maybe start at Image processing or Java image processing and take it from there.
 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic