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 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));
        }
예제 #3
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
        }
예제 #4
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));
        }