예제 #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());
        }
예제 #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!");
        }
예제 #3
0
        public void WeightingTest()
        {
            Console.WriteLine("Weighting Testing Begin...");
            var expected = new[] { 0.4, 0.3, 0.2, 0.1 };
            var actual   = Luminousity.LinearWeighting(4);

            Assert.IsTrue(expected.Length == actual.Length);
            for (int ii = 0; ii < expected.Length; ii++)
            {
                Assert.IsTrue(Math.Abs(Math.Round(10 * expected[ii]) - Math.Round(10 * actual[ii])) < 0.001);
            }
            Console.WriteLine("Weighting Successful");
        }
예제 #4
0
        public void LumaCalculationTest()
        {
            Console.WriteLine("Create a new color");

            const double expectedB = 0.0;
            var          actualB   = Luminousity.Luma(new Bgra(0, 0, 0, 0));
            const double expectedA = 255.0;
            var          actualA   = Luminousity.Luma(new Bgra(Byte.MaxValue, Byte.MaxValue, Byte.MaxValue, 0));

            Assert.IsTrue((Math.Abs(expectedA - actualA) < 0.0001));
            Assert.IsTrue((Math.Abs(expectedB - actualB) < 0.001));
            Assert.IsTrue((Math.Abs(actualA - actualB) > 0.001));
            Console.WriteLine("RepresentativeLuminousity Calculated Succesfully");
        }
예제 #5
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");
        }
예제 #6
0
        public void ArrayRepresentativeTest()
        {
            Console.WriteLine("Starting Luma( Color Array) Test");

            var colors = new Bgra[4];

            colors[0] = new Bgra(0, 0, 100, 0);
            colors[1] = new Bgra(0, 0, 90, 0);
            colors[2] = new Bgra(0, 0, 100, 0);
            colors[3] = new Bgra(0, 0, 100, 0);
            var expected = Luminousity.Luma(new Bgra(0, 0, (40 + 27 + 20 + 10), 0));
            var actual   = Luminousity.RepresentativeLuma(colors, Luminousity.LinearWeighting(colors.Length));

            Assert.IsTrue(Math.Abs(actual - expected) < 0.01);
            Console.WriteLine("Representative of Array Luma Test Successful");
        }
예제 #7
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");
        }