1 / 26

Lecture10

Lecture10. Java Advanced Imaging (JAI) API. Example First. import java.awt.image.renderable.*; import javax.media.jai.*; public class RenderedChainTest { public static void main(String[] args) { // Load the image // Do Convolution // Multiply the coefficients

mort
Download Presentation

Lecture10

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture10 Java Advanced Imaging (JAI) API

  2. Example First import java.awt.image.renderable.*; import javax.media.jai.*; public class RenderedChainTest { public static void main(String[] args) { // Load the image // Do Convolution // Multiply the coefficients // Save the image } }

  3. Rendered Chain Operators: FileLoad ParameterBlock pb = new ParameterBlock(); pb.add(“lena_512.jpg"); RenderedOp originalSourceImage = JAI.create("FileLoad",pb); • Java Advanced Imaging API has this phylosophy that the parameters required for a particular operation are put into ParameterBlock object and calls a some kind of method with operation name and a ParameterBlock object as the parameters. • This ParameterBlock object must be developed to suit the operation to be undertaken. • JAI - A convenience class for instantiating operations. It has all sorts of create methods to create various operator nodes in the rendering chain.

  4. Rendered chain: Convolve pb = new ParameterBlock(); pb.addSource(originalSourceImage); // supply the source // to convolve // construct the kernel ( filter really) float oneBys2 = 1/2.0f; float[] kernelData = {oneBys2, -oneBys2, -oneBys2, oneBys2}; KernelJAI haarKernel = new KernelJAI(2,2,0,0,kernelData); pb.add(haarKernel); RenderedOp convolvedImage = JAI.create("Convolve",pb);

  5. KernelJAI • public KernelJAI(int width, int height, int xOrigin, int yOrigin, float[] data) • Constructs a KernelJAI with the given parameters. • Parameters: • width - the width of the kernel. • height - the height of the kernel. • xOrigin - the X coordinate of the key kernel element. • yOrigin - the Y coordinate of the key kernel element. • data - the float data in row-major format.

  6. Rendered Chain: MultiplyConst pb = new ParameterBlock(); pb.addSource(convolvedImage); int height = convolvedImage.getHeight(); int width = convolvedImage.getWidth(); double[height * width] constants; for(int i=0;i < height * width; i++) constants[i] = 40.0; pb.add(constants); RenderedOp constantMultipliedImage = JAI.create("MultiplyConst",pb); • The MultiplyConst operation takes one rendered or renderable image and an array of double constants, and multiplies every pixel of the same band of the source by the constant from the corresponding array entry.

  7. Rendered Chain: Saving an image pb = new ParameterBlock(); pb.addSource(constantMultipliedImage); // add source for "FileStore" pb.add("outputImage.jpg"); // output file name pb.add("JPEG"); // output file format JAI.create("FileStore",pb);

  8. Babara_512.jpg

  9. outputImageBabara.jpg

  10. Rendered Chain

  11. Rendered Chain • Two types of chains: one the RenderedOp chain and the other OpImage chain. • OpImage is the base class for all image operations. It provides a home for information and functionalities common to all the op-image classes, and implements various utility methods that may be useful to a specific operation. • A RenderedOp stores an operation name, a ParameterBlock containing sources and parameters for the operation, and a RenderingHints containing hints which may be used in rendering the node.

  12. Pull Imaging Model • In the original AWT imaging Push Imaging Model was used and the center of this model was the Image class. • Similarly at the center of Java2D Immediate Mode Imaging Model was the BufferedImage class which implements the RenderedImage interface. • But at the center Java Advanced Imaging API is the PlanarImage class which implements the Pull Imaging Model. • When a request is made at the end of the rendered chain to render the image, this request travels through the chain upto the source and then image data is pulled through the chain as needed. • An imaging operator can have zero or more parameters. Each time the image passes the node, an imaging operator is applied with appropriate parameters. The transformed image is passed to the nest node until it reaches a “Sink”. • In general when you apply imaging operators this way, it forms a Directed Acyclic Graph (DAG). JAI has facilities to manipulate this graph.

  13. RenderedImage Interface • A rendered image is divided into a number of rectangular tiles. Each tile consists of image data covered by the rectangular region of the tile. • To map tiles in the image, an imaginary grid is thrown over it. Each cell in this grid represents a tile in the image. The size of this grid need not exactly match the size of the image.

  14. RenderedImage Attributes • Geometry related attributes: • width, height – width and height of the rendered image. • minX, minY – The upper left-hand coordinates of a rendered image. • numXTiles, numYTiles – The number of tiles in the x and y directions. • minTileX, minTileY – The minimum tile indices in the x and y directions. • tileWidth, tileHeight – Tile width and height • tileGridOffSetX, tileGridOffSetY – The x and y offsets of the first tile with respect to the origin of the coordinate system.

  15. RenderedImage Attributes • Image data related attributes: • data – Image data available as a Raster object. • ColorModel – Color Model. • SampleModel – Sample Model. • sources – Sources of image data available as a Vector object. • property – Property of a rendered image. The getProperties() method returns all the properties of the rendered image. • tile – A tile available as a Raster object. The getTile(xIndex,yIndex) method returns the tile as a Raster object at the tile index (xIndex,yIndex).

  16. Renderable Chain • Geometric operators such as translate, scale, rotate etc can be concatenated without rendering the intermediate images in between. • If the image need not rendered at the intermediate stages, you can use renderable chain. • In a renderable chain, the image data is computed only at the end of the chain, i.e. the Sink. • RenderableImage interface defines the behaviour of such renderable nodes. • At the source and the sink of a renderable chain must be RenderedImage’s.

  17. RenderableImage interface • RenderableImage has fewer attributes than RenderedImage because the pixels of RenderableImage have no pixel dimensions, except for the aspect ratio. • The attributes of RenderableImage • width, height – Width and Height defines the aspect ratio. The getHeight() method always returns 1.0f, and getWidth() method returns the aspect ratio. • minX, minY – The upper left-hand coordinates of a RenderableImage

  18. Renderable Chain • This technique is suitable for rendering independent operations where the RenderingContext is either not required or not known until the final node in the imaging chain. • One of the rendering attribute is the resolution and we can achieve resolution independence as we follow the renderable chain. • The problem with the rendered chain is that rendering hints such as emphasis on speed or emphasis on quality have to be decided before knowing the final information for intermediate nodes. But in the renderable chain these issues are decided only after final rendering hints are known.

  19. Package javax.media.jai.operator • Large number of classes which implements OperationDescriptor interface. • Each image operation in JAI must have a descriptor that implements this interface. • This interface provides a comprehensive description of a specific image operation. • All information regarding the operation, such as its name, version, input, and properties should be listed.

  20. OperationRegistry class • The OperationRegistry class maps a descriptor name (for example, an image operation name) into the particular kind of factory object requested, capable of implementing the functionality described by the descriptor. • At the highest level all objects are registered against some mode. • A mode is specified by a String which must be one of those returned by RegistryMode.getModeNames(). • Examples of known registry modes include "rendered", "renderable", "collection", "renderableCollection", "tileEncoder", "tileDecoder", "remoteRendered", "remoteRenderable", etc.

  21. Renderable Chain: Example public RenderedImage processChain() { // Load the image into a RenderedOp // Create a RenderableOp image from RenderedOp // Perform the invert operation // Perform addconst operation // Create the final RenderedImage return finalRenderedImage; }

  22. Create a RenderableOp image from RenderedOp ParameterBlock pb1 = new ParameterBlock(); pb1.add("baboon_256.jpg"); RenderedOp originalSourceImage = JAI.create("fileLoad",pb1); ParameterBlock pb2 = new ParameterBlock(); pb2.addSource(originalSourceImage); pb2.add(null); // use default for the operation chain for lower // resolution images pb2.add(null); // use default for maximum dimension for lowest // resolution image pb2.add(0.0f); // use default for minimum rendering independent // x of destination pb2.add(0.0f); // use default for minimum rendering independent // y of destination pb2.add(1.0f); // rendering-independent height RenderableOp renderableImg = JAI.createRenderable("renderable",pb2);

  23. Perform the invert operation & addconst operation ParameterBlock pb3 = new ParameterBlock(); pb3.addSource(renderableImg); RenderableOp op1 = JAI.createRenderable("invert",pb3); ParameterBlock pb4 = new ParameterBlock(); pb4.addSource(op1); // Op1 as the source double[] c = {2.0d}; pb4.add(c); // 2.0f as the constant RenderableOp op2 = JAI.createRenderable("addconst", pb4);

  24. Create the final RenderedImage RenderedImage finalRenderedImage = op2.createDefaultRendering();

  25. outputImageBaboon.jpg

  26. Renderable Chain • The createRendering method does not actually compute any pixels, bit it does instantiate a RenderedOp chain that will produce a rendering at the appropriate pixel dimensions. • The Renderable graph can be thought of as a template that, when rendered, causes the instantiation of a parallel Rendered graph to accomplish the actual processing.

More Related