public void TestCTUncalibratedWithRogueImagerPixelSpacing() { using (var dataset = CreateMockDataset("CT", SopClass.CtImageStorage, new SizeF(1f, 2f), null, "GEOMETRY", "garbage", null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(true, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.None, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); } } }
public void TestCTCalibrated() { using (var dataset = CreateMockDataset("CT", SopClass.CtImageStorage, null, new SizeF(0.4f, 0.3f), null, null, null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.CrossSectionalSpacing, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); } } }
public void TestCRUncalibratedWithDetectorSpacingInPixelSpacing() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, new SizeF(0.4f, 0.3f), new SizeF(0.4f, 0.3f), null, null, null)) { using (var sop = (ImageSop)Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Detector, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestMGCalibratedUsingGeometry() { using (var dataset = CreateMockDataset("MG", SopClass.DigitalMammographyXRayImageStorageForPresentation, new SizeF(0.6f, 0.5f), new SizeF(0.4f, 0.3f), "GEOMETRY", null, null)) { using (var sop = (ImageSop)Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Geometry, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestDXUncalibrated() { using (var dataset = CreateMockDataset("DX", SopClass.DigitalXRayImageStorageForPresentation, null, null, null, null, null)) { using (var sop = (ImageSop)Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(true, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.None, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestMGCalibratedUsingGeometryWithMagnificationFactor() { // we don't yet support the IHE Mammo profile requirement to use Imager Pixel Spacing corrected by Estimated Radiographic Magnification Factor using (var dataset = CreateMockDataset("MG", SopClass.DigitalMammographyXRayImageStorageForPresentation, new SizeF(0.6f, 0.5f), new SizeF(0.4f, 0.3f), "GEOMETRY", null, 1.5)) { using (var sop = (ImageSop)Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Geometry, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
private static SizeF GetPresentationImageSizeF(ISelectPresentationsInformation selectPresentation, int size) { //1英寸等于25.4毫米 float num = 25.4f / ((float)size); IPresentationImage image1 = selectPresentation.Image; Frame frame = ((IImageSopProvider)image1).Frame; switch (selectPresentation.PresentationMode) { case PresentationMode.Wysiwyg: { Rectangle rectangle = selectPresentation.DisplayRectangle; int width = rectangle.Width; Rectangle rectangle2 = selectPresentation.DisplayRectangle; int height = rectangle2.Height; return(new SizeF(width * num, height * num)); } case PresentationMode.CompleteImage: { int columns = frame.Columns; return(new SizeF(columns * num, frame.Rows * num)); } case PresentationMode.TrueSize: { int num1 = frame.Columns; NormalizedPixelSpacing normalizedPixelSpacing = frame.NormalizedPixelSpacing; int rows = frame.Rows; NormalizedPixelSpacing spacing2 = frame.NormalizedPixelSpacing; double row = spacing2.Row; SizeF ef = new SizeF((float)(num1 * normalizedPixelSpacing.Column), (float)(rows * row)); IPresentationImage image2 = selectPresentation.Image; ISpatialTransform spatialTransform = ((ISpatialTransformProvider)image2).SpatialTransform; if (((spatialTransform.RotationXY / 90) % 2) == 1) { float single1 = ef.Height; ef = new SizeF(single1, ef.Width); } return(ef); } } return(SizeF.Empty); }
public static bool IsHaveModalityPixelSpacing(DicomPrinter.Configuration config, IEnumerable <ISelectPresentationsInformation> collection, out string OutMessage) { OutMessage = null; if (config.PresentationMode == PresentationMode.TrueSize) { using (IEnumerator <ISelectPresentationsInformation> enumerator = collection.GetEnumerator()) { while (enumerator.MoveNext()) { ISelectPresentationsInformation selectinfo = enumerator.Current; IPresentationImage image1 = selectinfo.Image; NormalizedPixelSpacing spacing = ((IImageSopProvider)image1).Frame.NormalizedPixelSpacing; if ((spacing == null) || spacing.IsNull) { OutMessage = "NormalizedPixelSpacing为空"; return(false); } } } } return(true); }
public void TestGetPixelAspectRatioString() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, null, new SizeF(0.6f, 0.5f), "FIDUCIAL", "details", null)) using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Assert.AreEqual(@"5\6", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.33333331, 0.3333333); Assert.AreEqual(@"1\1", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.7074200013, 0.7074200009); Assert.AreEqual(@"1\1", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.3, 0.4); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.4, 0.3000001); Assert.AreEqual(@"4\3", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.55, 0.4); Assert.AreEqual(@"11\8", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); normalizedPixelSpacing.Calibrate(0.7777777, 0.3333333); Assert.AreEqual(@"7\3", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } }
public void TestManualCalibration() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, null, new SizeF(0.6f, 0.5f), "FIDUCIAL", "details", null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); normalizedPixelSpacing.Calibrate(0.3, 0.4); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Manual, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestCRUncalibrated() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, null, null, null, null, null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(true, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.None, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestMGCalibratedUsingGeometryWithMagnificationFactor() { // we don't yet support the IHE Mammo profile requirement to use Imager Pixel Spacing corrected by Estimated Radiographic Magnification Factor using (var dataset = CreateMockDataset("MG", SopClass.DigitalMammographyXRayImageStorageForPresentation, new SizeF(0.6f, 0.5f), new SizeF(0.4f, 0.3f), "GEOMETRY", null, 1.5)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Geometry, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestMGCalibratedUsingGeometry() { using (var dataset = CreateMockDataset("MG", SopClass.DigitalMammographyXRayImageStorageForPresentation, new SizeF(0.6f, 0.5f), new SizeF(0.4f, 0.3f), "GEOMETRY", null, null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Geometry, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); Assert.AreEqual(@"3\4", normalizedPixelSpacing.GetPixelAspectRatioString(), "GetPixelAspectRatioString result"); } } }
public void TestDXUncalibrated() { using (var dataset = CreateMockDataset("DX", SopClass.DigitalXRayImageStorageForPresentation, null, null, null, null, null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(true, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.None, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual(string.Empty, normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); } } }
public void TestCRCalibratedUsingFiducialWithoutImagerPixelSpacing() { using (var dataset = CreateMockDataset("CR", SopClass.ComputedRadiographyImageStorage, null, new SizeF(0.4f, 0.3f), "FIDUCIAL", "details", null)) { using (var sop = (ImageSop) Sop.Create(dataset)) { var normalizedPixelSpacing = new NormalizedPixelSpacing(sop.Frames[1]); Console.WriteLine(GetPixelSpacingAttributeInfo(dataset)); Assert.AreEqual(false, normalizedPixelSpacing.IsNull, "IsNull property"); Assert.AreEqual(0.3, normalizedPixelSpacing.Row, _tolerance, "Row property"); Assert.AreEqual(0.4, normalizedPixelSpacing.Column, _tolerance, "Column property"); Assert.AreEqual(NormalizedPixelSpacingCalibrationType.Fiducial, normalizedPixelSpacing.CalibrationType, "CalibrationType property"); Assert.AreEqual("details", normalizedPixelSpacing.CalibrationDetails, "CalibrationDetails property"); } } }
public void TestFindFraction() { var testRational = new Action <int, int>((expectedNumerator, expectedDenominator) => { var value = 1d * expectedNumerator / expectedDenominator; int actualNumerator, actualDenominator; NormalizedPixelSpacing.TestFindFraction(value, out actualNumerator, out actualDenominator); var expectedFraction = string.Format("{0}/{1}", expectedNumerator, expectedDenominator); var actualFraction = string.Format("{0}/{1}", actualNumerator, actualDenominator); const string msg = "Value={0}, Result={1}"; Console.WriteLine(msg, value, actualFraction); Assert.AreEqual(expectedFraction, actualFraction, "Value={0}", value); }); testRational.Invoke(0, 1); testRational.Invoke(1, 10); testRational.Invoke(-1, 10); testRational.Invoke(1, 100); testRational.Invoke(1, 1000); testRational.Invoke(1, 10000); testRational.Invoke(649, 200); testRational.Invoke(649, 300); testRational.Invoke(7, 11); testRational.Invoke(5, 19); testRational.Invoke(21, 19); testRational.Invoke(37, 61); testRational.Invoke(1, 9); testRational.Invoke(5, 9); testRational.Invoke(5, 99); testRational.Invoke(5, 999); var testIrrational = new Action <double, double>((expectedValue, tolerance) => { int actualNumerator, actualDenominator; NormalizedPixelSpacing.TestFindFraction(expectedValue, out actualNumerator, out actualDenominator, tolerance); var actualFraction = string.Format("{0}/{1}", actualNumerator, actualDenominator); var actualValue = 1d * actualNumerator / actualDenominator; const string msg = "Value={0}, Result={1} ({2}), Delta={3}"; Console.WriteLine(msg, expectedValue, actualFraction, actualValue, Math.Abs(expectedValue - actualValue)); Assert.AreEqual(expectedValue, actualValue, tolerance, "Value={0}", expectedValue); }); testIrrational.Invoke(Math.PI, 1e-6); testIrrational.Invoke(Math.PI, 1e-9); testIrrational.Invoke(Math.PI, 1e-15); testIrrational.Invoke(Math.E, 1e-6); testIrrational.Invoke(Math.E, 1e-9); testIrrational.Invoke(Math.E, 1e-15); try { testIrrational.Invoke(0.5 / int.MaxValue, 1e-16); Assert.Fail("Expected overflow exception"); } catch (OverflowException) {} try { testIrrational.Invoke(2d * int.MaxValue, 1e-16); Assert.Fail("Expected overflow exception"); } catch (OverflowException) {} }