VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
Vintasoft.Imaging.Codecs.ImageFiles.Dicom Namespace / DicomFile Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
Класс DicomFile
В этом разделе
Позволяет манипулировать файлом DICOM.
Объектная модель
DicomPageCollection DicomDataSet DicomAnnotationTreeNode DicomStudyInfo ImageFileSource DicomFile
Синтаксис
Пример

Этот C#/VB.Код NET показывает, как получить информацию о пациенте (метаданные) из DICOM-файла.


''' <summary>
''' Gets and prints information about DICOM file.
''' </summary>
''' <param name="filePath">Path to a DICOm file.</param>
Public Sub GetDicomFileInfo(filePath As String)
    ' open DICOM file
    Using file As New Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath)
        ' show file name and page count
        System.Console.WriteLine("File: {0} Page count: {1}", System.IO.Path.GetFileName(filePath), file.Pages.Count)
        System.Console.WriteLine()

        ' get DICOM file metadata
        Dim fileMetadata As New Vintasoft.Imaging.Metadata.DicomPageMetadata(file)

        ' for each metadata node
        For Each children As Vintasoft.Imaging.Metadata.DicomDataElementMetadata In fileMetadata
            ' print information about metadata node
            PrintMetadataNodeInfo(children)
            System.Console.WriteLine()
        Next
    End Using
End Sub

''' <summary>
''' Prints information about metadata node.
''' </summary>
''' <param name="node">Metadata node.</param>
Public Sub PrintMetadataNodeInfo(node As Vintasoft.Imaging.Metadata.MetadataNode)
    ' if node is DicomDataElementMetadata
    If TypeOf node Is Vintasoft.Imaging.Metadata.DicomDataElementMetadata Then
        Dim dataElementMetadata As Vintasoft.Imaging.Metadata.DicomDataElementMetadata = DirectCast(node, Vintasoft.Imaging.Metadata.DicomDataElementMetadata)
        ' show data element info
        System.Console.Write("(0x{0},0x{1}) {2,-40} {3}", dataElementMetadata.GroupNumber.ToString("X").PadLeft(4, "0"C), dataElementMetadata.ElementNumber.ToString("X").PadLeft(4, "0"C), dataElementMetadata.Name, GetValueAsString(dataElementMetadata))
    End If

    ' show children info
    For Each children As Vintasoft.Imaging.Metadata.MetadataNode In node
        PrintMetadataNodeInfo(children)
    Next
End Sub

''' <summary>
''' Returns the metadata value as a string.
''' </summary>
''' <param name="node">The metadata node.</param>
Private Function GetValueAsString(node As Vintasoft.Imaging.Metadata.DicomDataElementMetadata) As String
    Dim value As Object = node.Value

    ' if node value is empty
    If value Is Nothing Then
        Return "NULL"
    End If

    ' if node value is array
    If TypeOf value Is System.Array Then
        Dim array As System.Array = DirectCast(value, System.Array)

        ' if array is empty
        If array.Length = 0 Then
            Return "Empty Array"
        End If

        ' get array length
        Dim length As Integer = System.Math.Min(50, array.Length)

        ' convert array to a string
        Dim result As String = "{"
        For i As Integer = 0 To length - 2
            result += String.Format("{0}, ", ConvertToString(array.GetValue(i)))
        Next
        result += String.Format("{0}", ConvertToString(array.GetValue(length - 1)))
        If array.Length <> length Then
            result += " ..."
        End If
        result += "}"

        Return result
    ' if node contains UID
    ElseIf TypeOf value Is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUidBase Then
        ' return UID value
        Return ConvertToString(DirectCast(value, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUidBase).Value)
    Else
        Return ConvertToString(value)
    End If
End Function

''' <summary>
''' Converts the specified data to a string.
''' </summary>
''' <param name="data">The data.</param>
Private Function ConvertToString(data As Object) As String
    Return System.Convert.ToString(data, System.Globalization.CultureInfo.CurrentCulture)
End Function

' This code example produces the following output:
 
  File: brain_005.dcm Pages count: 1
