Navigation:  I Want To... > DICOM Imaging >

Add a DICOM bitmap display shutter

Previous pageReturn to chapter overviewNext page

Use Case

You want to add an arbitrarily-shaped display shutter on the image in a manner that conforms to DICOM Part 3.3, Section C.7.6.15.

Relevant Architecture

Image graphics
DICOM presentation state

Relevant Types

IDicomPresentationImage
DicomGraphicsPlane
UserOverlayPlaneGraphic

Sample Code

using System.Drawing;

using ClearCanvas.Common;

using ClearCanvas.Desktop;

using ClearCanvas.Desktop.Actions;

using ClearCanvas.ImageViewer;

using ClearCanvas.ImageViewer.BaseTools;

using ClearCanvas.ImageViewer.Graphics;

using ClearCanvas.ImageViewer.PresentationStates.Dicom;

 

// ... (other using namespace statements here)

 

namespace MyPlugin.DicomImaging

{

   [ButtonAction("apply""global-toolbars/ToolbarStandard/AddBitmapShutterTool""Apply")]

   [IconSet("apply", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   // ... (other action attributes here)

   [ExtensionOf(typeof (ImageViewerToolExtensionPoint))]

   public class AddBitmapShutterTool : ImageViewerTool

   {

      private readonly int _threshold = 1200// Chosen to perform best on CT images.

 

      public void Apply()

      {

         IDicomPresentationImage image = this.SelectedPresentationImage as IDicomPresentationImage;

 

         if (image == null)

            return;

 

         // Get the base image

         ImageGraphic baseImage = image.ImageGraphic;

 

         // Get the DICOM graphics plane

         DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);

 

         // Create a custom DICOM overlay plane graphic

         UserOverlayPlaneGraphic overlayPlane = new UserOverlayPlaneGraphic(baseImage.Rows, baseImage.Columns);

         overlayPlane.Label = "OverThreshold";

         overlayPlane.Description = string.Format("Pixels over {0}", _threshold);

         overlayPlane.Origin = new PointF(00);

         overlayPlane.Color = Color.Black;

         overlayPlane.Type = OverlayPlaneType.ROI;

 

         // Iterate through each pixel of the base image and if the pixel value

         // is below a certain threshold, shutter out the pixel

         // (in the context of a bitmap display shutter, a true pixel in the overlay means shuttered)

         baseImage.PixelData.ForEachPixel(

            delegate(int i, int x, int y, int pixelIndex)

               {

                  if (baseImage.PixelData.GetPixel(pixelIndex) < _threshold)

                     overlayPlane[x, y] = true;

               }

            );

 

         // Add the overlay to the collection of available overlays on the image

         dicomGraphicsPlane.UserOverlays.Add(overlayPlane);

 

         // Activate the overlay as a bitmap display shutter

         dicomGraphicsPlane.UserOverlays.ActivateAsShutter(overlayPlane);

 

         // Now render

         image.Draw();

      }

   }

}

Remarks

DICOM display shutters are masks applied on the image at presentation for the purposes of suppressing certain pixels from being displayed without irreversibly modifying the image's pixel data.  The shutters can be defined as a combination of geometric shapes or as an arbitrary bitmap.

In the sample above, the tool tests to see if a pixel in the underlying image is below a certain threshold. If it is, then that pixel in the overlay is shuttered.  Any unshuttered pixels in the overlay are transparent.  The DICOM overlay is then added to the DICOM graphics plane of the presentation image and activated as a shutter (as opposed to a regular overlay). When all the elements of the scene graph are composited and rendered, the pixels which are below the threshold will appear in the shutter colour, whereas all other pixels will appear normally.

Please note that the hard-coded threshold value in the sample was chosen to perform best on CT images.

Examples in Code Base

None currently