Leadtools.Dicom Requires Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.10.31
GetImage Method
See Also  Example
Leadtools.Dicom Namespace > DicomDataSet Class : GetImage Method




element
An item in the Data Set.
index
The zero-based index of the frame to load.
bitsPerPixel
Value that represents the resulting image pixel depth. Possible values are:
ValueMeaning
0Keep the original file's pixel depth (do not convert).
1 to 8The specified bits per pixel in the resultant image.
1212 bits per pixel in the resultant image.
1616 bits per pixel in the resultant image.
2424 bits per pixel in the resultant image.
3232 bits per pixel in the resultant image.
order
The desired color order.
flags
Flags that control the behaviour of this method.
Gets the image of a Pixel Data element.

Syntax

Visual Basic (Declaration) 
Public Function GetImage( _
   ByVal element As DicomElement, _
   ByVal index As Integer, _
   ByVal bitsPerPixel As Integer, _
   ByVal order As RasterByteOrder, _
   ByVal flags As DicomGetImageFlags _
) As RasterImage
Visual Basic (Usage)Copy Code
Dim instance As DicomDataSet
Dim element As DicomElement
Dim index As Integer
Dim bitsPerPixel As Integer
Dim order As RasterByteOrder
Dim flags As DicomGetImageFlags
Dim value As RasterImage
 
value = instance.GetImage(element, index, bitsPerPixel, order, flags)
C# 
public RasterImage GetImage( 
   DicomElement element,
   int index,
   int bitsPerPixel,
   RasterByteOrder order,
   DicomGetImageFlags flags
)
Managed Extensions for C++ 
public: RasterImage GetImage( 
   DicomElement* element,
   int index,
   int bitsPerPixel,
   RasterByteOrder order,
   DicomGetImageFlags flags
) 
C++/CLI 
public:
RasterImage GetImage( 
   DicomElement^ element,
   int index,
   int bitsPerPixel,
   RasterByteOrder order,
   DicomGetImageFlags flags
) 

Parameters

element
An item in the Data Set.
index
The zero-based index of the frame to load.
bitsPerPixel
Value that represents the resulting image pixel depth. Possible values are:
ValueMeaning
0Keep the original file's pixel depth (do not convert).
1 to 8The specified bits per pixel in the resultant image.
1212 bits per pixel in the resultant image.
1616 bits per pixel in the resultant image.
2424 bits per pixel in the resultant image.
3232 bits per pixel in the resultant image.
order
The desired color order.
flags
Flags that control the behaviour of this method.

Return Value

The image of a Pixel Data element.

Example

This example will read a DICOM dataset and do a number of image related operations such as loading and saving.

Visual BasicCopy Code
Public Sub TestDicomImage()
  Dim dicomFileName As String = "C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 14.5\Images\IMAGE3.dic"
  'Make sure to initialize the DICOM engine, this needs to be done only once
  'In the whole application
  DicomEngine.Startup()

  Dim ds As DicomDataSet = New DicomDataSet()
    Using (ds)
       'Load DICOM File
       ds.Load(dicomFileName, DicomDataSetLoadFlags.None)

       Dim pixelDataElement As DicomElement = ds.FindFirstElement(Nothing, DicomTagType.PixelData, True)
       If pixelDataElement Is Nothing Then
          MessageBox.Show("This dataset is missing the pixel data element", "Sample")
          Return
       End If

       If ds.GetImageCount(pixelDataElement) = 0 Then
          MessageBox.Show("This dataset has no images", "Sample")
          Return
       End If

       Dim imageInformation As DicomImageInformation = ds.GetImageInformation(pixelDataElement, 0)
       If imageInformation Is Nothing Then
          MessageBox.Show("Can't retrieve image information", "Sample")
          Return
       End If
       ' Over here we can access the different properties of the DicomImageInformation class to get some
       ' of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated)
       Dim image As RasterImage = ds.GetImage(pixelDataElement, 0, 0, RasterByteOrder.Gray, DicomGetImageFlags.AllowRangeExpansion Or DicomGetImageFlags.AutoApplyModalityLut Or DicomGetImageFlags.AutoApplyVoiLut)

       If image Is Nothing Then
          MessageBox.Show("Can't retrieve image", "Sample")
          Return
       End If

       'If the image has more than one frame then we can call DicomDataSet.GetImages to get all the frames

       Dim ds1 As DicomDataSet = New DicomDataSet()
       Using (ds1)

          ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian)
          Dim pixelDataElement1 As DicomElement = ds1.FindFirstElement(Nothing, DicomTagType.PixelData, True)
          If Not pixelDataElement1 Is Nothing Then
             ds1.SetImage(pixelDataElement1, image, DicomImageCompressionType.None, DicomImagePhotometricInterpretationType.Monochrome2, 16, 2, DicomSetImageFlags.AutoSetVoiLut)
             'If we have more than one frame then we can call DicomDataSet.SetImages

             'This is an alternative way to set the image, I will first delete the
             'existing image and then call DicomDataSet.InsertImage
             ds1.DeleteImage(pixelDataElement1, 0, 1)
             pixelDataElement1 = ds1.InsertElement(Nothing, False, DicomTagType.PixelData, DicomVRType.UN, False, 0)
             ds1.InsertImage(pixelDataElement1, image, 0, DicomImageCompressionType.None, DicomImagePhotometricInterpretationType.Monochrome2, 16, 2, DicomSetImageFlags.AutoSetVoiLut)
             'If we have more than one frame then we can call DicomDataSet.InsertImages

             ds1.Save("C:\\Test.dic", DicomDataSetSaveFlags.None)

          End If
       End Using

       'Load DICOM File
       ds.Load(dicomFileName, DicomDataSetLoadFlags.None)
    End Using

    DicomEngine.Shutdown()
 End Sub
