/// <summary> /// Prints information about DICOM series to the console. /// </summary> /// <param name="dir">The directory path.</param> public static void PrintDicomSeriesInformation(string dir) { // create the DICOM series manager Vintasoft.Imaging.Metadata.DicomSeriesManager manager = new Vintasoft.Imaging.Metadata.DicomSeriesManager(); manager.Images = new Vintasoft.Imaging.ImageCollection(); // get names of DICOM files in file directory string[] dicomFilePaths = System.IO.Directory.GetFiles(dir, "*.dcm", System.IO.SearchOption.AllDirectories); // add DICOM files to the DICOM series manager foreach (string dicomFilePath in dicomFilePaths) manager.Images.Add(dicomFilePath); // get patient identifiers from DICOM files System.Collections.Generic.IList<string> patientIdentifiers = manager.GetPatientIdentifiers(); // for each patient identifier foreach (string patientIdentifier in patientIdentifiers) { // get patient metadata Vintasoft.Imaging.Metadata.DicomPageMetadata patientMetadata = manager.GetPatientMetadata(patientIdentifier); // print patient information System.Console.WriteLine("Patient Name: {0}", GetValueAsString(patientMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientName)); System.Console.WriteLine("Patient Birth Date: {0}", GetValueAsString(patientMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientBirthDate)); // get studies identifiers for patient System.Collections.Generic.IList<string> studyIdentifiers = manager.GetStudyIdentifiers(patientIdentifier); // print the studies count for patient System.Console.WriteLine("Study Count: {0}", studyIdentifiers.Count); // for each study identifier foreach (string studyIdentifier in studyIdentifiers) { // get the study metadata Vintasoft.Imaging.Metadata.DicomPageMetadata studyMetadata = manager.GetStudyMetadata(studyIdentifier); // print study information System.Console.WriteLine("\tStudy Date: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyDate)); System.Console.WriteLine("\tStudy Time: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyTime)); System.Console.WriteLine("\tStudy Description: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyDescription)); System.Console.WriteLine("\tModality: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.Modality)); // get series identifiers for the study System.Collections.Generic.IList<string> seriesIdentifiers = manager.GetSeriesIdentifiers(studyIdentifier); // print the series count for the study System.Console.WriteLine("\tSeries Count: {0}", seriesIdentifiers.Count); // for each series identifier foreach (string seriesIdentifier in seriesIdentifiers) { // get series metadata Vintasoft.Imaging.Metadata.DicomPageMetadata seriesMetadata = manager.GetSeriesMetadata(seriesIdentifier); // print series information System.Console.WriteLine("\t\tSeries Description: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesDescription)); System.Console.WriteLine("\t\tSeries Date: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesDate)); System.Console.WriteLine("\t\tSeries Time: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesTime)); // get images for the series Vintasoft.Imaging.VintasoftImage[] images = manager.GetSeriesImages(seriesIdentifier); // print the image count in the series System.Console.WriteLine("\t\t\tImage Count: {0}", images.Length); } } } } /// <summary> /// Returns the DICOM metadata value as a string. /// </summary> /// <param name="pageMetadata">The DICOM page metadata.</param> /// <param name="id">The DICOM data element identifier.</param> /// <returns> /// The string with DICOM metadata value. /// </returns> private static string GetValueAsString( Vintasoft.Imaging.Metadata.DicomPageMetadata pageMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId id) { // get metadata node Vintasoft.Imaging.Metadata.DicomDataElementMetadata node = pageMetadata.FindChildNode(id); // if metadata node exists if (node != null && node.Value != null) { if (node.Value is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid) { Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid uid = (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid)node.Value; return uid.Value; } else if (node.Value is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime) { Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime dateTime = (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime)node.Value; return dateTime.LocalDateTime.ToString(); } else { return System.Convert.ToString(node.Value); } } return null; } /* This code example produces the following output: Patient Name: AGECANONIX Patient Birth Date: Study Count: 1 Study Date: 01.12.2003 0:00:00 Study Time: 12:00:00 Study Description: Specials^1CoronaryCTA_with_spiral _CTA_pre Modality: CT Series Count: 1 Series Description: CorCTA w/c 1.0 B20f Series Date: 01.12.2003 0:00:00 Series Time: 12:00:00 Image Count: 10 Patient Name: CEREBRIX Patient Birth Date: 01.04.1935 0:00:00 Study Count: 2 Study Date: 20.07.2007 0:00:00 Study Time: 08:13:35.9680000 Study Description: Neuro^Crane Modality: MR Series Count: 1 Series Description: t1_mpr3D_ns_sag_gd Series Date: 20.07.2007 0:00:00 Series Time: 08:59:10.3750000 Image Count: 15 Study Date: 03.08.2007 0:00:00 Study Time: 16:42:32.1090000 Study Description: PET^PETCT_CTplusFET_LM_Brain (Adult) Modality: PT Series Count: 1 Series Description: dynamic recon 3x10min Volume (Corrected) Series Date: 03.08.2007 0:00:00 Series Time: 16:53:56 Image Count: 10 Patient Name: RATIB^OSMAN Patient Birth Date: 25.06.1955 0:00:00 Study Count: 1 Study Date: 30.09.2004 0:00:00 Study Time: 11:56:15.5930000 Study Description: Cardiac^1CTA_CORONARY_ARTERIES_lowHR_TESTBOLUS (Adult) Modality: CT Series Count: 1 Series Description: CorCTALow 2.0 B25f 0-95% Series Date: 30.09.2004 0:00:00 Series Time: 14:28:38.4680000 Image Count: 25 */
''' <summary> ''' Prints information about DICOM series to the console. ''' </summary> ''' <param name="dir">The directory path.</param> Public Shared Sub PrintDicomSeriesInformation(dir As String) ' create the DICOM series manager Dim manager As New Vintasoft.Imaging.Metadata.DicomSeriesManager() manager.Images = New Vintasoft.Imaging.ImageCollection() ' get names of DICOM files in file directory Dim dicomFilePaths As String() = System.IO.Directory.GetFiles(dir, "*.dcm", System.IO.SearchOption.AllDirectories) ' add DICOM files to the DICOM series manager For Each dicomFilePath As String In dicomFilePaths manager.Images.Add(dicomFilePath) Next ' get patient identifiers from DICOM files Dim patientIdentifiers As System.Collections.Generic.IList(Of String) = manager.GetPatientIdentifiers() ' for each patient identifier For Each patientIdentifier As String In patientIdentifiers ' get patient metadata Dim patientMetadata As Vintasoft.Imaging.Metadata.DicomPageMetadata = manager.GetPatientMetadata(patientIdentifier) ' print patient information System.Console.WriteLine("Patient Name: {0}", GetValueAsString(patientMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientName)) System.Console.WriteLine("Patient Birth Date: {0}", GetValueAsString(patientMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.PatientBirthDate)) ' get studies identifiers for patient Dim studyIdentifiers As System.Collections.Generic.IList(Of String) = manager.GetStudyIdentifiers(patientIdentifier) ' print the studies count for patient System.Console.WriteLine("Study Count: {0}", studyIdentifiers.Count) ' for each study identifier For Each studyIdentifier As String In studyIdentifiers ' get the study metadata Dim studyMetadata As Vintasoft.Imaging.Metadata.DicomPageMetadata = manager.GetStudyMetadata(studyIdentifier) ' print study information System.Console.WriteLine(vbTab & "Study Date: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyDate)) System.Console.WriteLine(vbTab & "Study Time: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyTime)) System.Console.WriteLine(vbTab & "Study Description: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.StudyDescription)) System.Console.WriteLine(vbTab & "Modality: {0}", GetValueAsString(studyMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.Modality)) ' get series identifiers for the study Dim seriesIdentifiers As System.Collections.Generic.IList(Of String) = manager.GetSeriesIdentifiers(studyIdentifier) ' print the series count for the study System.Console.WriteLine(vbTab & "Series Count: {0}", seriesIdentifiers.Count) ' for each series identifier For Each seriesIdentifier As String In seriesIdentifiers ' get series metadata Dim seriesMetadata As Vintasoft.Imaging.Metadata.DicomPageMetadata = manager.GetSeriesMetadata(seriesIdentifier) ' print series information System.Console.WriteLine(vbTab & vbTab & "Series Description: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesDescription)) System.Console.WriteLine(vbTab & vbTab & "Series Date: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesDate)) System.Console.WriteLine(vbTab & vbTab & "Series Time: {0}", GetValueAsString(seriesMetadata, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId.SeriesTime)) ' get images for the series Dim images As Vintasoft.Imaging.VintasoftImage() = manager.GetSeriesImages(seriesIdentifier) ' print the image count in the series System.Console.WriteLine(vbTab & vbTab & vbTab & "Image Count: {0}", images.Length) Next Next Next End Sub ''' <summary> ''' Returns the DICOM metadata value as a string. ''' </summary> ''' <param name="pageMetadata">The DICOM page metadata.</param> ''' <param name="id">The DICOM data element identifier.</param> ''' <returns> ''' The string with DICOM metadata value. ''' </returns> Private Shared Function GetValueAsString(pageMetadata As Vintasoft.Imaging.Metadata.DicomPageMetadata, id As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDataElementId) As String ' get metadata node Dim node As Vintasoft.Imaging.Metadata.DicomDataElementMetadata = pageMetadata.FindChildNode(id) ' if metadata node exists If node IsNot Nothing AndAlso node.Value IsNot Nothing Then If TypeOf node.Value Is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid Then Dim uid As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid = DirectCast(node.Value, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomUid) Return uid.Value ElseIf TypeOf node.Value Is Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime Then Dim dateTime As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime = DirectCast(node.Value, Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomDateTime) Return dateTime.LocalDateTime.ToString() Else Return System.Convert.ToString(node.Value) End If End If Return Nothing End Function ' This code example produces the following output: ' ' Patient Name: AGECANONIX ' Patient Birth Date: ' Study Count: 1 ' Study Date: 01.12.2003 0:00:00 ' Study Time: 12:00:00 ' Study Description: Specials^1CoronaryCTA_with_spiral _CTA_pre ' Modality: CT ' Series Count: 1 ' Series Description: CorCTA w/c 1.0 B20f ' Series Date: 01.12.2003 0:00:00 ' Series Time: 12:00:00 ' Image Count: 10 ' Patient Name: CEREBRIX ' Patient Birth Date: 01.04.1935 0:00:00 ' Study Count: 2 ' Study Date: 20.07.2007 0:00:00 ' Study Time: 08:13:35.9680000 ' Study Description: Neuro^Crane ' Modality: MR ' Series Count: 1 ' Series Description: t1_mpr3D_ns_sag_gd ' Series Date: 20.07.2007 0:00:00 ' Series Time: 08:59:10.3750000 ' Image Count: 15 ' Study Date: 03.08.2007 0:00:00 ' Study Time: 16:42:32.1090000 ' Study Description: PET^PETCT_CTplusFET_LM_Brain (Adult) ' Modality: PT ' Series Count: 1 ' Series Description: dynamic recon 3x10min Volume (Corrected) ' Series Date: 03.08.2007 0:00:00 ' Series Time: 16:53:56 ' Image Count: 10 ' Patient Name: RATIB^OSMAN ' Patient Birth Date: 25.06.1955 0:00:00 ' Study Count: 1 ' Study Date: 30.09.2004 0:00:00 ' Study Time: 11:56:15.5930000 ' Study Description: Cardiac^1CTA_CORONARY_ARTERIES_lowHR_TESTBOLUS (Adult) ' Modality: CT ' Series Count: 1 ' Series Description: CorCTALow 2.0 B25f 0-95% ' Series Date: 30.09.2004 0:00:00 ' Series Time: 14:28:38.4680000 ' Image Count: 25 '
/// <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 ...} */
''' <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> /// Returns an image of DICOM frame and saves image to a PNG file. /// </summary> /// <param name="filePath">Path to a DICOM file.</param> /// <param name="pageIndex">Index of DICOM page.</param> public void GetAndSaveDicomImage(string filePath, int pageIndex) { // open DICOM file using (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile dicomFile = new Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath)) { // get DICOM page Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomPage page = dicomFile.Pages[pageIndex]; // get DICOM image using (Vintasoft.Imaging.VintasoftImage image = page.GetImage()) { // save image to a PNG file image.Save(@"E:\DicomImage.png"); } } }
''' <summary> ''' Returns an image of DICOM frame and saves image to a PNG file. ''' </summary> ''' <param name="filePath">Path to a DICOM file.</param> ''' <param name="pageIndex">Index of DICOM page.</param> Public Sub GetAndSaveDicomImage(filePath As String, pageIndex As Integer) ' open DICOM file Using dicomFile As New Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath) ' get DICOM page Dim page As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomPage = dicomFile.Pages(pageIndex) ' get DICOM image Using image As Vintasoft.Imaging.VintasoftImage = page.GetImage() ' save image to a PNG file image.Save("E:\DicomImage.png") End Using End Using End Sub
/// <summary> /// Returns DICOM image with overlay objects and saves it to a PNG file. /// </summary> /// <param name="filePath">Path to DICOM file.</param> /// <param name="pageIndex">Index of DICOM page.</param> public void GetAndSaveDicomImageWithOverlays(string filePath, int pageIndex) { // open DICOM file using (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile dicomFile = new Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath)) { // get DICOM page Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame frame = (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame)dicomFile.Pages[pageIndex]; // return DICOM image with overlay objects using (Vintasoft.Imaging.VintasoftImage image = frame.GetImage(null, true, null)) { // save image to a PNG file image.Save(@"E:\DicomImage.png"); } } }
''' <summary> ''' Returns DICOM image with overlay objects and saves it to a PNG file. ''' </summary> ''' <param name="filePath">Path to DICOM file.</param> ''' <param name="pageIndex">Index of DICOM page.</param> Public Sub GetAndSaveDicomImageWithOverlays(filePath As String, pageIndex As Integer) ' open DICOM file Using dicomFile As New Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath) ' get DICOM page Dim frame As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame = DirectCast(dicomFile.Pages(pageIndex), Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame) ' return DICOM image with overlay objects Using image As Vintasoft.Imaging.VintasoftImage = frame.GetImage(Nothing, True, Nothing) ' save image to a PNG file image.Save("E:\DicomImage.png") End Using End Using End Sub
/// <summary> /// Returns raw DICOM image, applies a VOI LUT to the DICOM image, /// draws the overlay objects to the DICOM image, saves DICOM image to a PNG file. /// </summary> /// <param name="filePath">Path to DICOM file.</param> /// <param name="pageIndex">Index of DICOM page.</param> public void GetAndSaveDicomImageWithOverlaysAndAdjustImageWindow(string filePath, int pageIndex) { // open DICOM file using (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile dicomFile = new Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath)) { // get DICOM page Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame frame = (Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame)dicomFile.Pages[pageIndex]; // get raw DICOM image // create settings for decoding DICOM image Vintasoft.Imaging.Codecs.Decoders.DicomDecodingSettings decodingSettings = new Vintasoft.Imaging.Codecs.Decoders.DicomDecodingSettings(); // specify that Modality LUT should not be applied to a DICOM image decodingSettings.ApplyModalityLut = false; // specify that VOI LUT should not be applied to a DICOM image decodingSettings.ApplyValueOfInterestLut = false; // specify that overlay objects should not be drawn on DICOM image decodingSettings.ShowOverlayImages = false; // get raw DICOM image using (Vintasoft.Imaging.VintasoftImage image = frame.GetImage(decodingSettings, null)) { // apply VOI LUT to the DICOM image Vintasoft.Imaging.ImageProcessing.ApplyDicomImageVoiLutCommand applyDicomImageVoiLutCommand = new Vintasoft.Imaging.ImageProcessing.ApplyDicomImageVoiLutCommand(); applyDicomImageVoiLutCommand.VoiLut = new Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomImageVoiLookupTable(128, 50); applyDicomImageVoiLutCommand.ExecuteInPlace(image); // draw overlay objects on DICOM image Vintasoft.Imaging.ImageProcessing.ApplyDicomOverlaysCommand applyDicomOverlaysCommand = new Vintasoft.Imaging.ImageProcessing.ApplyDicomOverlaysCommand(); applyDicomOverlaysCommand.OverlayImages = frame.OverlayImages; applyDicomOverlaysCommand.OverlayColor = new Vintasoft.Imaging.ImageColors.Rgb24Color(180, 180, 180); applyDicomOverlaysCommand.ExecuteInPlace(image); // save image to a PNG file image.Save(@"E:\DicomImage.png"); } } }
''' <summary> ''' Returns raw DICOM image, applies a VOI LUT to the DICOM image, ''' draws the overlay objects to the DICOM image, saves DICOM image to a PNG file. ''' </summary> ''' <param name="filePath">Path to DICOM file.</param> ''' <param name="pageIndex">Index of DICOM page.</param> Public Sub GetAndSaveDicomImageWithOverlaysAndAdjustImageWindow(filePath As String, pageIndex As Integer) ' open DICOM file Using dicomFile As New Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFile(filePath) ' get DICOM page Dim frame As Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame = DirectCast(dicomFile.Pages(pageIndex), Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomFrame) ' get raw DICOM image ' create settings for decoding DICOM image Dim decodingSettings As New Vintasoft.Imaging.Codecs.Decoders.DicomDecodingSettings() ' specify that Modality LUT should not be applied to a DICOM image decodingSettings.ApplyModalityLut = False ' specify that VOI LUT should not be applied to a DICOM image decodingSettings.ApplyValueOfInterestLut = False ' specify that overlay objects should not be drawn on DICOM image decodingSettings.ShowOverlayImages = False ' get raw DICOM image Using image As Vintasoft.Imaging.VintasoftImage = frame.GetImage(decodingSettings, Nothing) ' apply VOI LUT to the DICOM image Dim applyDicomImageVoiLutCommand As New Vintasoft.Imaging.ImageProcessing.ApplyDicomImageVoiLutCommand() applyDicomImageVoiLutCommand.VoiLut = New Vintasoft.Imaging.Codecs.ImageFiles.Dicom.DicomImageVoiLookupTable(128, 50) applyDicomImageVoiLutCommand.ExecuteInPlace(image) ' draw overlay objects on DICOM image Dim applyDicomOverlaysCommand As New Vintasoft.Imaging.ImageProcessing.ApplyDicomOverlaysCommand() applyDicomOverlaysCommand.OverlayImages = frame.OverlayImages applyDicomOverlaysCommand.OverlayColor = New Vintasoft.Imaging.ImageColors.Rgb24Color(180, 180, 180) applyDicomOverlaysCommand.ExecuteInPlace(image) ' save image to a PNG file image.Save("E:\DicomImage.png") End Using End Using End Sub