/Users/lyon/j4p/src/ip/apurva/FourierFrame.java

1    package ip.apurva; 
2     
3    import ip.color.Ccir601_2cbcr; 
4    import ip.gui.frames.ColorFrame; 
5    import math.MathUtils; 
6     
7    import java.awt.Menu; 
8    import java.awt.MenuBar; 
9    import java.awt.MenuItem; 
10   import java.awt.event.ActionEvent; 
11   import java.awt.event.ActionListener; 
12    
13   public class FourierFrame extends ZipFrame 
14           implements ActionListener { 
15    
16       MenuBar mb = getMenuBar(); 
17    
18       Menu Fou_menu = new Menu("Fourier Synthesis"); 
19       MenuItem FouMountain = addMenuItem(Fou_menu, 
20                                          "Mountain scene"); 
21   //MenuItem FouOcean = addMenuItem(Fou_menu,"Ocean"); 
22    
23       public void actionPerformed(ActionEvent e) { 
24           if (match(e, FouMountain)) { 
25               fou_mi(); 
26               return; 
27           } 
28           super.actionPerformed(e); 
29       } 
30    
31       public void fou_mi() { 
32           initframe(); 
33       } 
34    
35       public void initframe() { 
36           //randomise image 
37           imageRandom(); 
38           //gui.run fast fourier transform on it 
39           fftR2(); 
40           //mutiply 1/f filter 
41           Ccir601_2cbcr cc = new Ccir601_2cbcr( 
42                   new ColorFrame("colorframe")); 
43           cc.fromRgb(); 
44           cc.oneOnF(); 
45           cc.toRgb(); 
46           //gui.run inverse fast fourier transform 
47           ifftR2(); 
48           //gui.run rd image 
49           threeDImage(); 
50           short2Image(); 
51       } 
52    
53       public void imageRandom() { 
54           for (int i = 0; i < 
55                           shortImageBean.getR() 
56                   .length; i++) { 
57               for (int j = 0; j < 
58                               shortImageBean.getR()[0].length; j++) { 
59                   int s = MathUtils.rand(0, 255); 
60                   shortImageBean.getR()[i][j] += s; 
61                   shortImageBean.getB()[i][j] += s; 
62                   shortImageBean.getG()[i][j] += s; 
63               } 
64           } 
65    
66       } 
67    
68       public void threeDImage() { 
69    
70           graphics.ddd.MainFrame.image3D( 
71                   getImage(), 
72                   shortImageBean.getR()); 
73           return; 
74       } 
75    
76       public void multOneonF() { 
77           int xc = getImageWidth() / 2; 
78           int yc = getImageHeight() / 2; 
79           for (int x = 0; x < getImageWidth(); x++) { 
80               for (int y = 0; y < getImageHeight(); y++) { 
81                   double f = oneOnF(x, y, xc, yc); 
82                   shortImageBean.getR()[x][y] = 
83                   (short) (shortImageBean.getR()[x][y] * 
84                            f); 
85                   shortImageBean.getG()[x][y] = 
86                   (short) (shortImageBean.getG()[x][y] * 
87                            f); 
88                   shortImageBean.getB()[x][y] = 
89                   (short) (shortImageBean.getB()[x][y] * 
90                            f); 
91               } 
92           } 
93           short2Image(); 
94       } 
95    
96       public static double oneOnF(int x, 
97                                   int y, 
98                                   double xc, 
99                                   double yc) { 
100          double dx = x - xc; 
101          double dy = y - yc; 
102          double dx2 = dx * dx; 
103          double dy2 = dy * dy; 
104          double eps = 1; 
105          return 1 / Math.sqrt(dx2 + dy2 + eps); 
106      } 
107   
108      FourierFrame() { 
109          mb.add(Fou_menu); 
110          setMenuBar(mb); 
111          repaint(); 
112      } 
113   
114      public static void main(String args[]) { 
115          new FourierFrame(); 
116      } 
117   
118  }