• Like
Tk3813 Lecture6
Upcoming SlideShare
Loading in...5
×

Tk3813 Lecture6

  • 1,251 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,251
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
11
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Lecture 5: Images in Java (2) TK3813
  • 2. Contents
    • The Java2D API
    • Java Advanced Imaging
  • 3. The Java2D API
    • The producer-consumer approach is conceptually sound but rather clumsy for straightforward image processing applications.
    • This deficiency has been addressed with the introduction of the Java2D Application Programming Interface (API) into Java. With the release of Java 2, Java2D has become one of the standard APIs provided with the language.
    • The Java2D API consists of a number of classes, distributed amongst the old packages java.awt and java.awt.image and six new packages:
      • java.awt.color.
      • java.awt. font
      • java.awt.geom
      • java.awt.print
      • java.awt.image.renderable
      • com.sun.image.codec.jpeg
  • 4. Java2D API
    • Our discussion of Java 2D API imaging includes the following topics:
      • BufferedImage class - concrete subclass of the abstract Image subclass. It offers far more sophisticated and elaborate features than Image.
      • Raster and WritableRaste.
      • Reading a BufferedImage.
  • 5. BufferedImage
    • With Java 1.2 and the Java2D classes, came the java.awt.image.BufferedImage, which is a subclass of Image. It provides a more open and structured internal design with much greater access to the image data.
    BufferedImage DataBuffer ColorModel Raster SampleModel Composition of a BufferedImage object
  • 6. BufferedImage
    • BufferedImage includes a ColorModel object and a Raster object, which in turn contains instances of SampleModel and Databuffer.
      • A color model refers to how to the data describes the colors as they will appear in the display.
      • A common type of color model is RGB model. Java offers an RGB model where an alpha or transparency factor is included with the RGB values. One can also have grey scale models and index models where a data value holds an index into a palette of a fixed number of colors.
      • The raster refers to the data that specifies the colors of the individual pixels.
      • The Raster instance is actually composed of the raw data in a Databuffer and a SampleModel that details how the raw data values get translated into the color specifications for the model.
  • 7. BufferedImage
      • The number and types of bands in the SampleModel of the Raster must match the number and types required by the ColorModel to represent its color and alpha components.
      • All BufferedImage objects have an upper left corner coordinate of (0, 0).
      • Any Raster used to construct a BufferedImage must therefore have minX=0 and minY=0.
  • 8. BufferedImage
    • The constructor of BufferedImage takes image dimensions and image type as it parameters. There are 13 different standard image type, representing different combination of ColorModel and SampleModel.
    * * Selected types of BufferedImage, * the most useful types for our purposes. 8-bit red, green and blue samples; packed into an int. TYPE_INT_RGB 8-bit blue, green and red samples; each stored in one byte. TYPE_3BYTE_BGR 16-bit sample for each pixel; stored in a short. TYPE_UNSHORT_GRAY 8-bit sample for each pixel; stored in a byte. TYPE_BYTE_GRAY 1-bit sample for each pixel; 8 samples packed into a byte. TYPE_BYTE_BINARY Description Constant
  • 9. BufferedImage
    • The dimension and type of an existing BufferedImage object can be acquired using:
      • getWidth()
      • getHeight()
      • getType()
    • Its colour can be retrieve with getColorModel().
    • Pixel values can be inspected or modify:
      • getRGB()
      • setRGB()
  • 10. Method getRGB() and setRGB() provided by the BufferedImage class int getRGB(int x, int y); int[] getRGB(int x, int y, int w, int h, int[] data, int offset,int scansize); void setRGB(int x, int y, int value); void setRGB(int x, int y, int w, int h, int[] data, int offset,int scansize);
  • 11. Raster and WritableRaster
    • Java2D’s Raster class has methods that manipulate the samples of a pixel directly, without wasteful interpretation imposed by a ColorModel.
      • Read-only class.
      • A subclass of Raster, i.e. WritableRaster can change pixel’s values.
  • 12. Raster and WritableRaster
    • The pixel access method of Raster and WritableRaster have 2 broad classes:
      • Pixel methods:
        • getPixel()
        • setPixel()
      • Sample methods: operate on a particular sample of each pixel in a rectangular block.
        • getSample()
        • setSample()
  • 13. int[] getPixel(int x, int y, int[] data) float[] getPixel(int x, int y, float[] data) double[] getPixel(int x, int y, double[] data) int[] getPixels(int x, int y, mt w, mt h, int[] data) float[] getPixels(int x, int y, int w, int h, float[] data) double[] getPixels(int x, int y, int w, int h, double[] data) int getSample(int x, int y, int band) float getSampleFloat(int x, int y, int band) double getSampleDouble(int x, int y, int band) int[] getSamples(int x, int y, int w, int h, int band, int[] data) float[] getsamples(int x, int y, int w, int h, int band, float[] data) double[] getSamples(int x, int y, int w, int h, int band, double[] data) Table 4.4 Methods provided by the Raster class to inspect pixel values.
  • 14. void setPixel(int x, int y, int[] data) void setPixel(int x, int y, float[] data) void setPixel(int x, int y, double[] data) void setPixels(int x, int y, int w, int h, int[] data) void setPixels(int x, int y, int w, int h, float[] data) void setPixels(int x, int y, int w, int h, double[] data) void setSample(int x, int y, int band, int value) void setSample(int x, int y, int band, float value) void setSample(int x, int y, int band, double value) void setSample(int x, int y, int w, int h, int band, int[] data) void setSample(int x, int y, int w, int h, int band, float[] data) void setSample(int x, int y, int w, int h, int band, double[] data) Table 4.5 Methods provided by WritableRaster to modify pixel values.
  • 15. Raster and WritableRaster
    • Parameter band used by sample-based methos:
      • Always 0 for greyscale images.
      • 0,1 or 2 corresponding to red, green and blue bands
  • 16. Example
    • Suppose that we have a greyscale BufferedImage called image and we wish to divide all its grey levels by two.
    WritableRaster raster = image.getRaster(); int value; for(int y=0;y<image.getHeight();++y) for(int x=0;x<image.getWidth();++x) { value = raster.getSample(x,y,0)/2; raster.setDample(x,y,0,value); }
  • 17. Reading a BufferedImage
    • The package com.sun.image.coded.jpeg contains classes to support the reading of images from, and writing images to, datastreams that have been compressed using JPEG compression.
      • JPEGImageDecoder(reading)
      • JPEGImageEncoder(writing)
    Example: To load an image from file “in.jpg” FileInputStream fileStream = new FileInputStream(“in.jpg”); JPEGImageDecoder input=JPEGCodec.createJPEGDecoder(fileStream); BufferedImage image=input.decodeAsBufferedImage(); Example: Writing the image out to a file “out.jpg” FileOutputStream fileStream = new FileOutputStream(“out.jpg”); JPEGImageEncoder output=JPEGCodec.createJPEGEncoder(fileStream); output.encode(image);
  • 18. More info
    • http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Image.html
    • http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html
  • 19. Java Advanced Imaging (JAI)
    • The JAI, provides tools for &quot;sophisticated, high performance image processing.&quot;
    • First developed in the late 1990s some of the JAI features are now available in J2SE5.0 (e.g. I/O for a wide range of image formats) but it still provides a large and robust set of imaging tools.
    • For example, many high end imaging tasks involve dealing with extremely large images. JAI allows for &quot;tiling&quot; , in which users can grab a section of an image for display and thus save lots of bandwidth.
  • 20. Java Advanced Imaging (JAI)
    • Features include:
      • Delay execution of image processing task until they are needed. This &quot;just-in-time&quot; approach provides for faster response to the user since not time is wasted on unneeded computation.
      • Built-in RMI (Remote Method Invocation) allows for distributing image tasks and client interaction over the network.
      • Extensible framework allows for expansion of capabilities via plug-in modules developed by users and third parties.
  • 21. Applications of JAI
    • JSky is used by astronomers to plan observations for the Gemini Telescope . The JSky home site describes how the program manages catalogs of imagery obtained in many formats and provides imaging tools to analyze individual images as well as to combine and compare multiple images.
    • JAI is used as part of the Scientist's Expert Assistant developed at NASA Goddard Space Flight Center in conjunction with the Space Telescope Science Institute. This is &quot;a system that combines interactive visual and expert system approaches to assist astronomers in planning observations.&quot; See the papers and presentations describing the program.
  • 22. Applications of JAI
    • GeoVirgil is a &quot;planetary data analysis tool works as a map program (or Graphical Information System) for NASA planetary imagery. Developed by Steve McDonald, it &quot;combines imagery, elevation and other data sets into an integrated map view.&quot; Various image processing functions are available. A 3D version is under development.
    • AstroVirgil is another Java program from Steve McDonald that is used to analyze data from the space-based Chandra X-ray telescope .
    • JadeDisplay (http://www.openchannelfoundation.org/projects/JadeDisplay/) is &quot;a high-performance image display component for serious imaging applications using JAI. It works asynchronously, loading/computing image tiles in background threads. This frees up the GUI thread so the user doesn't have to wait for the entire image to load, and scrolling is fast regardless of image size (as long as it is tiled).&quot;
  • 23. Questions ???