/// <summary> /// Initializes a new instance of the <see cref="SliceInformation"/> class. /// </summary> /// <param name="dicomDataset">The DICOM dataset to abstract the metadata from.</param> /// <exception cref="ArgumentException"> /// The DICOM dataset has a negative width or height. /// The DICOM dataset did not contain the required DICOM attributes ('SOPClassUID', 'ImagePositionPatient', 'Columns', 'Rows', 'PixelSpacing', 'HighBit') /// </exception> /// <exception cref="ArgumentNullException">The provided DICOM dataset is null.</exception> public static SliceInformation Create(DicomDataset dicomDataset) { dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset)); var(width, height) = dicomDataset.GetSliceSize(); var origin = dicomDataset.GetOrigin(); var direction = dicomDataset.GetDirectionalMatrix(); var sopClass = dicomDataset.GetSopClass(); var rescaleIntercept = 0.0; var rescaleSlope = 1.0; // Only fetch the rescale and intercept from CT images. if (sopClass == DicomUID.CTImageStorage) { rescaleIntercept = dicomDataset.GetRescaleIntercept(); rescaleSlope = dicomDataset.GetRescaleSlope(); } return(new SliceInformation( width: width >= 0 ? (uint)width : throw new ArgumentException("The width of a slice cannot be less than 0", nameof(dicomDataset)), height: height >= 0 ? (uint)height : throw new ArgumentException("The height of a slice cannot be less than 0", nameof(dicomDataset)), voxelWidthInMillimeters: dicomDataset.GetPixelSpacingX(), voxelHeightInMillimeters: dicomDataset.GetPixelSpacingY(), slicePosition: GetSlicePosition(direction, origin), rescaleSlope: rescaleSlope, rescaleIntercept: rescaleIntercept, highBit: dicomDataset.GetHighBit(), signedPixelRepresentation: dicomDataset.IsSignedPixelRepresentation(), origin: origin, direction: direction, sopClass: sopClass, dicomDataset: dicomDataset)); }