Ejemplo n.º 1
0
        public void ShiftNoShiftSameFft()
        {
            // Expectation
            // INVFFT(SHIFTEDFFT(IMG) * SHIFTEDFILTER) == INVFFT(FFT(IMG) * FILTER)

            IImage <double> bunny = ImageFactory.Generate(BunnyPath)
                                    .Crop(0, 0, 512, 512);

            // Shift and NoShift FFT
            var noShiftFft = bunny.Fft(false);
            var shiftFft   = bunny.Fft(true);

            // Shift and NoShift Filter
            var noShiftfilter = Filters.MakeFilter(512, 512, Filters.IdealLowPass(50));
            var shiftFilter   = Filters.MakeFilterWithOffset(512, 512, Filters.IdealLowPass(50));

            // Multiply Filter by FFT
            IImage <Complex> shift   = ImageFactory.GenerateComplex(512, 512);
            IImage <Complex> noShift = ImageFactory.GenerateComplex(512, 512);

            Parallel.For(0, bunny.Length, i =>
            {
                shift[i]   = shiftFilter[i] * shiftFft[i];
                noShift[i] = noShiftfilter[i] * noShiftFft[i];
            });

            // Get Inverse FFT
            var shiftResult   = shift.InverseFft();
            var noShiftResult = noShift.InverseFft();

            Assert.IsTrue(ImagesEqualWithinEpsilon(noShiftResult, shiftResult, (x, y) => Math.Abs(x - y) < 0.05));
        }
Ejemplo n.º 2
0
        public void TestFFT()
        {
            // [512 * 512] image
            IImage <double> bun = ImageFactory
                                  .Generate(ImageTests.BunnyPath)
                                  .Crop(0, 0, 512, 512);

            Assert.IsTrue(bun.Height == 512);
            Assert.IsTrue(bun.Width == 512);

            // Fast Forrier Transform
            IImage <Complex> fft = bun.Fft();

            IImage <double> realPart = fft.RealPart();
            IImage <double> imagPart = fft.ImaginaryPart();

            Assert.IsFalse(ImageEmpty(realPart));
            Assert.IsFalse(ImageEmpty(imagPart));
            Assert.IsTrue(realPart.Width == imagPart.Width);
            Assert.IsTrue(realPart.Height == imagPart.Height);

            // IMAGINARY(COMPLEX) + REAL(COMPLEX) == COMPLEX
            IImage <Complex> fftEq = ImageFactory
                                     .GenerateComplex(512, 512, realPart.Zip(imagPart, (real, img) => new Complex(real, img)));

            Assert.IsTrue(ImagesEqual(fft, fftEq));


            realPart
            .WriteImage(Path.Combine(WorkingDirectory, "FFT RealPart"));

            imagPart
            .WriteImage(Path.Combine(WorkingDirectory, "FFT ImaginaryPart"));

            fft
            .Phase()
            .WriteImage(Path.Combine(WorkingDirectory, "FFT Phase"));

            fft
            .MagnitudePart()
            .WriteImage(Path.Combine(WorkingDirectory, "FFT Magnitude"));

            fft
            .InverseFft()
            .WriteImage(Path.Combine(WorkingDirectory, "FFT Inverse FFT"));
        }
Ejemplo n.º 3
0
 public void TestHarmonicSignal()
 {
     ImageFactory.GenerateComplex(128, 128)
     .MapLocation(Filters.HarmonicSignal((3.0 / 128.0), (2.0 / 128.0)))
     .WriteImage(WorkingDirectory, "Complex Harmonic");
 }
Ejemplo n.º 4
0
 public void TestClearComplex()
 {
     ImageFactory.GenerateComplex(50, 50).Clear();
 }
Ejemplo n.º 5
0
 public void TestIsSynchronizedComplex()
 {
     Assert.IsFalse(ImageFactory.GenerateComplex(50, 50).IsSynchronized);
 }
Ejemplo n.º 6
0
 public void TestIsReadOnlyComplex()
 {
     Assert.IsTrue(ImageFactory.GenerateComplex(50, 50).IsReadOnly);
 }
Ejemplo n.º 7
0
 public void TestAddComplex()
 {
     ImageFactory.GenerateComplex(50, 50).Add(default(Complex));
 }
Ejemplo n.º 8
0
 public void TestRemoveComplex()
 {
     ImageFactory.GenerateComplex(50, 50).Remove(default(Complex));
 }