Lecture10 Java Advanced Imaging (JAI) API. Example First import java.awt.image.renderable.*; import javax.media.jai.*; public class RenderedChainTest.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Advanced Programming Issues JAI and Threads Courtesy ndanger at
Digital Images in Java Java’s imaging classes. Java imaging library  Java has good support for image processing  Must master a handful of classes and.
Generating GAIGS XML Scripts I Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Chapter 2: Graphics Programming
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Continuing to very Powerful Rendering Model Java2D.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Regional Processing There goes the neighborhood. Overview  Under point processing a single input sample is processed to produce a single output sample.
Java2 Printing API Jean-Cédric Desrochers March 9, 2000.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
Programming with Collections Collections in Java Using Arrays Week 9.
Lecture09 Push & Immediate Mode Imaging. Push Imaging Model (PIM) ImageProducer is an interface for objects which can produce the image data for Images.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Computer Vision Lecture 3: Digital Images
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
Image processing Lecture 4.
Basic 3D Graphics Chapter 5. Bird’s Eye View  Basic 3D Graphics –Basic concepts of 3D graphics, rendering pipeline, Java 3D programming, scene graph,
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 l Array Basics l Arrays in Classes and Methods l Programming with Arrays.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Image Synthesis Rabie A. Ramadan, PhD 3. 2 Our Problem.
Lambdas and Streams. Functional interfaces Functional interfaces are also known as single abstract method (SAM) interfaces. Package java.util.function.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Files and Streams. Java I/O File I/O I/O streams provide data input/output solutions to the programs. A stream can represent many different kinds of sources.
Week 2 - Wednesday CS361.
ImageJ EE4H, M.Sc Computer Vision Dr. Mike Spann
Image Synthesis Rabie A. Ramadan, PhD D Images.
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Algorithm and Programming Array Dr. Ir. Riri Fitri Sari MM MSc International Class Electrical Engineering Dept University of Indonesia 15 March 2009.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC508 Convolution Operators. CSC508 Convolution Arguably the most fundamental operation of computer vision It’s a neighborhood operator –Similar to the.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
INTRODUCTION TO GIS  Used to describe computer facilities which are used to handle data referenced to the spatial domain.  Has the ability to inter-
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Computer Science 320 Parallel Image Generation. The Mandelbrot Set.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
: Chapter 5: Image Filtering 1 Montri Karnjanadecha ac.th/~montri Image Processing.
Two Dimensional Arrays. Students will be able to: code algorithms to solve two- dimensional array problems. use 2-D arrays in programs. pass two-use 2-D.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Chapter 9 Introduction to Arrays Fundamentals of Java.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Mohammed AM Dwikat CIS Department Digital Image.
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
ITK 9.3. Level Set Segmentation Shape Detection Segmentation
Geospatial Data Abstraction Library(GDAL) Sabya Sachi.
INTRODUCTION TO GEOGRAPHICAL INFORMATION SYSTEM
Wavelets : Introduction and Examples
WINDOWING AND CLIPPING
More Image Manipulation
Image Processing, Lecture #8
WINDOWING AND CLIPPING
Image Processing, Lecture #8
Convolution Layer Optimization
A type is a collection of values
Presentation transcript:

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) { public static void main(String[] args) { // Load the image // Do Convolution // Multiply the coefficients // Save the image }}

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. JAI - A convenience class for instantiating operations. It has all sorts of create methods to create various operator nodes in the rendering chain.

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);

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

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.

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);

Babara_512.jpg

outputImageBabara.jpg

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.

Pull Imaging Model In the original AWT imaging Push Imaging Model was used and the center of this model was the Image class. 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. 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. 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. 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. 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. In general when you apply imaging operators this way, it forms a Directed Acyclic Graph (DAG). JAI has facilities to manipulate this graph.

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. 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. 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.

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

RenderedImage Attributes Image data related attributes: Image data related attributes: data – Image data available as a Raster object.data – Image data available as a Raster object. ColorModel – Color Model.ColorModel – Color Model. SampleModel – Sample Model.SampleModel – Sample Model. sources – Sources of image data available as a Vector object.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.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).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).

Renderable Chain Geometric operators such as translate, scale, rotate etc can be concatenated without rendering the intermediate images in between. 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. 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. 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. RenderableImage interface defines the behaviour of such renderable nodes. At the source and the sink of a renderable chain must be RenderedImages. At the source and the sink of a renderable chain must be RenderedImages.

RenderableImage interface RenderableImage has fewer attributes than RenderedImage because the pixels of RenderableImage have no pixel dimensions, except for the aspect ratio. RenderableImage has fewer attributes than RenderedImage because the pixels of RenderableImage have no pixel dimensions, except for the aspect ratio. The attributes of RenderableImage 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.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 RenderableImageminX, minY – The upper left-hand coordinates of a RenderableImage

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.

Package javax.media.jai.operator Large number of classes which implements OperationDescriptor interface. Large number of classes which implements OperationDescriptor interface. Each image operation in JAI must have a descriptor that implements this 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. 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.All information regarding the operation, such as its name, version, input, and properties should be listed.

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. 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. 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().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.Examples of known registry modes include "rendered", "renderable", "collection", "renderableCollection", "tileEncoder", "tileDecoder", "remoteRendered", "remoteRenderable", etc.

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; }

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

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);

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

outputImageBaboon.jpg

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.