ezDICOM ActiveX viewer

Contents

Introduction

Medical images are often distributed in DICOM format. DICOM is the industry standard for medical images - CTs, MRI and ultrasound images are often saved in DICOM format. These components allow you to easily add DICOM support to many applications. My DICOM component is available for Windows and Linux computers. The Windows ActiveX component can be used with VisualBasic, C, Delphi, Internet Explorer, Word, or any other ActiveX-supporting application/compiler. The component displays most medical images files (automatically recognizing DICOM, NEMA, Siemens, GE, Picker, Elscint and many other formats). In addition to viewing DICOM images, this component also recognizes many proprietary scanner formats (e.g. Siemens, Philips, GE, etc).

You can set published properties from the compiler. In this example, the DCMfilename property has been set. Note that the DICOM component interactively displays the named image. You can also read or write properties with your code. In pascal, the call

DCMclx1.DCMfilename := 'c:\test.mr';

would also load an image. To read a property at runtime is equally straightforward:

StringVariable := DCMfilename;

Note that the latest versions of the ActiveX component can also display the DICOM header information (as shown on the right). This allows users to examine the scan protocol.

Properties

Properties can be changed in the compiler or when the program is running. You can both read from or write to any property. This table lists the published properties:

Properties    
Name: Type Default Comments
DCMbestfitzoom : wordbool false [ActiveX Only] Image size is scaled to match the size of the components window.
DCMcolorScheme : integer 1 Color range used to display intensity: 1= black and white, 2 = hot metal, -1 = inverted black and white, -2 = inverted hot metal
DCMfilename : widestring   Name of DICOM image opened. Assign to open an image. Note: when you write this value with "DCMloadmultiplefiles" set to true, the first image in the stack will be displayed (even if it is not the specified filename).
DCMloadmultiplefiles : wordbool false When this is set to false, only one image is loaded at a time (either a single 2D slice or a 3D volume, depending on the file). When this is set to true, and the target filename is a 2D slice, all images in the target folder that share the same dimensions will be opened as a single stacked 3D file. This allows you to see mosaics and reconstruct 3D images from 2D slices.
DCMoverlayColor : integer 0 Color of text overlay. 1= black, otherwise white.No effect when DCMoverlayOn is set to false.
DCMoverlayOn : wordbool true When set to true, text about the image size, patient ID, contrast, etc are displayed on the image in the DCMoverlayColor.
DCMslice : integer 1 Slice of 3D image displayed.
DCMshowHeader: boolean false Display or hide contents of DICOM header (e.g. Patient name, scan protocol details).
DCMsmoothOn : wordbool false Uses a bilinear smoothing algorithm which makes images look less jaggy. Smoothing is somewhat slow.
DCMtool : integer 1 Tool selected when the user clicks on the image.
  • 1: Contrast: mouse movememnts change the contrast and brightness.
  • 2: AreaContrast: the user can select a rectangle and the contrast will be adjusted to suit this region.
  • 3: Magnify: the user will see the selected region of the image enlarged.
  • 4: Pan [ActiveX Only] : if the image picture is larger than the client size, the user can drag the mouse to adjust the scroll bars.
  • 5: Line. The user can draw a line on the ROI, with the length (in mm) displayed.
DCMtoolbar : wordbool true Display a simple toolbar with basic buttons to allow the user to open and manipulate images.
DCMuseRecommendedContrast: woordbool true If set to true: when images are initially loaded, set the contrast and brightness of the image using the DCMrecWinCenter and DCMrecWinWidth values from the header of the DICOM file [as described below]. If this value is set to false, the contrast of the image will be evenly scaled between the brightest and darkest pixels in the image.
DCMwinCenter : double   The window center [brightness] of the image.
DCMwinWidth : double   The window width [contrast] of the image.
DCMzoomPct : integer 100 Adjust the scale of the displayed image. E.G. 150 would mean that the image is shown at 150% its native resolution. Note that writing to this function is ignored when DCMbestfitzoom is set to true.
DCMmosaicCols: integer 1 Number of columns in a mosaic (when writing: a mosaic is displayed with DCMmosaicCol*DCMmosaicRows images, with the top left image being DCMmosaicFirstSlice and the bottom right image being DCMmosaicLastSlice). Typically, you change this value immediately after changing the 3 other DCMmosaic values.
DCMmosaicFirstSlice: integer 1 Index of the first slice in the current mosaic. E.G. if this is "4", then the upper left image in the mosaic is the 4th slice (when writing: changes not implemented until next DCMmosaicCols call).
DCMmosaicLastSlice:integer 1 Index of the final slice in the current mosaic. E.G. if this is "16", then the bottom right image in the mosaic is the 16th slice (when writing: changes not implemented until next DCMmosaicCols call).
DCMmosaicRows:integer 1 Number of rows and columns in a mosaic (when writing: changes not implemented until next DCMmosaicCols call).

Functions

Unlike published properties, the following functions can only be called at runtime. These functions include a number of utilities that are usually less commonly used than the published proprties. Unless noted, the properties are read only (you can query the value, but you can not change the value).

