Пример #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));
        }
Пример #2
0
 public void TestEqualizeFrog()
 {
     ImageFactory
     .Generate(ImageTests.FrogPath)
     .Equalize()
     .WriteImage(Path.Combine(WorkingDirectory, "frog equalized"));
 }
Пример #3
0
        public void TestConvolve()
        {
            var bun = ImageFactory.Generate(ImageTests.BunnyPath);

            bun.Copy()
            .ConvolveRows(1, -1)
            .WriteImage(Path.Combine(WorkingDirectory, "C Rows"));

            bun.Copy()
            .ConvolveCols(1, -1)
            .WriteImage(Path.Combine(WorkingDirectory, "C Cols"));

            bun.Copy()
            .Convolve(
                new double[][]
            {
                new[] { -1.0, +1 },
                new[] { +1.0, -1 }
            })
            .WriteImage(Path.Combine(WorkingDirectory, "C Rows and Cols"));

            bun.Copy()
            .Convolve(
                new double[][]
            {
                new double[] { 1, 1, 1 },
                new double[] { 1, -8, 1 },
                new double[] { 1, 1, 1, }
            })
            .WriteImage(Path.Combine(WorkingDirectory, "C Rows and Cols 2"));
        }
Пример #4
0
        public void TestGenerate()
        {
            // GrayScale Image
            var img = ImageFactory.Generate(BunnyPath);

            Assert.IsFalse(ImageEmpty(img));
        }
Пример #5
0
        public void TestLeftToRight()
        {
            var bun = ImageFactory.Generate(BunnyPath);

            ImageFunctions.LeftToRight(bun, bun, bun)
            .WriteImage(Path.Combine(WorkingDirectory, "LeftToRight"));
        }
Пример #6
0
        public void TestTopToBottom()
        {
            var bun = ImageFactory.Generate(BunnyPath);

            ImageFunctions.TopToBottom(bun, bun, bun)
            .WriteImage(Path.Combine(WorkingDirectory, "TopToBottom"));
        }
Пример #7
0
        public void TestCdf()
        {
            double[] cdf = ImageFactory.Generate(ImageTests.FrogPath).CumulativeDistribution();

            Assert.IsNotNull(cdf);
            Assert.IsTrue(cdf.Length != 0);
        }
Пример #8
0
        public void BhattacharryaDistance()
        {
            var bunny = ImageFactory.Generate(ImageTests.BunnyPath);
            var value = bunny.HellingerDistance(bunny);

            // No difference between the images
            Assert.IsTrue(value == 0.0);
        }
Пример #9
0
        public void TestConvolveOther()
        {
            var bunny = ImageFactory.Generate(ImageTests.BunnyPath);

            bunny.GaussianBlur()
            .WriteImage(Path.Combine(WorkingDirectory, "GaussianBlur"));

            bunny.GaussianBlur2()
            .WriteImage(Path.Combine(WorkingDirectory, "GaussianBlur2"));

            bunny.GaussianBlur3()
            .WriteImage(Path.Combine(WorkingDirectory, "GaussianBlur3"));

            bunny.Unsharpen()
            .WriteImage(Path.Combine(WorkingDirectory, "Unsharpen"));

            bunny.Sharpness()
            .WriteImage(Path.Combine(WorkingDirectory, "Sharpness"));

            bunny.Sharpen()
            .WriteImage(Path.Combine(WorkingDirectory, "Sharpness"));

            bunny.EdgeDetect()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect"));

            bunny.EdgeDetect2()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect2"));

            bunny.EdgeDetect3()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect3"));

            bunny.EdgeDetect4()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect45"));

            bunny.EdgeDetect5()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect5"));

            bunny.EdgeDetect6()
            .WriteImage(Path.Combine(WorkingDirectory, "EdgeDetect6"));

            bunny.SobelHorizontal()
            .WriteImage(Path.Combine(WorkingDirectory, "SobelHorizontal"));

            bunny.SobelVertical()
            .WriteImage(Path.Combine(WorkingDirectory, "SobelVertical"));

            bunny.PrevitVertical()
            .WriteImage(Path.Combine(WorkingDirectory, "PrevitVerical"));

            bunny.PrevitHorizontal()
            .WriteImage(Path.Combine(WorkingDirectory, "PrevitHorizontal"));

            bunny.BoxBlur()
            .WriteImage(Path.Combine(WorkingDirectory, "BoxBlur"));

            bunny.TriangleBlur()
            .WriteImage(Path.Combine(WorkingDirectory, "TriangleBlur"));
        }
Пример #10
0
        public void TestZeroCrossings2()
        {
            var bunny = ImageFactory
                        .Generate(ImageTests.BunnyPath)
                        .ZeroCrossings(CrossingMethod.Two);

            bunny.Scale = 8.0;
            bunny.WriteImage(WorkingDirectory, "ZeroCrossings2");
        }
Пример #11
0
        public void TestZeroCrossingsChimney()
        {
            var chimney = ImageFactory.Generate(ImageTests.ChimneyPath)
                          .ZeroCrossings(CrossingMethod.One);

            chimney.Scale = 20.0;

            chimney.WriteImage(WorkingDirectory, "ChimneyZeroCross");
        }