'
  (0x0002,0x0001) File Meta Information Version            {0, 1}
  (0x0002,0x0002) Media Storage SOP Class UID              1.2.840.10008.5.1.4.1.1.4
  (0x0002,0x0003) Media Storage SOP Instance UID           0.0.0.0.1.8811.2.5.20010413115754.12432
  (0x0002,0x0010) Transfer Syntax UID                      1.2.840.10008.1.2.1
  (0x0002,0x0012) Implementation Class UID                 0.0.0.0
  (0x0002,0x0013) Implementation Version Name              NOTSPECIFIED
  (0x0002,0x0016) Source Application Entity Title          NOTSPECIFIED
  (0x0008,0x0008) Image Type                               {ORIGINAL, PRIMARY, MPR}
  (0x0008,0x0016) SOP Class UID                            1.2.840.10008.5.1.4.1.1.4
  (0x0008,0x0018) SOP Instance UID                         0.0.0.0.1.8811.2.5.20010413115754.12432
  (0x0008,0x0020) Study Date                               16.03.2001 0:00:00
  (0x0008,0x0021) Series Date                              16.03.2001 0:00:00
  (0x0008,0x0022) Acquisition Date                         16.03.2001 0:00:00
  (0x0008,0x0023) Content Date                             23.03.2001 0:00:00
  (0x0008,0x0030) Study Time                               14:30:08
  (0x0008,0x0031) Series Time                              14:34:14
  (0x0008,0x0032) Acquisition Time                         14:34:15
  (0x0008,0x0033) Content Time                             14:30:10
  (0x0008,0x0050) Accession Number                         NULL
  (0x0008,0x0060) Modality                                 MR
  (0x0008,0x0070) Manufacturer                             GE Medical Systems
  (0x0008,0x0080) Institution Name
  (0x0008,0x0090) Referring Physician's Name
  (0x0008,0x1010) Station Name                             MRS1
  (0x0008,0x1030) Study Description                        BRAIN
  (0x0008,0x103E) Series Description                       FSE PD AXIAL OBL
  (0x0008,0x1050) Performing Physician's Name
  (0x0008,0x1070) Operators' Name                          EC
  (0x0008,0x1090) Manufacturer's Model Name                SIGNA
  (0x0010,0x0010) Patient's Name
  (0x0010,0x0020) Patient ID                               123565
  (0x0010,0x0030) Patient's Birth Date                     NULL
  (0x0010,0x0040) Patient's Sex                            F
  (0x0010,0x1010) Patient's Age                            028Y
  (0x0010,0x1030) Patient's Weight                         61,235
  (0x0010,0x21B0) Additional Patient History               NULL
  (0x0018,0x0020) Scanning Sequence                        SE
  (0x0018,0x0021) Sequence Variant                         SK
  (0x0018,0x0022) Scan Options                             SP
  (0x0018,0x0023) MR Acquisition Type                      2D
  (0x0018,0x0024) Sequence Name                            fse
  (0x0018,0x0050) Slice Thickness                          5
  (0x0018,0x0080) Repetition Time                          2300
  (0x0018,0x0081) Echo Time                                22
  (0x0018,0x0083) Number of Averages                       1
  (0x0018,0x0084) Imaging Frequency                        63,8615
  (0x0018,0x0086) Echo Number(s)                           1
  (0x0018,0x0087) Magnetic Field Strength                  1,5
  (0x0018,0x0088) Spacing Between Slices                   2
  (0x0018,0x0089) Number of Phase Encoding Steps           256
  (0x0018,0x0091) Echo Train Length                        8
  (0x0018,0x0095) Pixel Bandwidth                          31,25
  (0x0018,0x1020) Software Version(s)                      3
  (0x0018,0x1030) Protocol Name                            CLINICAL BRAIN
  (0x0018,0x1088) Heart Rate                               0
  (0x0018,0x1090) Cardiac Number of Images                 0
  (0x0018,0x1094) Trigger Window                           0
  (0x0018,0x1100) Reconstruction Diameter                  220
  (0x0018,0x1250) Receive Coil Name                        HEAD
  (0x0018,0x1310) Acquisition Matrix                       {0, 256, 256, 0}
  (0x0018,0x1312) In-plane Phase Encoding Direction        ROW
  (0x0018,0x1314) Flip Angle                               90
  (0x0018,0x1316) SAR                                      0,0313309
  (0x0018,0x5100) Patient Position                         HFS
  (0x0020,0x000D) Study Instance UID                       0.0.0.0.2.8811.20010413115754.12432
  (0x0020,0x000E) Series Instance UID                      0.0.0.0.3.8811.2.20010413115754.12432
  (0x0020,0x0010) Study ID                                 8811
  (0x0020,0x0011) Series Number                            2
  (0x0020,0x0012) Acquisition Number                       31748
  (0x0020,0x0013) Instance Number                          5
  (0x0020,0x0020) Patient Orientation                      {L, PH}
  (0x0020,0x0030) Image Position                           {-110,5, -82,1063, -44,9575}
  (0x0020,0x0032) Image Position (Patient)                 {-110,5, -82,1063, -44,9575}
  (0x0020,0x0035) Image Orientation                        {1, 0, 0, 0, 0,99096, 0,134158}
  (0x0020,0x0037) Image Orientation (Patient)              {1, 0, 0, 0, 0,99096, 0,134158}
  (0x0020,0x0052) Frame of Reference UID                   0.0.0.0.4.8811.2.20010413115754.12432
  (0x0020,0x1002) Images in Acquisition                    1
  (0x0020,0x1040) Position Reference Indicator             NA
  (0x0020,0x1041) Slice Location                           -30,2
  (0x0028,0x0002) Samples per Pixel                        1
  (0x0028,0x0004) Photometric Interpretation               MONOCHROME2
  (0x0028,0x0010) Rows                                     256
  (0x0028,0x0011) Columns                                  256
  (0x0028,0x0030) Pixel Spacing                            {0,859375, 0,859375}
  (0x0028,0x0100) Bits Allocated                           16
  (0x0028,0x0101) Bits Stored                              16
  (0x0028,0x0102) High Bit                                 15
  (0x0028,0x0103) Pixel Representation                     1
  (0x0028,0x0106) Smallest Image Pixel Value               0
  (0x0028,0x0107) Largest Image Pixel Value                932
  (0x0028,0x0120) Pixel Padding Value                      0
  (0x0028,0x1050) Window Center                            0
  (0x0028,0x1051) Window Width                             0
  (0x0028,0x1052) Rescale Intercept                        0
  (0x0028,0x1053) Rescale Slope                            1
  (0x0028,0x1054) Rescale Type                             SIGNAL INTENSITY (UNITLESS)
  (0x7FE0,0x0010) Pixel Data                               {0, 0, 0, 0, 0, 0, 0, 0, 0 ...}
  



