/Users/lyon/j4p/src/j2d/filters/SharpenFilter.java

1    // SharpenFilter.java 
2    // SharpenFilter is an Java2DImageFilter that sharpens the edges 
3    // in a BufferedImage. 
4    package j2d.filters; 
5     
6    // Java core packages 
7     
8    import ip.transforms.BufferedImageProcessor; 
9     
10   import java.awt.image.BufferedImage; 
11   import java.awt.image.BufferedImageOp; 
12   import java.awt.image.ConvolveOp; 
13   import java.awt.image.Kernel; 
14    
15   public class SharpenFilter implements BufferedImageProcessor { 
16    
17       // apply edge-sharpening filter to BufferedImage 
18       public BufferedImage process(BufferedImage image) { 
19           // array used to detect edges in image 
20           float[] sharpenMatrix = { 
21               0.0f, -1.0f, 0.0f, 
22               -1.0f, 5.0f, -1.0f, 
23               0.0f, -1.0f, 0.0f}; 
24    
25           // create filter to sharpen edges 
26           BufferedImageOp sharpenFilter = 
27                   new ConvolveOp(new Kernel(3, 3, sharpenMatrix), 
28                           ConvolveOp.EDGE_NO_OP, null); 
29    
30           // apply sharpenFilter to displayImage 
31           return sharpenFilter.filter(image, null); 
32    
33       } // end method processImage 
34   } 
35    
36