Title: Image Processing Techniques using the JavaTM Advanced ImagingTM (JAI) API Framework
1Image Processing Techniques using the JavaTM
Advanced ImagingTM (JAI) API Framework
- Bill Champlin
- UCCS / CS525
- Spring 08
2Agenda
- Project Description
- Project Purpose
- Overview of JAI API Capabilities
- Installing JAI
- Programming Techniques
- Programming Model and Application Development
Steps - Example Image Processing Code Fragments
- Conclusions / Recommendations
- References
3Project Description
- The purpose of this project is to
- Discover the image processing (IP) capabilities
of Sun Microsystems JAI API - Learn the programming techniques necessary to
write JAI based applications - Report on how some other projects have leveraged
JAI (see project paper) - Astronomy
- Medical Imaging
- Database
- Transportation
- Planetary Exploration (viewing surface images of
Mars, Venus, moons of Jupiter, etc)
4JAI API Capabilities
- JAI is an API package that greatly simplifies
developing applications requiring the use of IP
algorithms - Provides over 80 pre-canned algorithms to save
developing from scratch - Provides a high level API for using these
algorithms - Extends existing Java 2D imaging capabilities
- Consequently integrates well with Java 2D (AWT)
and Swing APIs - Using organizations can integrate custom
algorithms - Highly portable runs on any hardware and O/S
Java does - Algorithms supported include
- Vector math routines applied to the same pixels
from one or more images i.e. add, subtract, or,
xor, log, extrema (min/max) and creating a
histogram - Image transformation routines i.e. convolving,
edge detection, and filtering (low / high pass
filters) - Geometric transforms including rotation, scaling,
translation and warping - Frequency operator encoding / decoding (codecs)
i.e. DCT/IDCT and DFT/IDFT
5JAI API Capabilities cont
- Additional Supported Capabilities
- Overlaying one image on top of another
- Creating the composite of two images using
Transparency - Tiling of images, so only those visible portions
need to be processed - Creating client/server imaging applications
- Easy creation of custom color lookup tables
(CLUTs) and running an image through a CLUT - Ability to apply different color systems to an
image and convert between them i.e. CIE/CMYK/RGB
6Installation
- Download and install the Java Development Toolkit
(JDK) or Java Run-Time Environment (JRE) if only
running applications - Download and install JAI API from Suns Java
website (see references) - Setup run path to find java and classpath to
find 3 JAI jar files, plus maximum heap memory
size option (-Xmx), but only if needed - Optionally download JAI demonstration tutor
program (see references) - Example setting paths and running
- Promptgtpath.\jre1.6.0_03\bin
- Promptgtjava -Xmx32m classpath ../classesjai_cor
e.jarjai_codec.jarmlibwrapper_jai.jar Tutor - Run from IDE or put java command as above into
.bat file or run directly from command line
7Programming Techniques
- Programming model
- Creates a pipeline of IP objects
- Deferred execution causes pipeline to execute
only when final result is requested
Programming Steps Fetch images For each Algo. to
execute -Build parameter list -Invoke Static JAI
create Operation -Do something with results
i.e. pipe to next operation, display images, or
save them
8Programming Techniques contdExample IP Code
Fragments
- Loading an image file from disk (correct codec
automatically used) - PlanarImage myImage JAI.create(fileload,
C/images/galaxyPicture.jpeg) - Or alternatively, to load an image from the
internet - PlanarImage myImage JAI.create("url",
- new URL("http//viva.uccs.edu/wchampli/cs525/im
ages/wchampli.png")) - Rotating an image (where angle is a float
initially set to 0 degrees) - public void actionPerformed(ActionEvent event)
// method called if button pressed - angle 45 // increase rotation angle by 45
degrees - ParameterBlock pb new ParameterBlock() //
create parm list - pb.addSource(myImage) // add image to
parameter list - pb.add(width / 2.0F) // x origin parameter
is one-half image width - pb.add(height / 2.0F) // y origin parameter
is one-half image height - pb.add((float) Math.toRadians((double)
angle)) // angle parameter - pb.add(new InterpolationNearest())// how to
fill in angles parameters - image JAI.create("Rotate", pb, null) //
execute the operation and get an image - canvas.set(image)// display result image
(notecould pipe into another operation)
9Conclusions/Recommendations
- Conclusions
- JAI makes it easy to develop IP applications and
it saves substantial programming effort over
re-coding algorithms - JAI is more portable typical C libraries targeted
for specific platforms - To date, JAI has been a well kept secret as
information is scattered amongst various sources
on the internet and it is not yet in widespread
use - Wikipedia entry just appeared in mid April
- JAI Tutorial not previously build-able due to
missing files (until the last few weeks) - Suns JAI project team now appears to be actively
working demos, fixing bugs, etc. so JAI use
should now become more widespread - Recommendations
- Performance Improvement Suggestions
- Change underlying data storage to use Java I/O
buffer classes to save copying between buffer
storage types - Modify IP algorithm code to create multiple
threads for processing large images to leverage
multi-cores - Create an IP algo chaining editor tool to build
algo pipelines and execute them (considering as a
possible masters project)
10References
- Project Website
- Project Wiki http//cs525javaimaging.pbwiki.com/
- Resources
- Sun Microsystems. Programming in Java Advanced
Imaging, Release 1.0.1, Palo Alto. CA, November
1999. http//java.sun.com/products/java-media/jai/
docs/ - R. Santos. Java Advanced Imaging API A
Tutorial. RITA Vol. XI Number 1, 2004,
(http//www.inf.ufrgs.br/revista/docs/rita11/rita
_v11_n1_p93a124.pdf) - JAI API doc page http//java.sun.com/products/jav
a-media/jai/forDevelopers/jai-apidocs/ - JAI API download page https//jai.dev.java.net/bi
nary-builds.htmlStable_builds_1.1.4 - JAI Tutorial http//java.sun.com/developer/relea
ses/jai/jaidemo - Developer Forum http//forum.java.sun.com/forum.j
spa?forumID540start0 - Suns Java JAI project https//jai.dev.java.net/
- Sample Using Projects
- JAI Success Stories http//java.sun.com/products/
java-media/jai/success/ - Univ. Washington Intelligent Transportation
System http//java.sun.com/products/java-media/ja
i/success/uw-its.html - LMCO Web based Electronic Light Table (WebELT)
http//java.sun.com/products/java-media/jai/succes
s/lmco.html - Note JAI Logo Icon taken from 6 above - JAI
Tutorial images directory warping code on
slide 14 taken from 6 above - JAI Tutorial
JAIWarpDemo.java source code
11 12Rotation Example
See code on slide 8
13Gamma Scaling Example
Gamma Scaling ramps up dimmer pixel values int
value slider.getValue() double gamma value
/ 100.0 double x // gamma is 0.0-1.0
for (int i 0 i lt 256 i) x i / 256.0
// values are 0.0-1.0 x 255.0 Math.pow(x,
gamma) tableData0i (byte)x
tableData1i (byte)x tableData2i
(byte)x ParameterBlock pb
new ParameterBlock() pb.addSource(image)
pb.add(new LookupTableJAI(tableData)) target
JAI.create("lookup", pb, null)
display.set(target)
14Warping Example
Warping translates image pts thru a
polynomial With coefficients set by control pt
locations float srcCoords new
float200 float dstCoords new
float200 warp WarpPolynomial.createWarp(srcCo
ords, 0, dstCoords, 0,2numPoints,1.0F/width,
1.0F/height, (float)width, (float)height,degree)
float tcoeffs warp.getCoeffs() int length
tcoeffs0.length coeffs new float2
length for (int i 0 i lt length i)
coeffsi tcoeffs0i coeffsilength
tcoeffs1i ParameterBlock pb new
ParameterBlock() pb.addSource(srcImage) pb.add(w
arp) pb.add(new InterpolationNearest()) dstImage
JAI.create("warp", pb)