Home » File Formats » File_DICOM » Manual
Package for reading and modifying DICOM files
Introduction
Introduction – using File_DICOM
What is DICOM?
File_DICOM allows reading and modifying of DICOM files. DICOM stands for Digital Imaging and COmmunications in Medicine, and is a standard for creating, storing and transfering digital images (X-rays, tomography) and related information used in medicine. This package in particular does not support the exchange/transfer of DICOM data, nor any network related functionality. More information on the DICOM standard can be found at the NEMA site.
Please be aware that any use of the information produced by this package for diagnosing purposes is strongly discouraged by the author. See here for more information.
Using it
File_DICOM can be used to accomplish two things, to retrieve data from a file (including image data), and to set new values for that data (allowing to write the modified file).
Let's see how we could show some relevant data from a DICOM file and export its image data at the same time.
Showing data
<?php
require_once('File/DICOM.php');
$dicom = new File_DICOM();
$res = $dicom->parse("test.dcm");
// check for errors
if (PEAR::isError($res)) {
die("Error: ".$res->getMessage()."\n");
}
// show a few attributes of the DICOM file using group and element index
echo 'StudyDate : '.$dicom->getValue(0x0008, 0x0020)."\n";
echo 'Image Date : '.$dicom->getValue(0x0008, 0x0023)."\n";
echo 'Image Type : '.$dicom->getValue(0x0008, 0x0008)."\n";
echo 'Study Time : '.$dicom->getValue(0x0008, 0x0030)."\n";
echo 'Institution Name : '.$dicom->getValue(0x0008, 0x0080)."\n";
echo 'Manufacturer : '.$dicom->getValue(0x0008, 0x0070)."\n";
echo 'Manufacturer Model Name : '.$dicom->getValue(0x0008, 0x1090)."\n";
// or using element name
echo 'Patient Name : '.$dicom->getValue('PatientName')."\n";
echo 'Patient Age : '.$dicom->getValue('PatientAge')."\n";
// dump a PGM image from the file data
$res = $dicom->dumpImage('test.pgm');
if (PEAR::isError($res)) {
die("Error: ".$res->getMessage()."\n");
}
?>
constructor File_DICOM::File_DICOM
constructor File_DICOM::File_DICOM() – Constructor.
Synopsis
require_once 'File/DICOM.php';
void constructor File_DICOM::File_DICOM (
)
Description
It creates a File_DICOM object.
Note
This function can not be called statically.
File_DICOM::parse
File_DICOM::parse() – Parse a DICOM file.
Synopsis
require_once 'File/DICOM.php';
mixed File_DICOM::parse (
string $infile
)
Description
Parse a DICOM file and get all of its header members.
Parameter
-
string
$infile -
The DICOM file to parse
Return value
returns true on success, PEAR_Error on failure
Note
This function can not be called statically.
File_DICOM::write
File_DICOM::write() – Write current contents to a DICOM file.
Synopsis
require_once 'File/DICOM.php';
mixed File_DICOM::write (
string $outfile = ''
)
Description
This package is not documented yet.
Parameter
-
string
$outfile -
The name of the file to write. If not given it assumes the name of the file parsed. If no file was parsed and no name is given returns a PEAR_Error
Return value
returns true on success, PEAR_Error on failure
Note
This function can not be called statically.
File_DICOM::getValue
File_DICOM::getValue() – Gets the value for a DICOM element.
Synopsis
require_once 'File/DICOM.php';
mixed File_DICOM::getValue (
mixed $group_or_name
, integer $element = null
)
Description
Gets the value for a DICOM element of a given group from the parsed DICOM file
Parameter
-
mixed
$group_or_name -
The group the DICOM element belongs to (integer), or its name (string)
-
integer
$element -
The identifier for the DICOM element (unique inside a group). Optional
Return value
returns The value for the DICOM element on success, PEAR_Error on failure
Note
This function can not be called statically.
Example
Using getValue()
<?php
require_once('File/DICOM.php');
$dicom_file = new File_DICOM();
$res = $dicom_file->parse('test.dcm');
// check for errors
if (PEAR::isError($res)) {
die($res->getMessage());
}
echo 'this value: '.$dicom_file->getValue('PatientName')."\n";
echo 'Should be the same as this value: '.$dicom_file->getValue(0x0010, 0x0010)."\n";
?>
File_DICOM::setValue
File_DICOM::setValue() – Sets the value for a DICOM element.
Synopsis
require_once 'File/DICOM.php';
void File_DICOM::setValue (
integer $gp
, integer $el
, mixed $value
)
Description
Sets the value for a DICOM element. Only works with strings now.
Parameter
-
integer
$gp -
The group the DICOM element belongs to
-
integer
$el -
The identifier for the DICOM element (unique inside a group)
-
mixed
$value
Note
This function can not be called statically.
File_DICOM::dumpImage
File_DICOM::dumpImage() – Dumps the contents of the image inside the DICOM file (element 0x0010 from group 0x7FE0) to a PGM (Portable Gray Map) file.
Synopsis
require_once 'File/DICOM.php';
mixed File_DICOM::dumpImage (
string $filename
)
Description
Use with Caution!!. For a 8.5MB DICOM file on a P4 it takes 28 seconds to dump it's image.
Parameter
-
string
$filename -
The file where to save the image
Return value
returns true on success, PEAR_Error on failure.
Note
This function can not be called statically.