/Users/lyon/j4p/src/j2d/edge/gabor/GaborPanel.java
|
1 package j2d.edge.gabor;
2
3
4 import futils.Futil;
5
6 import java.awt.*;
7 import java.io.File;
8 import java.util.Observable;
9 import java.util.Observer;
10
11 public class GaborPanel extends Panel
12 implements Observer {
13
14 private GaborCanvas spaceCanvas = new GaborCanvas();
15 //private GaborCanvas fourierCanvas = new GaborCanvas();
16 private FilterCanvas originalImage = new FilterCanvas();
17
18
19 // 24 angles at 15 degee increments
20 private GaborCanvas spaceArray[] = new GaborCanvas[18];
21
22 // This is the delta theta for the gabor subband.
23 private double angleIncrement = 180.0 / spaceArray.length;
24
25 private int kernelSize = 7;//used to be 7
26 private GaborParams gaborParams = new GaborParams();
27
28 public GaborParams getParams() {
29 return gaborParams;
30 }
31
32 public GaborPanel(Image img) {
33 originalImage.setImage(img);
34 }
35
36 public GaborPanel() {
37
38 }
39
40 public FilterCanvas[] getFilters() {
41 return filters;
42 }
43
44 public static Frame getGaborFrame() {
45 Frame f = new Frame();
46 GaborPanel gaborPanel = new GaborPanel();
47 f.setLayout(new BorderLayout());
48 f.add(gaborPanel, BorderLayout.CENTER);
49 gaborPanel.init();
50 f.show();
51 f.setSize(200, 200);
52 return f;
53 }
54
55 public Image getGaborImage() {
56 return spaceCanvas.getImage();
57 }
58
59 public static void main(String[] args) {
60 getGaborFrame();
61 }
62
63 public void save() {
64 File fn = Futil.getWriteFile("select fn.gz");
65
66 for (int i = 0; i < spaceArray.length; i++) {
67 GaborCanvas gc = spaceArray[i];
68 String f = fn.getAbsolutePath() + i;
69 gc.saveAsJava(new File(f));
70 }
71 }
72
73
74 public void init() {
75 new GaborView(gaborParams);
76 setLayout(new GridLayout(6, 0));
77
78 filters = new FilterCanvas[spaceArray.length];
79 for (int i = 0; i < spaceArray.length; i++) {
80 spaceArray[i] = new GaborCanvas();
81 add(spaceArray[i]);
82
83 }
84
85 gaborParams.addObserver(this);
86
87 for (int i = 0; i < spaceArray.length; i++) {
88 filters[i] = new FilterCanvas();
89 //filters[i].convolution(originalImage.getImage(), spaceArray[i].getKernel());
90 add(filters[i]);
91
92 }
93 update(null, null);
94
95
96 }
97
98 FilterCanvas filters[];
99
100 private Panel create_panel(String string, String string_0_) {
101 Panel panel = new Panel();
102 panel.setLayout(new GridLayout(3, 0));
103 Label label = new Label(string);
104 label.setAlignment(1);
105 panel.add(label);
106
107 return panel;
108 }
109
110
111 public void update(Observable o, Object arg) {
112 spaceCanvas.ComputeImageArrays(kernelSize, gaborParams.getLambda(),
113 gaborParams.getTheta(), gaborParams.getPhi(),
114 gaborParams.getGamma_val(), gaborParams.getSigma());
115 //fourierCanvas.ComputeImageArrays(kernelSize, gaborParams.getLambda(),
116 // gaborParams.getTheta(), gaborParams.getPhi_val(),
117 // gaborParams.getGamma_val(), gaborParams.getSigma());
118
119 spaceCanvas.drawImage("space");
120 //fourierCanvas.drawImage("fourier");
121
122 for (int i = 0; i < spaceArray.length; i++) {
123 GaborCanvas gc = spaceArray[i];
124 gc.ComputeImageArrays(kernelSize, gaborParams.getLambda(),
125 i * angleIncrement, gaborParams.getPhi(),
126 gaborParams.getGamma_val(), gaborParams.getSigma());
127 gc.drawImage("space");
128 filters[i].convolution(originalImage.getImage(), spaceArray[i].getKernel());
129 }
130 }
131
132 }
133