←Select platform

GetImages(DicomElement,int,int,int,RasterByteOrder,DicomGetImageFlags) Method

Summary
Gets the images of a Pixel Data element.
Syntax
C#
C++/CLI
Java
public RasterImage getImages(DicomElement element, int index, int count, int bitsPerPixel, int order, DicomGetImageFlags flags) 

Parameters

element
An item in the Data Set.

index
The zero-based index of the first frame to load.

count
Value that represents the number of frames to load.

bitsPerPixel
Value that represents the resulting image pixel depth. Possible values are:

Value Meaning
0 Keep the original file's pixel depth (do not convert).
1 to 8 Use the specified bits per pixel in the resulting image.
12 Use 12 bits per pixel in the resulting image.
16 Use 16 bits per pixel in the resulting image.
24 Use 24 bits per pixel in the resulting image.
32 Use 32 bits per pixel in the resulting image.

order
This value is ignored.

flags
Flags that control the behavior of this method.

Return Value

The images of a Pixel Data element.

Remarks

As an example, if you wish to load 50 images starting with the 50th frame in the Pixel Data, call this method with index set to 49 (the 50th frame in a zero-based index) and count set to 50. If element is null, you can retrieve all images within the Data Set. To do this you must call GetImageCount with the element parameter set to null to determine the number of images in the Data Set and then set the count parameter in GetImages to this value.

If DicomGetImageFlags.AllowRangeExpansion is set in [flags](" id="flagsparameterlink" class="popuplink.html), 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) cannot 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.

If the DICOM dataset has a Multi-frame Functional Groups module, some VOI LUT information will be read from the corresponding Frame VOI LUT Sequence, and some Modality LUT information will be read from the corresponding Pixel Value Transformation Sequence. The specific elements that are read are shown below: (0028,9132) Frame VOI LUT Sequence Child Elements

Tag Name
(0028,1050) Window Center
(0028,1051) Window Width
(0028,1055) Window Center & Width Explanation

(0028,9145) Pixel Value Transformation Sequence child elements

Tag Name
(0028,1052) Rescale Intercept
(0028,1053) Rescale Slope
(0028,1054) Rescale Type

For a detailed discussion on Multi-frame Functional Groups refer to the topic Multi-frame Functional Groups.

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public void TestDicomImage() 
{ 
   string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image3.dcm"); 
   //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, DicomTag.PixelData, true); 
      if (pixelDataElement == null) 
      { 
         Console.WriteLine("This dataset is missing the pixel data element", "Sample"); 
         return; 
      } 
 
      if (ds.GetImageCount(pixelDataElement) == 0) 
      { 
         Console.WriteLine("Sample: This dataset has no images"); 
         return; 
      } 
 
      DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0); 
      if (imageInformation == null) 
      { 
         Console.WriteLine("Sample: Can't retrieve image information"); 
         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) 
      { 
         Console.WriteLine("Sample: Can't retrieve image"); 
         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, DicomTag.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.DeleteElement(pixelDataElement1); 
            pixelDataElement1 = ds1.InsertElement(null, false, DicomTag.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(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "Test.dcm"), DicomDataSetSaveFlags.None); 
 
         } 
      } 
      //Load DICOM File 
      ds.Load(dicomFileName, DicomDataSetLoadFlags.None); 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.1.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Dicom Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.