C#Copy Code
public void TestDicomImage() 

   string dicomFileName = @"C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 14.5\Images\IMAGE3.dic"; 
   //Make sure to initialize the DICOM engine, this needs to be done only once  
   //In the whole application 
   DicomEngine.Startup(); 
   using (DicomDataSet ds = new DicomDataSet()) 
   { 
      //Load DICOM File 
      ds.Load(dicomFileName, DicomDataSetLoadFlags.None); 
 
      DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTagType.PixelData, true); 
      if (pixelDataElement == null) 
      { 
         MessageBox.Show("This dataset is missing the pixel data element", "Sample"); 
         return; 
      } 
 
      if(ds.GetImageCount(pixelDataElement) == 0) 
      { 
         MessageBox.Show("This dataset has no images", "Sample"); 
         return; 
      } 
 
      DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0); 
      if (imageInformation == null) 
      { 
         MessageBox.Show("Can't retrieve image information", "Sample"); 
         return; 
      } 
      // Over here we can access the different properties of the DicomImageInformation class to get some 
      // of the image attributes such as bits allocated (DicomImageInformation. BitsAllocated) 
      RasterImage image = ds.GetImage(pixelDataElement, 
         0, 
         0, 
         RasterByteOrder.Gray, 
         DicomGetImageFlags.AllowRangeExpansion | DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut); 
 
      if (image == null) 
      { 
         MessageBox.Show("Can't retrieve image", "Sample"); 
         return; 
      } 
 
      //If the image has more than one frame then we can call DicomDataSet.GetImages to get all the frames 
      using (DicomDataSet ds1 = new DicomDataSet()) 
      { 
         ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian); 
         DicomElement pixelDataElement1 = ds1.FindFirstElement(null, DicomTagType.PixelData, true); 
         if (pixelDataElement1 != null) 
         { 
            ds1.SetImage(pixelDataElement1, 
               image, 
               DicomImageCompressionType.None, 
               DicomImagePhotometricInterpretationType.Monochrome2, 
               16, 
               2, 
               DicomSetImageFlags.AutoSetVoiLut); 
            //If we have more than one frame then we can call DicomDataSet.SetImages 
 
            //This is an alternative way to set the image, I will first delete the 
            //existing image and then call DicomDataSet.InsertImage 
            ds1.DeleteImage(pixelDataElement1, 0, 1); 
            pixelDataElement1 = ds1.InsertElement(null, false, DicomTagType.PixelData, DicomVRType.UN, false, 0); 
            ds1.InsertImage(pixelDataElement1, 
               image, 
               0, 
               DicomImageCompressionType.None, 
               DicomImagePhotometricInterpretationType.Monochrome2, 
               16, 
               2, 
               DicomSetImageFlags.AutoSetVoiLut); 
            //If we have more than one frame then we can call DicomDataSet.InsertImages 
 
            ds1.Save(@"C:\\Test.dic", DicomDataSetSaveFlags.None); 
 
         } 
      } 
      //Load DICOM File 
      ds.Load(dicomFileName, DicomDataSetLoadFlags.None); 
   } 
   DicomEngine.Shutdown(); 
}

Remarks

If element is null, this method will load any image within the file, based on the index parameter.

If DicomGetImageFlags.AllowRangeExpansion is set in flag, consider the following example:

If the Data Set has the following attributes:

Bits allocated 16

Bits stored 12

Pixel Range 0 - +4095

Pixel Representation is unsigned (0)

Photometric Interpretation is MONOCHROME2

Rescale Slope 1

Rescale Intercept -1024

After applying the rescale slope and the intercept:

Output minimum pixel value = (0 * 1 +(-1024)) = -1024

Output maximum pixel value = (4095 * 1 + (-1024)) = 3071

The new pixel value range (–1024 to 3071) can not be represented with the current bits stored (12 bits), which can represent values in the range (–2048 to 2048). In this case the method will change the high bit inside the image object to be 12 instead of 11 (bits stored becomes 13), which can represent values in the range (–8192 to 8191).

Please note that the method will not be able to update the high bit and/or low bit if the number of bits stored was already equal to the number of bits allocated.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Leadtools.Dicom requires a Medical toolkit license and unlock key. For more information, refer to: Raster Pro/Document/Medical Features