Beispiel #1
0
        public static void LumaFromLeft(string filepath)
        {
            logger.Trace("Starting Luma From Left");
            Bitmap source = new Bitmap(filepath);
            var    image  = new Image <Bgra, Byte>(source);

            double[] lumas = Luminousity.RepresentativeLuminousity(image, 5, 10, Direction.FromRight);
            Visualizer.Plot(lumas, "RepresentativeLuminousity Values " + filepath.Split('\\').Last());
        }
Beispiel #2
0
        public void RepresentativeLuminousityTest()
        {
            const int imgSize = 100;

            // Create a Square
            Point[] square = new Point[4];
            square[0] = new Point(25, 25);
            square[1] = new Point(75, 25);
            square[2] = new Point(75, 75);
            square[3] = new Point(25, 75);

            var backgroundColor = new Bgra(0, 0, 0, 0);
            var foregroundColor = new Bgra(255, 255, 255, 255);

            // Create an Original Image
            var original = new Image <Bgra, Byte>(imgSize, imgSize, backgroundColor);

            original.FillConvexPoly(square, foregroundColor);

            // Create an Expected output array
            var expected = new double[imgSize];

            for (int ii = 0; ii < imgSize; ii++)
            {
                if (ii >= 25 && ii <= 75)
                {
                    expected[ii] = Luminousity.Luma(foregroundColor);
                }
                else
                {
                    expected[ii] = Utility.Defaults.Ignore;
                }
            }

            // Perform from the top, left right and bottom
            var actualLeft   = Luminousity.RepresentativeLuminousity(original, 1, 5, Direction.FromLeft);
            var actualRight  = Luminousity.RepresentativeLuminousity(original, 1, 5, Direction.FromRight);
            var actualTop    = Luminousity.RepresentativeLuminousity(original, 1, 5, Direction.FromTop);
            var actualBottom = Luminousity.RepresentativeLuminousity(original, 1, 5, Direction.FromBottom);

            // Check that lengths match
            Assert.IsTrue(actualBottom.Length == expected.Length);
            Assert.IsTrue(actualLeft.Length == expected.Length);
            Assert.IsTrue(actualRight.Length == expected.Length);
            Assert.IsTrue(actualTop.Length == expected.Length);

            // Check that the values match
            for (int ii = 0; ii < expected.Length; ii++)
            {
                Assert.IsTrue(Math.Abs(actualBottom[ii] - expected[ii]) < 0.001);
                Assert.IsTrue(Math.Abs(actualLeft[ii] - expected[ii]) < 0.001);
                Assert.IsTrue(Math.Abs(actualRight[ii] - expected[ii]) < 0.001);
                Assert.IsTrue(Math.Abs(actualTop[ii] - expected[ii]) < 0.001);
            }
            Console.WriteLine("Luminousity Scanning Tests Succesful!");
        }
Beispiel #3
0
        public static void ChamferFromLeft(string filepath)
        {
            logger.Trace("Starting Chamfer From Left");
            double[] kernel = new[] { -1.0, 0.0, 1.0 };
            Bitmap   source = new Bitmap(filepath);
            var      image  = new Image <Bgra, Byte>(source);

            double[] lumas       = Luminousity.RepresentativeLuminousity(image, 2, 4, Direction.FromLeft);
            int[]    indicies    = Utility.GetKernelIndicies(kernel, -1);
            var      convolution = Utility.Convolute(lumas, kernel, indicies);
            var      processed   = Utility.Threshold(Utility.Absolute(convolution), 0.3);
            var      chamfers    = Chamfer.Measure(processed);

            Visualizer.Plot(chamfers, "Convolution Result");
        }
Beispiel #4
0
        public static void ConvolutionFromLeft(string filepath)
        {
            logger.Trace("Starting Convolution From Left");
            double[] kernel = new[] { -1.0, 0.0, 1.0 };
            Bitmap   source = new Bitmap(filepath);
            var      image  = new Image <Bgra, Byte>(source);

            double[] lumas       = Luminousity.RepresentativeLuminousity(image, 1, 4, Direction.FromRight);
            int[]    indicies    = Utility.GetKernelIndicies(kernel, -1);
            var      convolution = Utility.Convolute(lumas, kernel, indicies);
            var      result      = Utility.Absolute(convolution);
            var      processed   = Utility.Threshold(Utility.Absolute(convolution), 0.3);

            for (int ii = 0; ii < result.Length; ii++)
            {
                if (processed[ii] != 0.0)
                {
                    result[ii] = processed[ii];
                }
            }
            Visualizer.Plot(result, "Convolution");
        }