/// <summary>
/// Gets and prints information about DICOM file.
/// </summary>
/// <param name="filePath">Path to a DICOm file.</param>
public void GetDicomFileInfo(string filePath)
{
    // open DICOM file
    using (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile file =
        new Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath))
    {
        // show file name and page count
        System.Console.WriteLine("File: {0} Page count: {1}",
            System.IO.Path.GetFileName(filePath), file.Pages.Count);
        System.Console.WriteLine();

        // get DICOM file metadata
        Vintasoft.Imaging.Metadata.DicomPageMetadata fileMetadata =
            new Vintasoft.Imaging.Metadata.DicomPageMetadata(file);

        // for each metadata node
        foreach (Vintasoft.Imaging.Metadata.DicomDataElementMetadata children in fileMetadata)
        {
            // print information about metadata node
            PrintMetadataNodeInfo(children);
            System.Console.WriteLine();
        }
    }
}

/// <summary>
/// Prints information about metadata node.
/// </summary>
/// <param name="node">Metadata node.</param>
public void PrintMetadataNodeInfo(Vintasoft.Imaging.Metadata.MetadataNode node)
{
    // if node is DicomDataElementMetadata
    if (node is Vintasoft.Imaging.Metadata.DicomDataElementMetadata)
    {
        Vintasoft.Imaging.Metadata.DicomDataElementMetadata dataElementMetadata =
            (Vintasoft.Imaging.Metadata.DicomDataElementMetadata)node;
        // show data element info
        System.Console.Write("(0x{0},0x{1}) {2,-40} {3}",
            dataElementMetadata.GroupNumber.ToString("X").PadLeft(4, '0'),
            dataElementMetadata.ElementNumber.ToString("X").PadLeft(4, '0'),
            dataElementMetadata.Name,
            GetValueAsString(dataElementMetadata));
    }

    // show children info
    foreach (Vintasoft.Imaging.Metadata.MetadataNode children in node)
        PrintMetadataNodeInfo(children);
}

