public void DoSegment(bool[,] image, out int[,] rows, out int[,] cols)
        {
            //Count the number of dark pixels per row and column
            uint[] colDarkPixelCounts = SegmentationAlgorithmHelpers.CountNumDarkPixelsPerCol(image);
            uint[] rowDarkPixelCounts = SegmentationAlgorithmHelpers.CountNumDarkPixelsPerRow(image);

            //Calculate the Histograms to select a threshold
            BimodalHistogram colHist = new BimodalHistogram(colDarkPixelCounts.ToDoubleArr());
            BimodalHistogram rowHist = new BimodalHistogram(rowDarkPixelCounts.ToDoubleArr());

            //Find the percentile rank corresponding to the threshold selected from the Histograms
            Percentile colPercentile = new Percentile(colDarkPixelCounts.ToDoubleArr());
            Percentile rowPercentile = new Percentile(rowDarkPixelCounts.ToDoubleArr());
            double colThresholdRank = colPercentile.CalculateRank(colHist.ThresholdValue);
            double rowThresholdRank = rowPercentile.CalculateRank(rowHist.ThresholdValue);

            //Look up the percentile values for the ranks x either side of the auto-selected ones
            double colStartRank = Math.Min(100, colThresholdRank + PERCENTILE_EITHER_SIDE);
            double colEndRank = Math.Max(0, colThresholdRank - PERCENTILE_EITHER_SIDE);
            double rowStartRank = Math.Min(100, rowThresholdRank + PERCENTILE_EITHER_SIDE);
            double rowEndRank = Math.Max(0, rowThresholdRank - PERCENTILE_EITHER_SIDE);

            double colStartVal = colPercentile.CalculatePercentile(colStartRank);
            double colEndVal = colPercentile.CalculatePercentile(colEndRank);
            double rowStartVal = rowPercentile.CalculatePercentile(rowStartRank);
            double rowEndVal = rowPercentile.CalculatePercentile(rowEndRank);

            //Determine the start & end indices of all the rows & cols, using the calculated start & end threshold vals
            uint[,] colChars = SegmentationAlgorithmHelpers.FindCharIndices(colDarkPixelCounts, colStartVal, colEndVal);
            uint[,] rowChars = SegmentationAlgorithmHelpers.FindCharIndices(rowDarkPixelCounts, rowStartVal, rowEndVal);

            rows = rowChars.ToIntArr();
            cols = colChars.ToIntArr();
        }
コード例 #2
0
        public void TestData1()
        {
            //Check that the data gets sorted into ascending order
            double[] arr = { 5, 4, 3, 7 };

            Percentile p = new Percentile(arr);

            double[] expected = { 3, 4, 5, 7 };
            CollectionAssert.AreEqual(expected, p.Data);
        }
コード例 #3
0
        public void DoSegment(bool[,] image, out int[,] rows, out int[,] cols)
        {
            //Count the number of dark pixels per row and column
            uint[] colDarkPixelCounts = SegmentationAlgorithmHelpers.CountNumDarkPixelsPerCol(image);
            uint[] rowDarkPixelCounts = SegmentationAlgorithmHelpers.CountNumDarkPixelsPerRow(image);

            //Calculate the percentile-based char start/end thresholds
            Percentile colPercentile = new Percentile(colDarkPixelCounts.ToDoubleArr());
            Percentile rowPercentile = new Percentile(rowDarkPixelCounts.ToDoubleArr());
            double colCharStartThreshold = colPercentile.CalculatePercentile(CHAR_START_THRESHOLD_PERCENTILE);
            double colCharEndThreshold = colPercentile.CalculatePercentile(CHAR_END_THRESHOLD_PERCENTILE);
            double rowCharStartThreshold = rowPercentile.CalculatePercentile(CHAR_START_THRESHOLD_PERCENTILE);
            double rowCharEndThreshold = rowPercentile.CalculatePercentile(CHAR_END_THRESHOLD_PERCENTILE);

            //Determine the start & end indices of all the rows & cols, using the percentile thresholds to determine entry & exit
            uint[,] colChars = SegmentationAlgorithmHelpers.FindCharIndices(colDarkPixelCounts, colCharStartThreshold, colCharEndThreshold);
            uint[,] rowChars = SegmentationAlgorithmHelpers.FindCharIndices(rowDarkPixelCounts, rowCharStartThreshold, rowCharEndThreshold);

            rows = rowChars.ToIntArr();
            cols = colChars.ToIntArr();
        }
