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

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, June 4, 2019 2:05:13 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 218

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

Attached is a sample Winforms project that uses the Leadtools.Dicom and Leadtools.MedicalViewer libraries to create a Presentation State file containing a Region of Interest that can be saved and reloaded.

To initialize the Presentation state file, a new DicomDataSet has to be created and the relevant tags from the loaded DICOM file is brought over:

Code:
      void InitPre()
      {
         if (preDs == null)
         {
            preDs = new DicomDataSet();
            preDs.Reset();
            preDs.Initialize(DicomClassType.ColorSoftcopyPresentationState, DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.ExplicitVR);
            preDs.AddPresentationStateImageReference(ds, null, 0);
            preDs.InsertElementAndSetValue(DicomTag.PatientID, ds.GetStringValue(ds.FindFirstElement(null, DicomTag.PatientID, false), 0));
            preDs.InsertElementAndSetValue(DicomTag.SeriesInstanceUID, GenerateNewUid("1.2.840.114257.1.1"));
            preDs.InsertElementAndSetValue(DicomTag.StudyInstanceUID, ds.GetStringValue(ds.FindFirstElement(null, DicomTag.StudyInstanceUID, false), 0));
            preDs.InsertElementAndSetValue(DicomTag.SOPInstanceUID, GenerateNewUid("1.2.840.114257.1.1"));
         }
      }


Once the user adds a Region to the MedicalWebViewer using MedicalViewerActionType of PolygonRegion (or any other shaped region) a 1-bit mask is created and saved into the OverlayImage of the image in the DICOM file.

Code:
void UpdateOverlay(RasterImage overlayImage)
      {
         cell.Image.SetOverlayImage(0, overlayImage, RasterGetSetOverlayImageMode.Copy);

         var attributes = cell.Image.GetOverlayAttributes(0, RasterGetSetOverlayAttributesFlags.Flags | RasterGetSetOverlayAttributesFlags.Origin | RasterGetSetOverlayAttributesFlags.Color | RasterGetSetOverlayAttributesFlags.Dicom);
         attributes.AutoProcess = true;
         attributes.AutoPaint = true;
         attributes.BitsAllocated = 1;
         attributes.Type = "R";
         attributes.Origin = LeadPoint.Create(0, 0);
         attributes.Description = "ROI Overlay";
         attributes.Rows = overlayImage.ImageHeight;
         attributes.Columns = overlayImage.ImageWidth;
         attributes.ImageFrameOrigin = 1;
         attributes.FramesInOverlay = cell.Image.PageCount;

         attributes.Color = new RasterColor(0, 255, 255, 255);

         overlayImage.UpdateOverlayAttributes(0, attributes, RasterGetSetOverlayAttributesFlags.Flags | RasterGetSetOverlayAttributesFlags.Origin | RasterGetSetOverlayAttributesFlags.Color | RasterGetSetOverlayAttributesFlags.Dicom);

         preDs.AddPresentationStateImageReference(ds, null, 0);
         preDs.SetOverlayAttributes(0, attributes, DicomSetOverlayFlags.None);
         preDs.SetOverlayImage(0, overlayImage);
      }


Once the region is set, it is saved to the file:
Code:
  
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.Filter = "Pre | *.pre";
         if (dlg.ShowDialog() == DialogResult.OK)
            preDs.Save(dlg.FileName, DicomDataSetSaveFlags.None);


Then it can be reloaded at a later date by the following:
Code:
         OpenFileDialog dlg = new OpenFileDialog
         {
            Filter = "DICOM Pre Files (*.pre)|*.PRE"
         };
         if (dlg.ShowDialog() == DialogResult.OK)
         {
            InitPre();
            preDs.Load(dlg.FileName, DicomDataSetLoadFlags.None);
            if (preDs.OverlayCount > 0)
            {
               overlayImage = preDs.GetOverlayImage(0);
               cell.Image.AddMaskToRegion(null, overlayImage, RasterRegionCombineMode.Set);
               cell.Invalidate();
            }
         }


File Attachment(s):
RegionOfInterestDemo.zip (13kb) downloaded 62 time(s).
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 

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.167 seconds.