/// <summary>
/// Returns the metadata value as a string.
/// </summary>
/// <param name="node">The metadata node.</param>
private string GetValueAsString(Vintasoft.Imaging.Metadata.DicomDataElementMetadata node)
{
    object value = node.Value;

    // if node value is empty
    if (value == null)
        return "NULL";

    // if node value is array
    if (value is System.Array)
    {
        System.Array array = (System.Array)value;

        // if array is empty
        if (array.Length == 0)
            return "Empty Array";

        // get array length
        int length = System.Math.Min(50, array.Length);

        // convert array to a string
        string result = "{";
        for (int i = 0; i < length - 1; i++)
            result += string.Format("{0}, ", ConvertToString(array.GetValue(i)));
        result += string.Format("{0}", ConvertToString(array.GetValue(length - 1)));
        if (array.Length != length)
            result += " ...";
        result += "}";

        return result;
    }
    // if node contains UID
    else if (value is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUidBase)
    {
        // return UID value
        return ConvertToString(((Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUidBase)value).Value);
    }
    else
    {
        return ConvertToString(value);
    }
}

/// <summary>
/// Converts the specified data to a string.
/// </summary>
/// <param name="data">The data.</param>
private string ConvertToString(object data)
{
    return System.Convert.ToString(data, System.Globalization.CultureInfo.CurrentCulture);            
}

