advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Using Rasters for Image Processing, Part 1 :

Using Rasters for Image Processing, Part 1

by Anghel Leonard

Many modern image technologies are based on raster concept— things like televisions, photo cameras, or printers. They provide superior image control, allowing you to process an entire image or only a piece of it, and full control over pixel's colors. You're free to develop new image filters, or allow images to mix. Basically, having a raster is like having a "playground" because you are free to try whatever you want to do with the image.

This article discusses rasters from the Java perspective. You'll find out what the components of a raster are in Java and how to exploit them in an application. You'll learn how to store, extract, and manipulate image samples, and then learn how how to extract a color band and how to create a zoom effect.

Creating a Raster

A raster is a rectangular area of pixels from an image or a piece of an image. Java rasters are representated by the java.awt.image.Raster class and its subclass. You create a raster using these classes or obtain one from an Image object, BufferedImage object or from an array of pixels. To store information about the pixels of a raster you use data buffers that represent instances of the direct DataBuffers subclasses. The SampleModel class and its subclasses manage the rules for extracting and storing pixels into the data buffers. These classes contain enough methods for providing to the programmer a large flexibility in working with rasters.


Figure 1. Creating a Raster: A raster contains a DataBuffer and a SampleModel.

The DataBuffer and SampleModel Classes

To understand how theseDataBuffer and SampleModel work together to create a raster, it is important to be familiar with a few concepts. Suppose you have an image in the default color model (the AlphaRedGreenBlue color model). A pixel's components are categorized as "samples". Samples are defined as "bands." In this example, the pixel has four samples, represented by the four color components. This means that the image has four bands: red, green, blue, and transparency. The red band contains all the red samples of the image, the green one all the green samples, etc.

Remember that this is just an example. Not all images have four bands and not all images have these same bands. For example, a multi-spectral image has many bands, whereas an image represented by the elevation model will have only one.


Figure 2. An Image Band: A possible red band fragment.

The abstract class SampleModel contains methods for extracting a pixel's samples, for storing them in data buffers, and for extracting them from data buffers. To store the samples in DataBuffers, you use arrays of primitive data types. In fact, a DataBuffer object encapsulates one or more arrays of primitive data types. Generally, each array in the data buffer is in fact, a block of data that has a specified dimension. The first block is known as block 0, the second is block 1, etc. When no block is specified block 0 is used, by default.

To create a DataBuffer, create an instance of one of the following subclasses:

  • java.awt.image.DataBufferByte: the data is represented in the unsigned byte primitive type.
  • java.awt.image.DataBufferShort: the data is represented in the short primitive type.
  • java.awt.image.DataBufferUShort: the data is represented in the unsigned short primitive type.
  • java.awt.image.DataBufferInt: the data is represented in the int primitive type.
  • java.awt.image.DataBufferFloat: the data is represented in the float primitive type.
  • java.awt.image.DataBufferDouble: the data is represented in the double primitive type.
There are two major ways to store samples in a DataBuffer:

The first way to store samples uses the ComponentSampleModel class (which is a direct subclass of SampleModel) and the two ComponentSampleModel's subclasses: PixelInterleavedSampleModel and BandedSampleModel. More bands can be in the same block or in separated blocks.

If you want to store one sample per DataBuffer element, and the samples of all bands to be in only one block, use the PixelInterleavedSampleModel class. If you want to store the samples for every band into a separate block, use the BandedSampleModel class. These two classes work with all the above listed DataBufferXXX classes.


Figure 3. Storing Samples in a DataBuffer: This image shows the different models for storing samples in a DataBuffer.

The second way to store samples uses the SinglePixelPackedSampleModel and MultiPixelPackedSampleModel classes (both are subclasses of SampleModel). To store all the samples of one pixel per one DataBuffer element, use the SinglePixelPackedSampleModel class. In this case, the samples are stored into the first block. To store samples from different pixels per one DataBuffer element, use the MultiPixelPackedSampleModel class. These two classes work only with the DataBufferByte (8 bits-1 byte), DataBufferUShort (16 bits-2 bytes), and DataBufferInt (32 bits-4 bytes) classes.


Figure 4. Using SinglePixelPackedSampleModel: Store all the samples of one pixel per one DataBuffer element using SinglePixelPackedSampleModel.

Remember that DataBuffer's blocks are counting from 0 to n-1. The bands stored into a DataBuffer are also counting from 0 to n-1.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 DevX Skillbuilding from IBM developerWorks
 Avaya DevConnect Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 48
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Apple Details iPhone/Mac Developer Event
RIM Ups Ante With Mobile Software Push
Novell Readies Silverlight Clone for Linux
Yahoo Pitches The 'Next Generation of Search'
Alfresco's Latest ECM: Prying Open a Sector?
SaaS Tool Offers Custom Database Development
Microsoft’s Automated Agent: Can We Talk?
Borland Finally Sells CodeGear
Red Hat Heads for the JON 2.0
Out with the Old, in with the New at JavaOne

Create Secure Java Applications Productively, Part 1: Use Rational Application Developer and Data Studio
.NET Building Blocks: Custom User Control Fundamentals
Secure Internet File-Sharing with PHP, MySQL, and JavaScript
Getting Started with TBB on Windows
Moving to VoIP: Should You Go It Alone?
Introduction to the WPF Command Framework
7.0, Microsoft's Lucky Version?
Will Hyper-V Make VMware This Decade's Netscape?
Eliminate Fragmentation Frustration with Netbiscuits
Taming Trees: Building Branching Structures

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES