Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, July 25, 2019 4:40:26 PM(UTC)


Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

Below is a code snippet to show how to load Annotations that are stored in the DICOM format as a presentation state file as LEAD Annotations.

Here are some relevant links to the documentation for classes from the LEADTOOLS Medical SDK that are used in this example:

DicomAnnotationsUtilities Class
GetPresentationStateImageReference Method

Here is the code for loading the DICOM Annotations:
      static void LoadDICOMAnnotations(string filename)
         //load the DICOM File so we can get the SOP Instance UID
         DicomDataSet _ds = new DicomDataSet();
         _ds.Load(filename, DicomDataSetLoadFlags.LoadAndClose);

         //Get the SOP Instance UID
         string imageSopInstanceUid;
         DicomElement pImageElement = _ds.FindFirstElement(null, DicomTag.SOPInstanceUID, false);
         if (null != pImageElement)
            imageSopInstanceUid = _ds.GetStringValue(pImageElement, 0);

            //Once we have the SOP Instance ID, we then get the Annotations from the file
            var annotations = GetAnnotationsFromDICOMFile(imageSopInstanceUid, filename);
            //Do stuff here with the annotations such as render them

static List<AnnContainer> GetAnnotationsFromDICOMFile(string imageSopInstanceUid, string filename)
         //Load the PRE file - for this example we're assuming that the filename is the same as the DCM file, just the extension is different
         string preFilename = Path.ChangeExtension(filename, "pre");

         //Instantiate the DicomAnnotationsUtilities and load the PRE File
         DicomAnnotationsUtilities _dicomAnnotationsUtilities = new DicomAnnotationsUtilities();
         DicomDataSet _curPsDataset = new DicomDataSet();
         _curPsDataset.Load(preFilename, DicomDataSetLoadFlags.LoadAndClose);

         //Get the Presentation State Image Refernece from the PRE file using the SOP Instance UID from the DCM file
         List<AnnContainer> annContainers = new List<AnnContainer>();
         DicomElement pImageElement = _curPsDataset.GetPresentationStateImageReference(imageSopInstanceUid);
         if (null == pImageElement)
            return annContainers;

         //Get all of the Annotations containers contained in the file and add them to a list
         DicomElement graphicAnnSqItem = _curPsDataset.FindFirstGraphicAnnSQItem();
         while (null != graphicAnnSqItem)
            AnnContainer container  = _dicomAnnotationsUtilities.FromDataSetToAnnContainer(_curPsDataset, graphicAnnSqItem);
            if (container != null)

            graphicAnnSqItem = _curPsDataset.FindNextGraphicAnnSQItem(graphicAnnSqItem);

         return annContainers;
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.031 seconds.