provided by: 
Originally published at Internet.comJava Programming Notes # 460 * Preface * General * Viewing tip * Figures * Listings * Supplementary material * General background information * Constructing images * The framework program named ImgMod05 * ConvolveOp Examples * Preview * Discussion and sample code * Run the program * Summary * What's next? * Complete program listing * Copyright * Resources * About the author
Preface
General
In an earlier lesson titled A Framework for Experimenting with Java 2D Image-Processing Filters (see Resources), 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 2DAPI: * LookupOp * AffineTransformOp * BandCombineOp * ConvolveOp * RescaleOp * ColorConvertOp
In several of the previous lessons listed in the Resources section, I taught you how to use the LookupOp, the AffineTransformOp, and the BandCombineOp image-filtering classes.
In this lesson, I will teach you how to use the ConvolveOp image-filtering class to perform a variety of filtering operations on images.
I will teach you how to use the remaining classes from the above list in future lessons.
Viewing tip
I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures and listings while you are reading about them.
Figures
* Figure 1. Illustration of an edge treatment option. * Figure 2. Illustration of another edge treatment option. * Figure 3. Application of a flat 4x4 smoothing filter. * Figure 4. Application of an embossing filter using ConvolveOp. * Figure 5. Screen shot of the user input GUI. * Figure 6. Screen shot of typical program output.
Listings
* Listing 1. Beginning of the class definition. * Listing 2. The 9x9 convolution filter matrix. * Listing 3. Instantiation of Label object for display of data entry errors. * Listing 4. The primary constructor. * Listing 5. Beginning of the method named constructMainPanel. * Listing 6. Creation of the panel for radio buttons and text fields. * Listing 7.. Creation and population of a sub-panel for the radio buttons. * Listing 8. Creation of a sub-panel that contains the text fields. * Listing 9. Population and initialization of the array of TextField objects. * Listing 10. Complete the construction of the user input GUI. * Listing 11. Beginning of the processMainPanel method. * Listing 12. Conversion of the 2D convolution filter into a 1D array. * Listing 13. Correct for all filter values equal to 0.0f. * Listing 14. Setting the edge treatment parameters. * Listing 15. Creation of the ConvolveOp filter. * Listing 16. Apply the ConvolveOp filter and return the filtered image. * Listing 17. The required processImg method. * Listing 18. Complete listing for the class named ImgMod42.
Supplementary material
I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find a consolidated index at www.DickBaldwin.com.
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 titled Processing Image Pixels using Java, Getting Started (see Resources). Therefore, I won'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 titled A Framework for Experimenting with Java 2D Image-Processing Filters (see Resources).
However, if you don't have the time to do that, you should take a look at the earlier lesson titled Using the Java 2D LookupOp Filter Class to Process Images (see Resources), in which I summarized the behavior of the framework program named ImgMod05.
ConvolveOp Examples
In my opinion, the ConvolveOp class is the weakest of the image-filtering classes in the Java 2D API. I will explain my reasons for this opinion later in the section titled Assessment. First, however, I will show you some examples of image convolution using the capabilities of the ConvolveOp class.
Edge treatment
When performing image convolution, you must always decide how you are going to treat the edges of the image. The ConvolveOp class provides the following choices: * Copy edge pixels in unmodified form * Zero fill the edge pixels Emphasizing edge treatment
The processed portion of the images in Figures 1 and 2 was
Author: Richard G. Baldwin
Read article at Internet.com site