Page 201 - The Definitive Guide to Building Java Robots
P. 201
Preston_5564C06.fm Page 182 Friday, September 23, 2005 5:13 AM
182 CHAPTER 6 ■ VISION
pixel, and multiply that by 1/9. Continue this until all surrounding pixels are calculated. After-
ward, add the results. You get something like
255 * (9/9), 255 * 4/9, 255 * 4/9 = 255, 113,113
which is slightly pink.
The third type is combination processing. This is the process of performing multiple pixel
and/or convolution operations on an image at once to complete the process. For example,
sometimes you might want to perform operation A before operation B, but lighting conditions
might make you want to perform another operation C. Now, depending on the number of filters
you have creating methods for all these combinations—and combinations of combinations—
it can get downright confusing.
What I have done to simplify this is to create a FilterParameter object that will contain the
following information:
• A BufferedImage to process
• The name of the filter
• An ArrayList of parameters
By creating a generic object, I can facilitate adding, removing, and combining any number of
filters for a specific operation without having to code separate methods for them (see Example 6-9).
Example 6-9. FilterParamters.java
package com.scottpreston.javarobot.chapter6;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class FilterParameters {
// name to identify
private String name;
// image to work with
private BufferedImage image;
// parameters
private ArrayList parameters = new ArrayList();
// constructor
public FilterParameters(String n) {
name = n;
}
public BufferedImage getImage() {
return image;
}