public PixelDataInfo(DicomAttributeCollection dataset) { dataset.LoadDicomFields(this); AspectRatio = PixelAspectRatio.FromString(dataset[DicomTags.PixelAspectRatio].ToString()) ?? new PixelAspectRatio(0, 0); PixelSpacing = PixelSpacing.FromString(dataset[DicomTags.PixelSpacing].ToString()) ?? new PixelSpacing(0, 0); ImagerPixelSpacing = PixelSpacing.FromString(dataset[DicomTags.ImagerPixelSpacing].ToString()) ?? new PixelSpacing(0, 0); }
protected void SerializeDisplayedArea(DisplayedAreaModuleIod displayedAreaModule, DicomPresentationImageCollection <T> images) { displayedAreaModule.InitializeAttributes(); List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem> displayedAreas = new List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem>(); foreach (T image in images) { DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem displayedArea = new DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem(); displayedArea.InitializeAttributes(); displayedArea.ReferencedImageSequence = new[] { CreateImageSopInstanceReference(image.Frame) }; ImageGraphic imageGraphic = ((IImageGraphicProvider)image).ImageGraphic; Size imageSize = new Size(imageGraphic.Columns, imageGraphic.Rows); // compute the visible area of the image as a rectangle oriented positively in screen space RectangleF visibleImageArea = imageGraphic.SpatialTransform.ConvertToSource(image.ClientRectangle); visibleImageArea = RectangleUtilities.ConvertToPositiveRectangle(visibleImageArea); visibleImageArea = RectangleUtilities.RoundInflate(visibleImageArea); visibleImageArea = RectangleUtilities.Intersect(visibleImageArea, new Rectangle(new Point(0, 0), imageSize)); // compute the pixel addresses of the visible area by intersecting area with actual pixel addresses available Rectangle visiblePixels = ConvertToPixelAddressRectangle(Rectangle.Truncate(visibleImageArea)); displayedArea.DisplayedAreaTopLeftHandCorner = visiblePixels.Location; displayedArea.DisplayedAreaBottomRightHandCorner = visiblePixels.Location + visiblePixels.Size; ISpatialTransform spatialTransform = image.SpatialTransform; switch (_displayAreaSerializationOption) { case DisplayAreaSerializationOption.SerializeAsMagnification: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.Magnify; displayedArea.PresentationPixelMagnificationRatio = spatialTransform.Scale; break; case DisplayAreaSerializationOption.SerializeAsTrueSize: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.TrueSize; displayedArea.PresentationPixelSpacing = image.Frame.NormalizedPixelSpacing; break; case DisplayAreaSerializationOption.SerializeAsDisplayedArea: default: displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.ScaleToFit; break; } displayedArea.PresentationPixelAspectRatio = PixelAspectRatio.FromString(image.Frame.NormalizedPixelSpacing.GetPixelAspectRatioString()); displayedAreas.Add(displayedArea); } displayedAreaModule.DisplayedAreaSelectionSequence = displayedAreas.ToArray(); }