static void Main(string[] args) { Func<int, double> func = i => (i > 1 && i < 6) ? 1 : 0; var image = new CImage<double>(8, 8); //написать по крутому пока пишем по ламерски for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { image[i, j] = func(i) * func(j); } } var res1 = FourierTransform.ForwardFFT2D(image.ToComplex()); var res = FourierTransform.BackwardFFT2D(res1); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Console.Write("{0} ", res[i, j]); } Console.WriteLine(); } var c1 = new Complex(-123, 456); var c2 = c1.Sqrt; Console.WriteLine(c2*c2); }
public CImage<double> AppVIT(CImage<double> img, bool addHopt, bool addH0, bool addHk, bool addNoise, double sigma, double X0) { int height = img.GetH; int width = img.GetW; //CImage<double> imgOut = new CImage<double>(height, width); CImage<double> imgOut = new CImage<double>(oSize, oSize); GenerateH0(addH0); GenerateHk(addHk); GenerateHopt(addHopt); GenerateVIT(); CImage<Complex> fImg = FourierTransform.ForwardFFT2D(img.ToComplex()); CImage<Complex> fVIT = VIT.ToComplex(); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { fImg[i, j] = fImg[i, j] * fVIT[i, j]; } } img = FourierTransform.BackwardFFT2D(fImg).ToDouble(); int k = Size / oSize; for (int i = 0; i < oSize; i++) { for (int j = 0; j < oSize; j++) { imgOut[i, j] = img[i * k, j * k]; } } if (addNoise) { Random rnd = new Random(7); for (int i = 0; i < oSize; i++) { for (int j = 0; j < oSize; j++) { double buf = imgOut[i, j] + GenerateNormNoise(rnd, sigma, X0) * Math.Sqrt(imgOut[i, j]); if (buf > 255) imgOut[i, j] = 255; else if (buf < 0) imgOut[i, j] = 0; else imgOut[i, j] = buf; //imgOut[i, j] = buf < 255 ? buf : 255; //imgOut[i, j] = buf > 0 ? buf : 0; } } } //for (int i = 0; i < Size; i++) //{ // for (int j = 0; j < Size; j++) // { // imgOut[i, j] = imgOut[i, j] + 128; // } //} return imgOut; }