コード例 #4
0
        public void TestConstructor3()
        {
            //Test with List
            List<double> list = new List<double>(new double[] { 3, 5, 7 });

            Percentile p = new Percentile(list);

            double[] expected = { 3, 5, 7 };
            CollectionAssert.AreEqual(expected, p.Data);
        }
コード例 #5
0
        public void TestCalculateRank3()
        {
            //Test that calculating rank is the inverse of calculating percentile (won't always be true for arbitrary 
            //values on a small data set like this, but as the data set tends towards infinity, the difference 
            //between them will tend towards 0)
            //So here a value for which it will be true has been selected
            double[] arr = { 62, 66, 71, 75, 75, 78, 81, 83, 84, 85, 85, 87, 89, 89, 91, 92, 93, 94, 95, 99 };

            Percentile p = new Percentile(arr);

            double percentile = 50;
            double percentileVal = p.CalculatePercentile(percentile);

            Assert.AreEqual(percentile, p.CalculateRank(percentileVal));
        }
コード例 #6
0
        public void TestCalculateRank2()
        {
            //Test calculating rank on known data (non-quartile output)
            double[] arr = { 55, 59, 59, 60, 61, 63, 64, 64, 65, 68, 68, 69, 72, 74 };

            Percentile p = new Percentile(arr);

            Assert.AreEqual(32, Math.Round(p.CalculateRank(61))); //Rounded
        }
コード例 #7
0
        public void TestCalculateRank1()
        {
            //Test calculating the rank on known values
            double[] arr = { 62, 66, 71, 75, 75, 78, 81, 83, 84, 85, 85, 87, 89, 89, 91, 92, 93, 94, 95, 99 };

            Percentile p = new Percentile(arr);

            Assert.AreEqual(50, p.CalculateRank(85));
        }
コード例 #8
0
        public void TestCalculatePercentile8()
        {
            //Test percentile > 100
            double[] arr = { 1, 2 };

            Percentile p = new Percentile(arr);

            try
            {
                p.CalculatePercentile(100.1);
                //No Exception, Fail
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException)
            {
                //Correct exception, pass
            }
            catch
            {
                //Wrong Exception, fail
                Assert.Fail();
            }
        }
コード例 #9
0
        public void TestCalculatePercentile6()
        {
            //Test array with just one element
            uint[] arr = { 1 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(1, p.CalculatePercentile(23));
        }
コード例 #10
0
        public void TestCalculatePercentile5()
        {
            //Test Quartiles of random data
            uint[] arr = { 10, 20, 42, 36, 102, 12, 34 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(14, p.CalculatePercentile(25));
            Assert.AreEqual(34, p.CalculatePercentile(50));
            Assert.AreEqual(40.5, p.CalculatePercentile(75));
        }
コード例 #11
0
        public void TestCalculatePercentile4()
        {
            //Test Quartiles of data trivially split into quartiles
            uint[] arr = { 1, 2, 3, 4 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(1.5, p.CalculatePercentile(25));
            Assert.AreEqual(2.5, p.CalculatePercentile(50));
            Assert.AreEqual(3.5, p.CalculatePercentile(75));
        }
コード例 #12
0
        public void TestCalculatePercentile3()
        {
            //Test unordered
            uint[] arr = { 2, 3, 0 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(2, p.CalculatePercentile(50));
        }
コード例 #13
0
        public void TestCalculatePercentile2()
        {
            //Test even arr 50th percentile
            uint[] arr = { 0, 1 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(0.5, p.CalculatePercentile(50));
        }
コード例 #14
0
        public void TestCalculatePercentile1()
        {
            //Test odd arr 50th percentile
            uint[] arr = { 0, 2, 3 };

            Percentile p = new Percentile(arr.ToDoubleArr());

            Assert.AreEqual(2, p.CalculatePercentile(50));
        }