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

1    package j2d.edge; 
2     
3    import gui.run.RunButton; 
4    import gui.run.RunSlider; 
5    import j2d.*; 
6    import j2d.animation.AnimationDialog; 
7     
8    import javax.swing.*; 
9    import java.awt.*; 
10    
11    
12   public class MehrotraAndZhangPanel extends JPanel { 
13    
14    
15       private int kernelWidth = 15; 
16       private double h = 2.0; 
17    
18       ImageProcessListener ipl = null; 
19    
20       /**Construct the frame*/ 
21       public MehrotraAndZhangPanel(ImageProcessListener _ipl) { 
22           ipl = _ipl; 
23           initGuiElements(); 
24    
25       } 
26    
27       /**Component initialization*/ 
28       private void initGuiElements() { 
29           setLayout(new FlowLayout()); 
30    
31           add(new RunButton("apply") { 
32               public void run() { 
33                   updateImage(); 
34               } 
35           }); 
36           add(new RunButton("Reset") { 
37               public void run() { 
38                   ipl.update(null); 
39               } 
40           }); 
41           add(new JLabel("kernel width")); 
42           add(new RunSlider(4, 19, 15) { 
43               public void run() { 
44                   kernelWidth = getValue(); 
45                   updateImage(); 
46               } 
47           }); 
48           add(new RunButton("comparison") { 
49               public void run() { 
50                   ImageProcessorFactory ipf = 
51                           new MehrotraAndZhangProcessor( 
52                                   kernelWidth, 
53                                   h); 
54                   ComparisonUtils.showComparisonFrame( 
55                           getComparisonPanel(ipf)); 
56               } 
57           }); 
58           add(new RunButton("save gifs") { 
59               public void run() { 
60    
61                   saveGifs(); 
62               } 
63           }); 
64       } 
65    
66       private void saveGifs() { 
67           ImageProcessorFactory ipf = 
68                   new AnimationProcessor(); 
69    
70           ImageBeanInterface origImagePanel = 
71                   (ImageBeanInterface) ipl; 
72           new AnimationDialog(origImagePanel.getImage(), 
73                   ipf); 
74       } 
75    
76       public JPanel getComparisonPanel(ImageProcessorFactory ipf) { 
77    
78           ImageBeanInterface origImagePanel = 
79                   (ImageBeanInterface) ipl; 
80           Image sourceImage = origImagePanel.getImage(); 
81           return ComparisonUtils.getComparisonPanel(sourceImage, ipf); 
82    
83       } 
84    
85       public void updateImage() { 
86           try { 
87               ipl.update(new MehrotraAndZhangProcessor( 
88                       kernelWidth, 
89                       h 
90               )); 
91           } catch (Exception e) { 
92               System.out.println("ER!:kernelWidth=" + kernelWidth); 
93           } 
94       } 
95    
96       private class AnimationProcessor 
97               extends MehrotraAndZhangProcessor { 
98           public AnimationProcessor() { 
99               super(kernelWidth, h); 
100          } 
101   
102          public ImageProcessorInterface getProcessor(int i) { 
103              return 
104                      new MehrotraAndZhangProcessor( 
105                              kernelWidth, 
106                              Math.log(i / (float) kernelWidth)); 
107          } 
108      } 
109   
110   
111  } 
112