Function Comments
DCMimageSlices: Integer Number of slices in the current image. 2D images have only a single slice, whereas 3D volumes have multiple slices.
DCMimageWid: Integer Horizontal width of the image (pixels).
DCMimageHt: Integer Vertical height of the image (pixels).
DCMlinemm: Double Reports the lenght of a line drawn by a user who has selected the 'line' drawing tool.
DCMintercept: Double Recommended intensity intercept (brightness)
DCMslope: Double Recomended intensity slope (contrast)
DCMmmHt: Double Reports the distance between voxels in the X dimension (width).
DCMmmSlices: Double Reports the interslice distance (Z dimension).
DCMmmWid: Double Reports the distance between voxels in the Y dimension (height).
DCMversionInfo: string Version of ezDICOM ActiveX component
DCMmosaicX (Row, Col, FirstSlice, LastSlice: Integer) [write only] Creates a mosaic that is Row images high, Col images wide, where the upper left image is first slice and the bottom right image is the LastSlice. If LastSlice is larger than the number of slices in an image, the last slice will be equal to the number of slices. For example, calling Set_DCMmosaicX(2,2,1,32000) with an image of 16 slices will create a 2x2 mosaic showing the 1st, 6th, 11th and 16th slices.
DCMrecWinCenter: Integer Reports window center (brightness)
DCMrecWinWidth: Integer Reports window width (contrast)
DCMsavetofile(lFilename: WideString) [write only] Saves the currently viewed image to disk. The extention of the filename specifies the image format. For the ActiveX component, images can be saved to JPG or BMP format. With the CLX component, images can be saved as BMP, PNG or JPG format.
DCMsliceMaxBright: Integer Reports the intensity of the brightest voxel on a slice.
DCMsliceMinBright: Integer Reports the intensity of the darkest voxel on a slice.
DCMslope: Double Recommended intensity slope (contrast)
DCMcopyImage2Clipboard Copy current image to the clipboard so it can be copied elsewhere.
DCMcopyHeader2Clipboard Copy text from the DICOM header to the clipboard so it can be copied elsewhere. Each element is saved on a separate line, and names and values are separated with the '=' symbol.
DCMwriteHeader2Text (const DICOMinput,TEXToutput: WideString) [write only] Writes the contents of the DICOM header to a text file. The inputs are the name of the DICOM file and the requested name for the text file. The group/element/values are separated by the '|' [pipe] symbol. Note that this text will typically exceed 255 characters, and indeed might exceed 65,535 characters.
DCMwriteHeader2String (const DICOMinput: WideString); [write only] Loads the requested file and places text output into the Windows clipboard.

Events

Optionally, you can design your program to respond to events generated by the component.

Event Comments
DCMMouseDown (ASender: TObject; X, Y, Button, Shift: Integer); Event generated when the user clicks on an image. X and Y report the mouse position.
DCMMouseMove(ASender: TObject; X, Y, Button,Shift: Integer); Generated when the mouse moves over the image. X and Y report the mouse position.
DCMmouseMoveIntensity(ASender: TObject; X, Y, Button, Shift, Intensity: Integer; RGB: WordBool); Generated when the mouse moves. X and Y report the mouse position, with Intensity reporting the image intensity beneath the mouse cursor. RGB is set to true if the intensity value is a 24-bit red, green blue value.
DCMmouseUp(ASender: TObject; X, Y, Button,Shift: Integer) This event signals that the user has released the mouse button (ending a click or drag over the image).

Perhaps the trickiest (but also most useful) features of my component is the ability to view multiple 2D files as if they were a single 3D image. DICOM files are either saved as 2D slices or as 3D volumes. My component automatically detects the format. A 3D file is always identified as such. However, when encountering a 2D file, the programs behavior depends on the property DCMloadmultiplefiles. If this property is true, the component will search for other DICOM files that have the same image dimension and are in the same folder. It will then organize these files based on their slice order and present the display the first image in the stack. Consider the example illustrated on the right of the figure below, calling DCMfilename := 'a23.dcm'. If DCMloadmultiplefiles is set to false, the individual will be shown a23.dcm. However, if DCMloadmultiplefiles is set to true, the software will load the entire stack a11.dcm-a31.dcm and display the first image (a11.dcm).

Downloading

I provide both the source code and the compiled components so that you can modify and adapt this code. I think this is a pretty mature, standalone component, so I suspect far more people will want to use the component rather than modify it. If you make any significant improvements, you may wish to send them to me so I can include your changes into the standard distribution. Please note that you should take full responsibility and liability for both the compiled components as well as the source code. This project is provided on an 'as is' basis. While I am happy to try to help people, please understand that I am a full time research scientist and university lecturer, and I may not be able to respond to all of your questions (though I try my best).

Shift+click here to download the compiled component and source code (release 1, rev 19). The AcitveX component comes precompiled, so you can immediately start using it with VisualBasic, Csharp, VisualC, InternetExplorer, Delphi or any other ActiveX aware software. If you do wish to modify the code, you will require Delphi for windows compiler (personal version is free). The CLX component's source code can be modified or used with Delphi or (if you are using Linux) the Kylix compiler for Linux (open edition is free).

logo