コード例 #1
0
 /// <summary>
 /// Gets the origin (Image position patient) from the Dicom dataset.
 /// </summary>
 /// <param name="dicomDataset">The Dicom dataset.</param>
 /// <returns>The origin.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'ImagePositionPatient' tag or did not have 3 parts to the attribute.</exception>
 public static Point3D GetOrigin(this DicomDataset dicomDataset)
 {
     dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));
     return(new Point3D(
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImagePositionPatient, 0),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImagePositionPatient, 1),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImagePositionPatient, 2)));
 }
コード例 #2
0
        /// <summary>
        /// Gets the directional matrix (image orientation to the patient) from the DICOM dataset.
        /// </summary>
        /// <param name="dicomDataset">The DICOM dataset.</param>
        /// <returns>The directional matrix (image orientation to the patient).</returns>
        /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
        /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'ImageOrientationPatient' tag or the tag did not have 6 parts.</exception>
        public static Matrix3 GetDirectionalMatrix(this DicomDataset dicomDataset)
        {
            dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));

            // Extract the 2 3-dimensional points from the 'ImageOrientationPatient' DICOM attribute.
            var imageOrientationPatientX = new Point3D(
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 0),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 1),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 2));

            var imageOrientationPatientY = new Point3D(
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 3),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 4),
                dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.ImageOrientationPatient, 5));

            // Insist that the image orientations are of unit length, this is defined in the standard but
            // rounding in serialization can cause them to be slightly off with respect to the double representation.
            imageOrientationPatientX /= imageOrientationPatientX.Norm();
            imageOrientationPatientY /= imageOrientationPatientY.Norm();

            // The standard also insists iop[0] and iop[1] are orthogonal.
            return(Matrix3.FromColumns(
                       imageOrientationPatientX,
                       imageOrientationPatientY,
                       Point3D.CrossProd(imageOrientationPatientX, imageOrientationPatientY)));
        }
コード例 #3
0
 /// <summary>
 /// Gets the SOP class from a DICOM dataset.
 /// </summary>
 /// <param name="dicomDataset">The DICOM dataset to extract the SOP class from.</param>
 /// <returns>The DICOM UID SOP class.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'SOPClassUID' tag.</exception>
 public static DicomUID GetSopClass(this DicomDataset dicomDataset)
 {
     dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));
     return(dicomDataset.GetRequiredDicomAttribute <DicomUID>(DicomTag.SOPClassUID));
 }
コード例 #4
0
 /// <summary>
 /// Gets the high bit value from the DICOM dataset.
 /// </summary>
 /// <param name="dicomDataset">The DICOM dataset.</param>
 /// <returns>The high bit value.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'HighBit' tag.</exception>
 public static uint GetHighBit(this DicomDataset dicomDataset)
 {
     dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));
     return((uint)dicomDataset.GetRequiredDicomAttribute <int>(DicomTag.HighBit));
 }
コード例 #5
0
 /// <summary>
 /// Gets the value from the 'PixelRepresentation' attribute and checks if it equals 1.
 /// If 1, the underlying voxel information is signed.
 /// </summary>
 /// <param name="dicomDataset">The DICOM dataset.</param>
 /// <returns>If the pixel representation is signed.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'PixelRepresentation' tag.</exception>
 public static bool IsSignedPixelRepresentation(this DicomDataset dicomDataset)
 {
     dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));
     return(dicomDataset.GetRequiredDicomAttribute <int>(DicomTag.PixelRepresentation) == 1);
 }
コード例 #6
0
 /// <summary>
 /// Gets the value of the 'RescaleSlope' attribute as a double.
 /// Note: This should only be used on CT datasets.
 /// </summary>
 /// <param name="dicomDataset">The DICOM dataset.</param>
 /// <returns>If the pixel representation is signed.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'RescaleSlope' tag or was not a CT image.</exception>
 public static double GetRescaleSlope(this DicomDataset dicomDataset)
 {
     CheckSopClass(dicomDataset, DicomUID.CTImageStorage);
     return(dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.RescaleSlope));
 }
コード例 #7
0
 /// <summary>
 /// Gets the height of a voxel from the DICOM dataset.
 /// </summary>
 /// <param name="dicomDataset">The DICOM dataset.</param>
 /// <returns>The voxel height.</returns>
 /// <exception cref="ArgumentNullException">The provided DICOM dataset was null.</exception>
 /// <exception cref="ArgumentException">The provided DICOM dataset did not contain the 'PixelSpacing' tag.</exception>
 public static double GetPixelSpacingY(this DicomDataset dicomDataset)
 {
     // Note: Pixel spacing in DICOM is back to front, so we take the first item (0) from this tag for Y spacing.
     dicomDataset = dicomDataset ?? throw new ArgumentNullException(nameof(dicomDataset));
     return(dicomDataset.GetRequiredDicomAttribute <double>(DicomTag.PixelSpacing, 0));
 }