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.

 Avaya DevConnect Center
 Service Component Architecture/Service Data Objects Solution Center
 Intel Go Parallel Portal
 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 53
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%.

Windows 7: It's Not Just a Codename Anymore
Microsoft Shines Silverlight on Eclipse
OpenOffice Hits 3.0: Can It Challenge Microsoft?
Get Ready for Microsoft's 'Oslo' Modeling Tool
Latest Linux Hits Networking Flaws
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next
Is .NET on Linux Finally Ready?
Red Hat Takes on HPC Market, Microsoft

Intel Sees Fewer Power Cords in Your Future
F# 101
Use Explicit Conversion Functions to Avert Reckless Implicit Conversions
Polyglot Programming: Building Solutions by Composing Languages
Automated testing for .NET by Ben Hall
"Supply Chain" SOA with SKOS
Service Component Architecture in Real Life
C++Ox: The Dawning of a New Standard
Getting Started with Virtualization
Master Complex Builds with MSBuild

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: BitLocker Encryption on Windows Server 2008
Go Parallel Article: Intel Thread Checker, Meet 20 Million LOC
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES