Ejemplo n.º 1
0
        public void TestAdjustableDataVoiLut()
        {
            const int    rngSeed = 0x0D924561;
            const int    firstMappedPixelValue = -5;
            const int    lastMappedPixelValue  = 1243;
            const double windowCenter          = 12345;
            const double windowWidth           = 65536;
            const int    minOutputValue        = int.MinValue;
            const int    maxOutputValue        = int.MaxValue;

            var lutData = LutTestHelper.GenerateRandomLutData(lastMappedPixelValue - firstMappedPixelValue + 1, rngSeed);

            var dataVoiLut = new AdjustableDataLut(new SimpleDataLut(firstMappedPixelValue, lutData, minOutputValue, maxOutputValue, rngSeed.ToString("X8"), rngSeed.ToString("X8")));
            var voiLut     = (IBasicVoiLutLinear)dataVoiLut;

            // do not perform exact floating point assertion, as the AdjustableDataLut function is very likely to produce floating point error
            for (var n = 0; n < lutData.Length; ++n)
            {
                Assert.AreEqual(lutData[n], dataVoiLut[n + firstMappedPixelValue], 0.5, "AdjustableDataLut[@{0}]", n);
            }

            dataVoiLut.AssertLookupValues(-10, 2000);

            voiLut.WindowCenter = windowCenter;
            voiLut.WindowWidth  = windowWidth;

            for (var n = 0; n < lutData.Length; ++n)
            {
                const double centerLessHalf = windowCenter - 0.5;
                const double windowLessOne  = windowWidth - 1;
                const double halfWidth      = windowLessOne / 2;
                const double outputRange    = ((double)maxOutputValue - minOutputValue);

                var input = lutData[n];

                double expected;
                if (input <= centerLessHalf - halfWidth)
                {
                    expected = minOutputValue;
                }
                else if (input > centerLessHalf + halfWidth)
                {
                    expected = maxOutputValue;
                }
                else
                {
                    expected = ((input - centerLessHalf) / windowLessOne + 0.5) * outputRange + minOutputValue;
                }

                Assert.AreEqual(expected, dataVoiLut[n + firstMappedPixelValue], 0.5, "After Adjust - AdjustableDataLut[@{0}]", n);
            }

            dataVoiLut.AssertLookupValues(-10, 2000);
        }
Ejemplo n.º 2
0
		public void TestAdjustableDataVoiLut()
		{
			const int rngSeed = 0x0D924561;
			const int firstMappedPixelValue = -5;
			const int lastMappedPixelValue = 1243;
			const double windowCenter = 12345;
			const double windowWidth = 65536;
			const int minOutputValue = int.MinValue;
			const int maxOutputValue = int.MaxValue;

			var lutData = LutTestHelper.GenerateRandomLutData(lastMappedPixelValue - firstMappedPixelValue + 1, rngSeed);

			var dataVoiLut = new AdjustableDataLut(new SimpleDataLut(firstMappedPixelValue, lutData, minOutputValue, maxOutputValue, rngSeed.ToString("X8"), rngSeed.ToString("X8")));
			var voiLut = (IBasicVoiLutLinear) dataVoiLut;

			// do not perform exact floating point assertion, as the AdjustableDataLut function is very likely to produce floating point error
			for (var n = 0; n < lutData.Length; ++n)
			{
				Assert.AreEqual(lutData[n], dataVoiLut[n + firstMappedPixelValue], 0.5, "AdjustableDataLut[@{0}]", n);
			}

			dataVoiLut.AssertLookupValues(-10, 2000);

			voiLut.WindowCenter = windowCenter;
			voiLut.WindowWidth = windowWidth;

			for (var n = 0; n < lutData.Length; ++n)
			{
				const double centerLessHalf = windowCenter - 0.5;
				const double windowLessOne = windowWidth - 1;
				const double halfWidth = windowLessOne/2;
				const double outputRange = ((double) maxOutputValue - minOutputValue);

				var input = lutData[n];

				double expected;
				if (input <= centerLessHalf - halfWidth)
					expected = minOutputValue;
				else if (input > centerLessHalf + halfWidth)
					expected = maxOutputValue;
				else
					expected = ((input - centerLessHalf)/windowLessOne + 0.5)*outputRange + minOutputValue;

				Assert.AreEqual(expected, dataVoiLut[n + firstMappedPixelValue], 0.5, "After Adjust - AdjustableDataLut[@{0}]", n);
			}

			dataVoiLut.AssertLookupValues(-10, 2000);
		}