Exemplo n.º 1
0
        /// <summary>
        /// Tests the statistics calculation for consistency over a number of trial runs using the same shape.
        /// </summary>
        protected void TestRoiStatsCalculationConsistency()
        {
            const int samples  = 100;
            const int gridSize = 4;

            foreach (ImageKey imageKey in Enum.GetValues(typeof(ImageKey)))
            {
                WriteLine("Testing on Image {0}", imageKey.ToString());
                using (IPresentationImage image = GetImage(imageKey))
                {
                    IImageSopProvider        provider = (IImageSopProvider)image;
                    IOverlayGraphicsProvider overlayGraphicsProvider = (IOverlayGraphicsProvider)image;
                    int rows = provider.Frame.Rows;
                    int cols = provider.Frame.Columns;

                    for (int r = rows / gridSize / 2; r < rows; r += rows / gridSize)
                    {
                        for (int c = cols / gridSize / 2; c < cols; c += cols / gridSize)
                        {
                            if (this.VerboseOutput)
                            {
                                WriteLine("Checking {0} core samples for consistent results at location {1}", samples, new PointF(c, r));
                            }

                            T      shapeData = CreateCoreSampleShape(new PointF(c, r), rows, cols);
                            double expectedArea = 0, expectedMean = 0, expectedSigma = 0;
                            for (int n = 0; n < samples; n++)
                            {
                                Roi           userRoi = CreateRoiFromGraphic(overlayGraphicsProvider, shapeData);
                                RoiStatistics stats   = RoiStatistics.Calculate(userRoi);
                                if (n == 0)
                                {
                                    if (userRoi is IRoiAreaProvider)
                                    {
                                        expectedArea = ((IRoiAreaProvider)userRoi).Area;
                                    }
                                    expectedMean  = stats.Mean;
                                    expectedSigma = stats.StandardDeviation;

                                    if (this.VerboseOutput)
                                    {
                                        WriteLine("First sample reported A={0:f0}  \u03BC={1:f3}  \u03C3={2:f3}", expectedArea, expectedMean, expectedSigma);
                                    }

                                    continue;
                                }

                                // very strict tolerance. performing the calculation the first time should yield the same result as the next hundred times.
                                if (userRoi is IRoiAreaProvider)
                                {
                                    Assert.AreEqual(expectedArea, ((IRoiAreaProvider)userRoi).Area, double.Epsilon, "Area calculation consistency fail.");
                                }
                                Assert.AreEqual(expectedMean, stats.Mean, double.Epsilon, "Mean calculation consistency fail.");
                                Assert.AreEqual(expectedSigma, stats.StandardDeviation, double.Epsilon, "Stdev calculation consistency fail.");
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestNonTrivial3()
        {
            RoiStatistics stats;

            using (TestRoi roi = new TestRoi(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150, 247, 28, 86, 47, 137, 107, 233, 52, 235, 152, 249, 190, 56, 106, 255, 221, 89, 151, 193))
            {
                stats = RoiStatistics.Calculate(roi);
            }
            Assert.IsTrue(stats.Valid);
            Assert.AreEqual(82.88888889, stats.Mean, 1, "Mean incorrect.");
            Assert.AreEqual(93.56549357, stats.StandardDeviation, 2, "StdDev incorrect.");
        }
Exemplo n.º 3
0
        public void TestNonTrivial2()
        {
            RoiStatistics stats;

            using (TestRoi roi = new TestRoi(80, 233, 92, 23, 201, 13, 162, 42, 149, 102, 179, 4, 24, 102, 124, 125, 28, 66, 32, 223, 80, 61, 234, 230, 77, 251, 188, 119, 135, 116, 204, 184, 198, 52, 200, 7))
            {
                stats = RoiStatistics.Calculate(roi);
            }
            Assert.IsTrue(stats.Valid);
            Assert.AreEqual(120.5555556, stats.Mean, 1, "Mean incorrect.");
            Assert.AreEqual(76.14026322, stats.StandardDeviation, 2, "StdDev incorrect.");
        }
Exemplo n.º 4
0
        public void TestNonTrivial()
        {
            RoiStatistics stats;

            using (TestRoi roi = new TestRoi(6, 86, 142, 208, 205, 214, 71, 8, 224, 231, 131, 4, 56, 123, 186, 180, 103, 163, 166, 212, 48, 130, 111, 94, 37, 239, 200, 117, 188, 56, 50, 42, 135, 114, 168, 231))
            {
                stats = RoiStatistics.Calculate(roi);
            }
            Assert.IsTrue(stats.Valid);
            Assert.AreEqual(129.9722222, stats.Mean, 1, "Mean incorrect.");
            Assert.AreEqual(71.59189344, stats.StandardDeviation, 2, "StdDev incorrect.");
        }
Exemplo n.º 5
0
        public void TestTrivial()
        {
            const byte value = 129;

            byte[] data = new byte[36];
            for (int n = 0; n < 36; n++)
            {
                data[n] = value;
            }
            RoiStatistics stats;

            using (TestRoi roi = new TestRoi(data))
            {
                stats = RoiStatistics.Calculate(roi);
            }
            Assert.IsTrue(stats.Valid);
            Assert.AreEqual(value, stats.Mean, "Mean incorrect.");
            Assert.AreEqual(0, stats.StandardDeviation, "StdDev incorrect.");
        }
Exemplo n.º 6
0
        private void PerformRoiStatsCalculations(Roi roi, double expectedPerimeter, double expectedArea, double expectedMean, double expectedSigma, string mode, string shapeData, Units areaPerimeterUnits)
        {
            WriteLine("Testing {1}-MODE {2} ROI using {0}", shapeData, mode.ToUpperInvariant(), this.ShapeName);

            RoiStatistics roiStats      = RoiStatistics.Calculate(roi);
            double        measuredArea  = 0;
            double        measuredMean  = roiStats.Mean;
            double        measuredSigma = roiStats.StandardDeviation;

            if (roi is IRoiAreaProvider)
            {
                ((IRoiAreaProvider)roi).Units = areaPerimeterUnits;
                measuredArea = ((IRoiAreaProvider)roi).Area;
            }

            if (this.VerboseOutput)
            {
                WriteLine("Expecting  A={0:f0}  \u03BC={1:f3}  \u03C3={2:f3}", expectedArea, expectedMean, expectedSigma);
                WriteLine("Actual     A={0:f0}  \u03BC={1:f3}  \u03C3={2:f3}", measuredArea, measuredMean, measuredSigma);
            }

            double errorArea  = Math.Abs(expectedArea - measuredArea);
            double errorMean  = Math.Abs(expectedMean - measuredMean);
            double errorSigma = Math.Abs(expectedSigma - measuredSigma);

            WriteLine("Errors    \u0394A={0:f2} \u0394\u03BC={1:f2} \u0394\u03C3={2:f2}", errorArea, errorMean, errorSigma);

            double areaToleranceFactor = 0.01;

            if (expectedPerimeter / expectedArea > 0.25)
            {
                WriteLine("High Perimeter-to-Area Ratio (P={0:f3})", expectedPerimeter);
                areaToleranceFactor = 0.05;
            }

            double toleranceArea  = areaToleranceFactor * expectedPerimeter;
            double toleranceMean  = 2.0;
            double toleranceSigma = 2.0;

            Assert.AreEqual(expectedArea, measuredArea, toleranceArea, string.Format("\u0394area exceeds tolerance of {0:p0} of ROI perimeter", areaToleranceFactor));
            Assert.AreEqual(expectedMean, measuredMean, toleranceMean, string.Format("\u0394mean exceeds tolerance of 1% of pixel value range"));
            Assert.AreEqual(expectedSigma, measuredSigma, toleranceSigma, string.Format("\u0394stdev exceeds tolerance of 1% of pixel value range"));
        }
Exemplo n.º 7
0
        public void TestTrivial3()
        {
            const byte   value1 = 97;
            const byte   value2 = 232;
            const double mean   = (value2 + value1) / 2d;

            byte[] data = new byte[36];
            for (int n = 0; n < 36; n++)
            {
                data[n] = n < 18 ? value1 : value2;
            }
            RoiStatistics stats;

            using (TestRoi roi = new TestRoi(data))
            {
                stats = RoiStatistics.Calculate(roi);
            }
            Assert.IsTrue(stats.Valid);
            Assert.AreEqual(mean, stats.Mean, "Mean incorrect.");
            Assert.AreEqual(mean - value1, stats.StandardDeviation, "StdDev incorrect.");
        }