Java Advanced Imaging (JAI) Application Program Interface (API) provides a low cost, licensing independence and inter-platform independent API to create java applications for image processing, representation and visualization . It gives a professional approach to image manipulation by allowing to write our own routines rather than just using commercial image processing systems.
JAI provides an effective solution for handling large image files over the internet. There are different classes in JAI to deal with image processing.
JAI provides an effective solution for handling large image files over the internet. There are different classes in JAI to deal with image processing.
PlanarImage
This is the basic class used for image representation, it uses Raster objects to store the pixel data associated with the image. The PlanarImage image object has a ColorModel with it,which specifies how the pixel data is converted into colors.
TiledImage
This class is used to read and write image data. It isa sub class of the above PlanarImage class.
RenderedOp
This is also a sub-class of PlanarImage used to represent a node in rendered imaging chain , which is one of the most powerful concepts in JAI allowing processing of an image in a series of steps.
Advantages of JAI
Consider an example to understand how the image is processed using JAI
- Web server with an application server
1.load the image using
FileSeekableStream fstream = = new FileSeekableStream(“file”);
2.create an operator to decode the image
RenderedOp image = JAI.create(“stream”, fstream);
3.create an interpolation object and parameterBlock
4.Interpolation intp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
ParameterBlock paramb= new ParameterBlock();
paramb.addSource(image);
paramb.add(3.0F); // x scale
paramb.add(3.0F); // y scale
paramb.add(1.0F); // x translate
paramb.add(1.0F); // y translate
paramb.add(intp); // interpolation
5. RenderedOp imagenew = JAI.create(“scale”, params);
or
float scale = ‘newWidth’ / image.getWidth();
RenderingHints rh = new RenderingHints(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
FileSeekableStream fstream = = new FileSeekableStream(“file”);
2.create an operator to decode the image
RenderedOp image = JAI.create(“stream”, fstream);
3.create an interpolation object and parameterBlock
4.Interpolation intp = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
ParameterBlock paramb= new ParameterBlock();
paramb.addSource(image);
paramb.add(3.0F); // x scale
paramb.add(3.0F); // y scale
paramb.add(1.0F); // x translate
paramb.add(1.0F); // y translate
paramb.add(intp); // interpolation
5. RenderedOp imagenew = JAI.create(“scale”, params);
or
float scale = ‘newWidth’ / image.getWidth();
RenderingHints rh = new RenderingHints(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
RenderedOp imagenew = JAI.create(“SubsampleAverage”,
image, scale, scale, rh);
6.Output the image:
JAI.create(“encode”, resizedImage, outputStream, “JPEG”, null);
JAI helps programmers to make easy image processing applications and it reduces substantial programming effort of developers by over re-coding algorithms. JAI provides above 80 pre-canned algorithms to save development time. JAI is more portable than any other typical libraries targeted for specific platforms. It provides a scalable solution in image processing in PDA, laptop etc.