Пример #12
0
        public void DoubleToFromComplex()
        {
            IImage <double>  bunny       = ImageFactory.Generate(BunnyPath);
            IImage <Complex> complxBunny = bunny.ToComplexImage();
            IImage <double>  bunny2      = complxBunny.RealPart();

            // Real(Complex(bunny)) == bunny
            Assert.IsTrue(ImagesEqual(bunny, bunny2));
        }
Пример #13
0
        public void TestMatrixProduct()
        {
            var bun = ImageFactory.Generate(ImageTests.BunnyPath);

            Assert.IsFalse(ImageEmpty(bun));

            bun.Multiply(bun)
            .WriteImage(WorkingDirectory, "Matrix Product");
        }
Пример #14
0
        public void TestProject()
        {
            var mona  = ImageFactory.Generate(ImageTests.MonaPath);
            var mona2 = mona.UpsampleRows();

            Assert.IsFalse(ImageEmpty(mona2));
            Assert.IsTrue(mona.Height * 2 == mona2.Height);
            mona2.WriteImage(WorkingDirectory, "projected");
        }
Пример #15
0
        public void FftTests()
        {
            IImage <double> bunny = ImageFactory.Generate(BunnyPath)
                                    .Crop(0, 0, 512, 512);

            IImage <double> bunny2 = bunny.Fft().InverseFft().Normalize256();

            // IMG = INVFFT( FFT(IMG) )
            Assert.IsTrue(ImagesEqualWithinEpsilon(bunny, bunny2, (x, y) => Math.Abs(x - y) < 0.05));
        }
Пример #16
0
        public override void Handle(HttpRequest request, HttpResponse response)
        {
            response.ContentType = "image/jpeg";
            var task = ImageFactory.Generate(true);

            using (var image = task.Result.Item1)
            {
                image.Save(response.OutputStream, ImageFormat.Jpeg);
            }
        }
Пример #17
0
        public void TestHistogram()
        {
            IImage <double> frog = ImageFactory
                                   .Generate(ImageTests.FrogPath);

            int[] histogram = frog.Histogram();

            Assert.IsNotNull(histogram);
            Assert.IsTrue(histogram.Length > 10);
            // Assert.IsTrue(histogram.Distinct().Count() == histogram.Length);
        }
Пример #18
0
        public void AddSubtract()
        {
            IImage <double> bunny = ImageFactory.Generate(BunnyPath);
            // bunny + bunny
            IImage <double> added = ImageFunctions.Add(bunny, bunny);
            // bunny + bunny - bunny
            IImage <double> original = ImageFunctions.Subtract(added, bunny);

            // bunny + bunny - bunny == bunny
            Assert.IsTrue(ImagesEqual(bunny, original));
        }
Пример #19
0
        public void FftFilterPassAll()
        {
            IImage <double> bunny = ImageFactory.Generate(BunnyPath)
                                    .Crop(0, 0, 512, 512);

            IImage <double> bunny2 = bunny.ApplyFilter((x, y) => 1.0).Normalize256();

            // Filter is pass through (multiplication w/ 1 for all frequencies)
            // IMG = INVFFT( FFT(IMG) )
            Assert.IsTrue(ImagesEqualWithinEpsilon(bunny, bunny2, (x, y) => Math.Abs(x - y) < 0.05));
        }
Пример #20
0
        public void TestImageCropRectangle()
        {
            IImage <double> image = ImageFactory.Generate(BunnyPath);

            int dimensions = Math.Min(image.Width, image.Height);

            image.Crop(new System.Drawing.Rectangle()
            {
                Height = dimensions, Width = dimensions / 2
            })
            .WriteImage(Path.Combine(WorkingDirectory, "Bun Crop Rectangle"));
        }
Пример #21
0
        private async Task PostImage()
        {
            var server = Api.Photo.GetWallUploadServer((long)Config.pabloses.grekaneveryday);

            var data = await ImageFactory.Generate();

            var post = data.Item2;

            var ms = new MemoryStream();

            data.Item1.Save(ms, ImageFormat.Jpeg);
            ms.Position = 0;

            var response = await _client.PostAsync(
                server.UploadUrl,
                new MultipartFormDataContent { { new StreamContent(ms), "photo", "grek.jpg" } }
                );

            ms.Position = 0;

//            Tweetinvi.Auth.ExecuteOperationWithCredentials(_twicreds, () =>
//                Tweet.PublishTweet(post.Text, new PublishTweetOptionalParameters
//                {
//                    Medias =
//                    {
//                        Tweetinvi.Auth.ExecuteOperationWithCredentials(
//                            _twicreds,
//                            () => Upload.UploadImage(ms.ToArray())
//                        )
//                    }
//                }));

            await _telegram.SendPhotoAsync(
                (string)Config.telegram.grekaneveryday.channel,
                new FileToSend("grek.jpg", ms)
                );

            var text = $"[{post.Date}] {post.Text}";

            await _telegram.SendTextMessageAsync("@textgrekaneveryday", text);

            var respString = await response.Content.ReadAsStringAsync();

            Api.Wall.Post(new WallPostParams
            {
                OwnerId     = -(long)Config.pabloses.grekaneveryday,
                FromGroup   = true,
                Attachments = Api.Photo.SaveWallPhoto(
                    respString, (ulong)Config.bot_id, (ulong)Config.pabloses.grekaneveryday
                    ),
                Message = post.Text
            });
        }
