1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Drawing;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceDFT9 {Ten classFFT One { A intRow; - intCol; - Double[,] FM; the Double[,] FN; - Double[,] X; - Double[,] Original; - PublicFFT (String name) + { -Bitmap Bitmap =NewBitmap (name); + This. Col =bitmap. Width; A This. Row =bitmap. Height; atOriginal=New Double[Row,col]; -fm=New Double[Row,row]; -fn=New Double[Col,col]; -x=New Double[Row,col]; - for(inti =0; i < row; i++) - { in for(intj =0; J < Col; J + +) - { toOriginal[i, j] = (bitmap. GetPixel (j,i). R + bitmap. GetPixel (j,i). G + bitmap. GetPixel (j,i). B)/3; + } - } the initfmn (); * $ }Panax Notoginseng Public Double[,] Getfft () - { theX =martiply (martiply (FM, Original), T (FN)); + returnX; A } the + Public Double[,] Getifft () - { $ returnmartiply (martiply (T (FM), X), FN); $ } - Private Double[,] TDouble[,] a) - { the intAwidth = A.getlength (0); - intAheight = A.getlength (1);Wuyi Double[,] reutrnt =New Double[Aheight, awidth]; the for(inti =0; i < awidth; i++) - { Wu for(intj =0; J < Aheight; J + +) - { AboutReutrnt[j, I] =A[i, j]; $ } - } - returnreutrnt; - } A Private Double[,] martiply (Double[,]a,Double[,]b) + { the intAwidth = A.getlength (0); - intAheight = A.getlength (1); $ intBheight = B.getlength (1); the Double[,] Returnmaxtrix =New Double[Awidth, bheight]; the for(inti =0; i < awidth; i++) the { the for(intj =0; J < Bheight; J + +) - { in for(intK =0; K < Aheight; k++) the { theReturnmaxtrix[i, j] + = A[i, K] *B[k, j]; About } the } the } the returnReturnmaxtrix; + } - Private voidinitfmn () the {Bayi DoubleFirstm =1/math.sqrt (row); the DoubleFIRSTN =1/math.sqrt (col); the for(inti =0; i < row; i++) - { - for(intj =0; J < Row; J + +) the { the if(i = =0) the { theFm[i, J] =firstm; - } the Else the { theFm[i, J] = Math.sqrt (2.0/row) * Math.Cos (i * j * Math.PI/row);94 } the } the } the for(inti =0; I < col; i++)98 { About for(intj =0; J < Col; J + +) - {101 if(i = =0)102 {103Fn[i, J] =firstn;104 } the Else106 {107Fn[i, J] = Math.sqrt (2.0/col) * Math.Cos (i * j * Math.PI/col);108 }109 } the }111 } the }113}
Discrete cosine transform