DICOM.pm Introduction
This library uses a simple object model to store the elements of a
DICOM file header. The main class is called DICOM.
An object of this class holds the DICOM dictionary and has the ability
to read a DICOM file, and return the header elements.
A DICOM object holds a number of DICOM_ELEMENT objects in a hash that
is indexed by the group and element codes for that particular
element. For example, the date of a study is stored as the element
StudyDate, in group 0008, element 0020. It is of type DA,
so it is a text field.
Programming
A Perl application based on this library looks something like this:
#! /usr/local/bin/perl -w |
Modify for your Perl interpreter path. |
use lib '/path/to/my/modules'; |
Modify for location of your .pm modules. |
use DICOM; |
Basic class. |
$dicom = DICOM->new(); |
Creates new DICOM object and sets up its dictionary. |
$dicom->fill("filename"); |
Reads in and parses the DICOM file. |
$date = $dicom->element('0008', '0020'); |
Example of retrieving a field value. |
Using the GUI
The DICOM.pm GUI uses the Perl/Tk library, developed by Nick
Ing-Simmons. You can download and install this library from a CPAN
site. Look for a file such as Tk800.023.tar.gz.
Once Perl/Tk is installed, you can add GUI functionality by making a
few changes and additions to the program:
use DICOM_GUI; |
Required if you are to use the GUI. |
$dicom = DICOM_GUI->new(); |
Takes the place of DICOM->new() |
$dicom->loop(); |
Initiates the main event loop in Perl/Tk |
API Reference: class DICOM
new() |
Create a new instance of this class.
|
processOpts(optHash) |
Save and process options. Note that option 'o' will save the file to
disk at this point. Modifications (option 'm') are run first.
optHash: Ref to hash with options:
Key | Value | Description |
s | Sort index | Field to sort by. |
m | New Value | New value for 'value' field. |
o | Output file | File to save to. |
|
fill(infile) |
Fill in this object from the given input file.
infile: Input DICOM file name.
|
write(outfile) |
Write this object as a DICOM file to disk.
outfile: Output DICOM file name.
If omitted, file will be saved to current name.
|
printContents(handle) |
Print a textual representation of the current DICOM file.
handle: Handle to file opened for writing.
If omitted, writes to standard output.
|
contents() |
Return a sorted array of references to element arrays, sorted.
|
setIndex(index) |
Set the field index for element sorting.
index: Ordinal index of the field.
|
getIndex() |
Returns the current sort index.
|
value(grp, elem) |
Returns the value field of the given element, or null if group or
element are invalid. Equivalent to field(grp, elem, 'value').
grp, elem: Decimal indexes.
|
field(grp, elem, fieldname) |
Returns the value of the field of given index in the specified
element.
grp, elem: Decimal indexes.
fieldname: String name of the field.
|
editHeader(editstr) |
Edit header value from string.
editstr: 'gggg,eeee=newvalue' or 'fieldname=newvalue'.
gggg, eeee = grp, elem (in hex)
fieldname = name of field from @dicom_fields.
|
fieldByName(fieldname) |
Returns the group and element numbers (decimal) of the element with
given name.
fieldname: Name to search for.
|
setElementValue(grp, elem, value) |
Set the value field of the given element.
|
|