/Users/lyon/j4p/src/ip/transforms/FFTRadix2.java

1    package ip.transforms; 
2     
3    import ip.gui.frames.FFTFrame; 
4    import ip.vs.ColorUtils; 
5    import ip.vs.ImageUtils; 
6    import math.transforms.FFT; 
7     
8    public class FFTRadix2 { 
9     
10       FFTFrame parent; 
11    
12       private ColorUtils CU = new ColorUtils(); 
13       private ImageUtils iUtil = new ImageUtils(); 
14       private FFT imgFFT = new FFT(); 
15    
16       private short[] imageData_R; 
17       private short[] imageData_G; 
18       private short[] imageData_B; 
19    
20    
21       public FFTRadix2(FFTFrame _parent) { 
22    
23           parent = _parent; 
24           initData(); 
25       } 
26    
27       private void initData() { 
28           imgFFT.DisplayLogPSD = true; 
29           int w = parent.getImageWidth(); 
30           int h = parent.getImageHeight(); 
31           // separated R,G,B values 
32           //System.out.println("getting the 1-D arrays"); 
33           get1DArraysFromParent(); 
34           //System.out.println("init complete"); 
35       } 
36    
37       public void get1DArraysFromParent() { 
38           if (parent == null) 
39               System.out.println( 
40                       "ER:get1DArraysFromParent, parent==null"); 
41           if (parent.getImageWidth() != parent.getImageHeight()) 
42               System.out.println("ComplexRgb:transforms.fft Non-square image detected"); 
43           int N = parent.getImageWidth() * parent.getImageHeight(); 
44           imageData_R = new short[N]; 
45           imageData_G = new short[N]; 
46           imageData_B = new short[N]; 
47    
48           for (int x = 0; x < parent.getImageWidth(); x++) 
49               for (int y = 0; y < parent.getImageHeight(); y++) { 
50                   imageData_R[x + y * parent.getImageWidth()] = parent.shortImageBean.getR()[x][y]; 
51                   imageData_G[x + y * parent.getImageWidth()] = parent.shortImageBean.getG()[x][y]; 
52                   imageData_B[x + y * parent.getImageWidth()] = parent.shortImageBean.getB()[x][y]; 
53               } 
54       } 
55    
56       public FFT fft = new FFT(); 
57    
58       public FFT getVsFft() { 
59           return fft; 
60       } 
61    
62       public int[] fft() { 
63           fft.DisplayLogPSD = true; 
64           if (parent.getImageWidth() != parent.getImageHeight()) 
65               System.out.println("ComplexRgb:transforms.fft ER! Non-square image"); 
66           return fft.forward2dFFT( 
67                   imageData_R, 
68                   imageData_G, 
69                   imageData_B, 
70                   parent.getImageWidth(), 
71                   parent.getImageHeight()); 
72       } 
73    
74       public int[] getPhaseImage() { 
75           fft.DisplayLogPSD = true; 
76           if (parent.getImageWidth() != parent.getImageHeight()) 
77               System.out.println("ComplexRgb:transforms.fft ER! Non-square image"); 
78           fft.forward2dFFT( 
79                   imageData_R, 
80                   imageData_G, 
81                   imageData_B, 
82                   parent.getImageWidth(), 
83                   parent.getImageHeight()); 
84           return fft.getPhaseImage(); 
85       } 
86    
87       public void complexMult(FFTRadix2 other) { 
88           fft.complexMult(other.getVsFft()); 
89       } 
90    
91       public int[] getPsd() { 
92           return fft.getPsd(); 
93       } 
94    
95    
96       public int[] ifft() { 
97           return fft.reverse2dFFT(); 
98       } 
99    
100   
101  } 
102   
103   
104   
105   
106   
107   
108   
109