Пример #22
0
        public void ApplyFiler()
        {
            var filter = Filters.MakeFilter(512, 512, Filters.Gaussian(256.0));

            IImage <Complex> bun = ImageFactory
                                   .Generate(ImageTests.BunnyPath)
                                   .Crop(0, 0, 512, 512)
                                   .Fft();

            ImageFunctions
            .Multiply(bun, filter.ToComplexImage())
            .InverseFft()
            .WriteImage(WorkingDirectory, "Apply Filter");
        }
Пример #23
0
        /*
         * // ratio of lower:upper threshold
         * private static int ratio = 3;
         *
         * // maximum value for the lower Threshold
         * private static int max_lowThreshold = 100;
         * private static double[][] Gx =
         *  new[] {
         *      new double[] { -1, 0, +1 },
         *      new double[] { -2, 0, +2 },
         *      new double[] { -1, 0, +1 }
         *  };
         *
         * private static double[][] Gy =
         *  new[] {
         *      new double[] { -1, -2, -1 },
         *      new double[] { +0, +0, +0 },
         *      new double[] { +1, +2, +1 }
         *  };
         */
        /*
         *
         * GAUSSIAN_NOISE_ REDUCE
         *
         * apply 5x5 Gaussian convolution filter, shrinks the image by 4 pixels in each direction, using Gaussian filter found here:
         *
         * http://en.wikipedia.org/wiki/Canny_edge_detector
         *
         */
        private static IImage <double> CannyEdgeDetect(IImage <double> img_in, double highThresholdPercentage, double lowThresholdPercentage)
        {
            double[] g;
            int[]    direction;
            CalcGradientSobel(img_in, out g, out direction);

            IImage <double> img_scratch = ImageFactory.Generate(img_in.Width, img_in.Height);

            CannyEdgeDetector.NonMaxSuppression(img_scratch, g, direction);

            double high, low;

            EstimateThreshold(img_scratch, highThresholdPercentage, lowThresholdPercentage, out high, out low);

            return(hysteresis(high, low, img_scratch));
        }
Пример #24
0
        public void TestPoLink2()
        {
            var bunny = ImageFactory
                        .Generate(ImageTests.BunnyPath)
                        .ZeroCrossings(CrossingMethod.Three);

            bunny.Scale = 16.0;

            var link = bunny
                       .PoLink(false, 1.0, 0.5, 2.0, 0.785398, 0.6, 2.0)
                       .DisplayLinkGraph();

            string path = Path.Combine(WorkingDirectory, "DisplayLinkGraph2") + ".png";

            File.WriteAllBytes(path, link);
        }
Пример #25
0
        public void Cols()
        {
            IImage <double> image = ImageFactory.Generate(BunnyPath);

            ImageColumn <double>[] cols = image.Columns();
            Assert.IsNotNull(cols);
            Assert.IsTrue(cols.Length == image.Height);

            for (int j = 0; j < image.Width; j++)
            {
                ImageColumn <double> col = cols[j];
                Assert.IsNotNull(col);
                Assert.IsTrue(col.Count == col.Height);
                Assert.IsTrue(col.Count == image.Height);
            }
        }
Пример #26
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"));
        }
Пример #27
0
        public void TestImageCrop()
        {
            IImage <double> image = ImageFactory.Generate(BunnyPath);

            int dimensions = Math.Min(image.Width, image.Height / 2);

            var cropped = image.Crop(0, 0, dimensions, dimensions);

            Assert.IsTrue(cropped.Height == dimensions);
            Assert.IsTrue(cropped.Width == dimensions);

            for (int y = 0; y < dimensions; y++)
            {
                for (int x = 0; x < dimensions; x++)
                {
                    Assert.IsTrue(cropped[y, x].Equals(image[y, x]));
                }
            }

            cropped.WriteImage(Path.Combine(WorkingDirectory, "Bun Crop"));
        }
Пример #28
0
        public void Rows()
        {
            IImage <double> image = ImageFactory.Generate(BunnyPath);

            ImageRow <double>[] rows = image.Rows();

            Assert.IsNotNull(rows);
            Assert.IsTrue(rows.Length == image.Height);

            for (int i = 0; i < image.Height; i++)
            {
                ImageRow <double> row = rows[i];
                Assert.IsNotNull(row);
                Assert.IsTrue(row.Count == row.Width);
                Assert.IsTrue(row.Count == image.Width);

                for (int x = 0; x < image.Width; x++)
                {
                    Assert.IsTrue(image[i, x].Equals(row[x]));
                }
            }
        }
Пример #29
0
 public void TestGrayscaleTransforms()
 {
     this.Transforms(ImageFactory.Generate(BunnyPath));
 }
Пример #30
0
 public void TestEquivalenceComplex()
 {
     Equivalence(ImageFactory.Generate(BunnyPath).ToComplexImage());
 }