/* This code example produces the following output:

File: brain_005.dcm Pages count: 1

(0x0002,0x0001) File Meta Information Version            {0, 1}
(0x0002,0x0002) Media Storage SOP Class UID              1.2.840.10008.5.1.4.1.1.4
(0x0002,0x0003) Media Storage SOP Instance UID           0.0.0.0.1.8811.2.5.20010413115754.12432
(0x0002,0x0010) Transfer Syntax UID                      1.2.840.10008.1.2.1
(0x0002,0x0012) Implementation Class UID                 0.0.0.0
(0x0002,0x0013) Implementation Version Name              NOTSPECIFIED
(0x0002,0x0016) Source Application Entity Title          NOTSPECIFIED
(0x0008,0x0008) Image Type                               {ORIGINAL, PRIMARY, MPR}
(0x0008,0x0016) SOP Class UID                            1.2.840.10008.5.1.4.1.1.4
(0x0008,0x0018) SOP Instance UID                         0.0.0.0.1.8811.2.5.20010413115754.12432
(0x0008,0x0020) Study Date                               16.03.2001 0:00:00
(0x0008,0x0021) Series Date                              16.03.2001 0:00:00
(0x0008,0x0022) Acquisition Date                         16.03.2001 0:00:00
(0x0008,0x0023) Content Date                             23.03.2001 0:00:00
(0x0008,0x0030) Study Time                               14:30:08
(0x0008,0x0031) Series Time                              14:34:14
(0x0008,0x0032) Acquisition Time                         14:34:15
(0x0008,0x0033) Content Time                             14:30:10
(0x0008,0x0050) Accession Number                         NULL
(0x0008,0x0060) Modality                                 MR
(0x0008,0x0070) Manufacturer                             GE Medical Systems
(0x0008,0x0080) Institution Name
(0x0008,0x0090) Referring Physician's Name
(0x0008,0x1010) Station Name                             MRS1
(0x0008,0x1030) Study Description                        BRAIN
(0x0008,0x103E) Series Description                       FSE PD AXIAL OBL
(0x0008,0x1050) Performing Physician's Name
(0x0008,0x1070) Operators' Name                          EC
(0x0008,0x1090) Manufacturer's Model Name                SIGNA
(0x0010,0x0010) Patient's Name
(0x0010,0x0020) Patient ID                               123565
(0x0010,0x0030) Patient's Birth Date                     NULL
(0x0010,0x0040) Patient's Sex                            F
(0x0010,0x1010) Patient's Age                            028Y
(0x0010,0x1030) Patient's Weight                         61,235
(0x0010,0x21B0) Additional Patient History               NULL
(0x0018,0x0020) Scanning Sequence                        SE
(0x0018,0x0021) Sequence Variant                         SK
(0x0018,0x0022) Scan Options                             SP
(0x0018,0x0023) MR Acquisition Type                      2D
(0x0018,0x0024) Sequence Name                            fse
(0x0018,0x0050) Slice Thickness                          5
(0x0018,0x0080) Repetition Time                          2300
(0x0018,0x0081) Echo Time                                22
(0x0018,0x0083) Number of Averages                       1
(0x0018,0x0084) Imaging Frequency                        63,8615
(0x0018,0x0086) Echo Number(s)                           1
(0x0018,0x0087) Magnetic Field Strength                  1,5
(0x0018,0x0088) Spacing Between Slices                   2
(0x0018,0x0089) Number of Phase Encoding Steps           256
(0x0018,0x0091) Echo Train Length                        8
(0x0018,0x0095) Pixel Bandwidth                          31,25
(0x0018,0x1020) Software Version(s)                      3
(0x0018,0x1030) Protocol Name                            CLINICAL BRAIN
(0x0018,0x1088) Heart Rate                               0
(0x0018,0x1090) Cardiac Number of Images                 0
(0x0018,0x1094) Trigger Window                           0
(0x0018,0x1100) Reconstruction Diameter                  220
(0x0018,0x1250) Receive Coil Name                        HEAD
(0x0018,0x1310) Acquisition Matrix                       {0, 256, 256, 0}
(0x0018,0x1312) In-plane Phase Encoding Direction        ROW
(0x0018,0x1314) Flip Angle                               90
(0x0018,0x1316) SAR                                      0,0313309
(0x0018,0x5100) Patient Position                         HFS
(0x0020,0x000D) Study Instance UID                       0.0.0.0.2.8811.20010413115754.12432
(0x0020,0x000E) Series Instance UID                      0.0.0.0.3.8811.2.20010413115754.12432
(0x0020,0x0010) Study ID                                 8811
(0x0020,0x0011) Series Number                            2
(0x0020,0x0012) Acquisition Number                       31748
(0x0020,0x0013) Instance Number                          5
(0x0020,0x0020) Patient Orientation                      {L, PH}
(0x0020,0x0030) Image Position                           {-110,5, -82,1063, -44,9575}
(0x0020,0x0032) Image Position (Patient)                 {-110,5, -82,1063, -44,9575}
(0x0020,0x0035) Image Orientation                        {1, 0, 0, 0, 0,99096, 0,134158}
(0x0020,0x0037) Image Orientation (Patient)              {1, 0, 0, 0, 0,99096, 0,134158}
(0x0020,0x0052) Frame of Reference UID                   0.0.0.0.4.8811.2.20010413115754.12432
(0x0020,0x1002) Images in Acquisition                    1
(0x0020,0x1040) Position Reference Indicator             NA
(0x0020,0x1041) Slice Location                           -30,2
(0x0028,0x0002) Samples per Pixel                        1
(0x0028,0x0004) Photometric Interpretation               MONOCHROME2
(0x0028,0x0010) Rows                                     256
(0x0028,0x0011) Columns                                  256
(0x0028,0x0030) Pixel Spacing                            {0,859375, 0,859375}
(0x0028,0x0100) Bits Allocated                           16
(0x0028,0x0101) Bits Stored                              16
(0x0028,0x0102) High Bit                                 15
(0x0028,0x0103) Pixel Representation                     1
(0x0028,0x0106) Smallest Image Pixel Value               0
(0x0028,0x0107) Largest Image Pixel Value                932
(0x0028,0x0120) Pixel Padding Value                      0
(0x0028,0x1050) Window Center                            0
(0x0028,0x1051) Window Width                             0
(0x0028,0x1052) Rescale Intercept                        0
(0x0028,0x1053) Rescale Slope                            1
(0x0028,0x1054) Rescale Type                             SIGNAL INTENSITY (UNITLESS)
(0x7FE0,0x0010) Pixel Data                               {0, 0, 0, 0, 0, 0, 0, 0, 0 ...}
*/

Иерархия наследования
Требования

Целевые платформы: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

Смотрите также