←Select platform

GetOverlayImage Method

Summary
Retrieves the "Overlay Data" (60xx,3000) for the specified overlay index.
Syntax
C#
C++/CLI
Java
public RasterImage GetOverlayImage( 
   int index 
) 
public RasterImage getOverlayImage(int index) 
public: 
RasterImage^ GetOverlayImage(  
   int index 
)  

Parameters

index
The zero-based index of the overlay whose image is required.

Return Value

Image filled with the overlay data.

Remarks

This method will extract the "Overlay Data" (60xx,3000) for an overlay, initialize the returned image based on the "Overlay Columns" (60xx,0011) and "Overlay Rows" (60xx,0010), and then fill the image with the stream of bytes under the "Overlay Data" (60xx,3000) element. If the method does not find the "Overlay Data" element inside the Data Set it will throw an DicomExceptionCode.OverlayDataMissing exception.

Before calling this method you must call GetOverlayAttributes to determine if the overlay pixel data is embedded in the "Image Pixel Data" (7FE0,0010) element or is under the "Overlay Data" (60xx,3000) element. If the overlay data is embedded in the "Image Pixel Data", UseBitPlane will be set to true in the attributes returned by GetOverlayAttributes.

If the overlay pixel data is embedded in the "Image Pixel Data" (7FE0, 0010), follow these steps to get the overlay data:

  1. Call one of the methods which can be used to extract the "Image Pixel Data", such as GetImage. This will return a raster image populated with the "Image Pixel Data" with the overlay data embedded. For this example, assume that the raster image returned by this method is called mainImage.
  2. Call GetOverlayAttributes to get the attributes of the overlay. For this example, assume that the overlay attributes returned by this method is called overlayAttributes.
  3. Now we need to add our overlay as one of the overlays associated with mainImage. To do that, we need to call SetOverlayAttributes:

    mainImage.UpdateOverlayAttributes(0, overlayAttributes, RasterGetSetOverlayAttributesFlags.Flags | RasterGetSetOverlayAttributesFlags.BitIndex | RasterGetSetOverlayAttributesFlags.Origin | RasterGetSetOverlayAttributesFlags.Dicom | RasterGetSetOverlayAttributesFlags.Color);

    We are assuming that this is the first overlay in the image; this is why we are passing 0 as the overlay index.

  4. Now we need to extract the overlay data from the main image data:

    mainImage.UpdateOverlayBits(0, RasterUpdateOverlayBitsFlags.FromImage);
  5. Now call mainImage.GetOverlayImage to get the overlay data itself as a raster image.

Example
C#
using Leadtools; 
using Leadtools.Dicom; 
 
 
public void TestOverlay() 
{ 
   string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "Overlay.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); 
 
      if (ds.OverlayCount > 0) 
      { 
         RasterOverlayAttributes attributes = ds.GetOverlayAttributes(0); 
         if (attributes != null) 
         { 
            // We can call in here methods like GetOverlayGroupNumber, IsOverlayInDataset  
            // and GetOverlayActivationLayer to get some further infromation about the overlay 
 
            //Let's get the overlay Image, If RasterOverlayAttributes.NumFramesInOverlay  
            //Is greater than 1 we can call GetOverlayImages to extract all the frames 
            RasterImage overlayImage = ds.GetOverlayImage(0); 
            if (overlayImage != null) 
            { 
               using (DicomDataSet ds1 = new DicomDataSet()) 
               { 
                  ds1.Initialize(DicomClassType.DXImageStoragePresentation, DicomDataSetInitializeType.ExplicitVRLittleEndian); 
                  ds1.SetOverlayAttributes(0, attributes, DicomSetOverlayFlags.None); 
                  ds1.SetOverlayImage(0, overlayImage);//We can call SetOverlayImages if the overlay has more than one frame 
                  ds1.Save(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "NewOverlay.dcm"), DicomDataSetSaveFlags.None); 
               } 
            } 
         } 
      } 
   } 
   DicomEngine.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

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