provided by: 
Originally published at Internet.com
Java Programming Notes # 458 * Preface * General Background Information * Preview * Discussion and Sample Code * Run the Program * Summary * What's Next? * References * Complete Program Listing -----------------------------------
Preface
Part of a series
In an earlier lesson entitled "A Framework for Experimenting with Java 2D Image-Processing Filters" (see References), I taught you how to write a framework program that makes it easy to use the image-filtering classes of the Java 2D API to process the pixels in an image and to display the processed image.
At the close of that lesson, I told you that future lessons would teach you how to use the following image-filtering classes from the Java 2D API: * LookupOp * AffineTransformOp * BandCombineOp * ConvolveOp * RescaleOp * ColorConvertOp
In several previous lessons listed in the References section, I taught you how to use the LookupOp and the AffineTransformOp image-filtering classes.
In this lesson, I will teach you how to use the BandCombineOp image-filtering class to perform a variety of filtering operations on images. I will also teach you how to extract and filter Raster objects from images. (The use of Raster objects is completely new to this lesson.)
I will teach you how to use the remaining classes from the above list in future lessons.
Viewing tip
You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings and figures while you are reading about them.
Supplementary material
I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find those lessons published at Gamelan.com. However, as of the date of this writing, Gamelan doesn't maintain a consolidated index of my Java tutorial lessons, and sometimes they are difficult to locate there. You will find a consolidated index at www.DickBaldwin.com.
I also recommend that you pay particular attention to the lessons listed in the References section of this document.
General Background Information
Constructing images
Before getting into the programming details, it may be useful for you to review the concept of how images are constructed, stored, transported, and rendered in Java (and in most modern computer environments for that matter).
I provided a great deal of information on those topics in the earlier lesson entitled Processing Image Pixels using Java, Getting Started. Therefore, I wwon't repeat that information here. Rather, I will simply refer you back to the earlier lesson.
The framework program named ImgMod05
It will also be useful for you to understand the behavior of the framework program named ImgMod05. Therefore, I strongly recommend that you study the earlier lesson entitled "A Framework for Experimenting with Java 2D Image-Processing Filters" (see References).
However, if you don't have the time to do that, you should take a look at the earlier lesson entitled "Using the Java 2D LookupOp Filter Class to Process Images" (see References), in which I summarized the behavior of the framework program named ImgMod05.
Preview
In this lesson, I will present and explain an image-processing program named ImgMod41 that is compatible with the framework program named ImgMod05.
The program GUI
The program GUI is shown in Figure 1. 
Figure 1
In addition to providing instructions to the user, this GUI allows the user to specify the location and dimensions of a rectangular area within the original image, from which a Raster object will be extracted. The GUI also allows the user to specify the values in a 3x4 image-processing matrix having three rows and four columns that is used to process the raster using the BandCombineOp image-filtering class.
Buffered v.s. Raster objects. I have illustrated the filtering of BufferedImage objects in several previous lessons listed in the References section. I will have more to say about Raster objects later in this lesson. For now, suffice it to say that by converting the BufferedImage object to a Raster object, it is possible to operate on smaller rectangular areas of the image that are extracted from within the body of the entire image. BufferedImage objects versus Raster objects
As I mentioned earlier, the use of Raster objects is completely new to this lesson.
Unlike some of the other image-filtering classes in the Java 2D API that can operate either on BufferedImage objects or on Raster objects, the BandCombineOp filter can operate only on Raster objects.
Image-filtering methodology
For the BandCombineOp class, the red, green, and blue values of each pixel are treated as a column matrix. A 1 is appended onto the end of each column matrix producing a set of four-element column matrices that represents all of the pixels in the input Raster object. (Each pixel is represented by a four-element column matrix.)
Each pixel in the output Raster is produced by multiplying a user-specified 3x4 image-processing matrix by the 4x1 column matrix that represents the corresponding pixel
Author: Richard G. Baldwin
Read article at Internet.com site