Use Case
| • | You want to overlay a 1-bit bitmap overlay on the image in a manner that conforms to DICOM Part 3.3, Section C.9.2. |
Relevant Architecture
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/AddBitmapOverlayTool", "Apply")]
[IconSet("apply", IconScheme.Colour, "Icons.MyToolSmall.png", "Icons.MyToolMedium.png", "Icons.MyToolLarge.png")]
// ... (other action attributes here)
[ExtensionOf(typeof (ImageViewerToolExtensionPoint))]
public class AddBitmapOverlayTool : 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(0, 0);
overlayPlane.Color = Color.PeachPuff;
// Iterate through each pixel of the base image and if the pixel value
// is above a certain threshold, flag the pixel in the overlay accordingly
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 on the "LAYER1" layer
dicomGraphicsPlane.UserOverlays.ActivateAsLayer(overlayPlane, "LAYER1");
// Now render
image.Draw();
}
}
}
Remarks
A common use for a DICOM overlay is when you want to markup notable features on an underlying image. For example, if you are writing a computer aided diagnosis tool and you want to indicate the presence of a tumour in a different colour, adding a DICOM overlay is what you need.
In the sample above, the tool tests to see if a pixel in the underlying image is above a certain threshold. If it is, that pixel in the overlay is made opaque. All other 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 regular overlay on the "LAYER1" layer (as opposed to being activated as a bitmap display shutter). When all the elements of the scene graph are combined and rendered, the pixels which are above the threshold will appear in the selected overlay 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 |