LEADTOOLS Support
Medical
Medical SDK Examples
HOW TO: Load Annotations from DICOM File as LEAD Annotations
#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 ClassGetPresentationStateImageReference MethodHere is the code for loading the DICOM Annotations:
Code: 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
}
}
Code: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)
annContainers.Add(container);
graphicAnnSqItem = _curPsDataset.FindNextGraphicAnnSQItem(graphicAnnSqItem);
}
return annContainers;
}
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.
LEADTOOLS Support
Medical
Medical SDK Examples
HOW TO: Load Annotations from DICOM File as LEAD Annotations
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.