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();
        }
        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();
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public void TestCalculatePercentile3()
        {
            //Test unordered
            uint[] arr = { 2, 3, 0 };

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

            Assert.AreEqual(2, p.CalculatePercentile(50));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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));
        }