/Users/lyon/j4p/src/j2d/edge/SobelProcessor.java

1    package j2d.edge; 
2     
3    import j2d.ImageUtils; 
4    import ip.transforms.Kernels; 
5    import j2d.ImageProcessorInterface; 
6    import j2d.ImageProcessorFactory; 
7    import j2d.hpp.InvertFilter; 
8     
9    import java.awt.*; 
10    
11    
12   public class SobelProcessor 
13           implements ImageProcessorInterface, 
14           ImageProcessorFactory { 
15    
16       private int a; 
17       private boolean isX = true; 
18    
19    
20       public SobelProcessor(int a, boolean isX) { 
21    
22           this.a = a; 
23           this.isX = isX; 
24       } 
25    
26       public ImageProcessorInterface getProcessor(int a) { 
27           return new SobelProcessor(a, isX); 
28       } 
29    
30       public Image process(Image img) { 
31           return sobel(img); 
32    
33       } 
34    
35       private Image sobel(Image img) { 
36           System.out.println(" a=" + a); 
37           //ThresholdProcessor tp = new ThresholdProcessor(128); 
38           ImageProcessorInterface invert = InvertFilter.getProcessor(); 
39           float f[][] = null; 
40           if (isX) 
41               f = Kernels.getSobelX(a); 
42           else 
43               f = Kernels.getSobelY(a); 
44    
45           return 
46                   invert.process(ImageUtils.convolution(img, f)); 
47       } 
48    
49   } 
50    
51