Using class_dicom.php in Windows

I had the opportunity today to help someone get class_dicom.php working under windows. I was pretty surprised to learn that you do not have to modify the class much, but it does take some time to install the other prerequisite software.

If you’re using IIS, you can skip step #1. You will need to get a copy of PHP installed under IIS. PHP on IIS (http://php.iis.net/) will allow you to do that easily. If you are using IIS, change the file locations below as appropriate for your enviroment.

1. You’ll need a copy of PHP.

Since you’ll probably want to run your PHP scripts under a web server you might as well kill two (three) birds with one stone.  The Wamp (http://www.wampserver.com/)  package is an easy as pie installer that will install and configure Apache, mySQL, PHP, and several other handy tools at once.

Once installed, be sure to find it in the system tray, left click it, and then select Put Online to start it up.

You can then go to http://localhost to test your install out.

The files you’re serving are all under C:\wamp\www\

2. You’ll need the Windows binaries of the DCMTK.

Head on over to the DCMTK website (http://dicom.offis.de/dcmtk.php.en/) and under executable binaries, grab the zip file for Windows.

Unzip it an copy the result to C:\dcmtk so it’s easy to find.

3. Get a copy class_dicom.php.

You can download a zipped version from GitHub (https://github.com/vedicveko/class_dicom.php/zipball/master). Once downloaded unzip it to C:\wamp\www\class_dicom.

You should be able to visit your web server at http://localhost/class_dicom and see a directory listing.

We’re going to need to make some modifications to the class. Open C:/wamp/www/class_dicom/class_dicom.php in an editor.

Near the top of a file is a line that looks like this:

define('TOOLKIT_DIR', '/usr/local/bin');

We need to change that to point to where we installed DCMTK. Change the line to look like this:

define('TOOLKIT_DIR', 'C:/dcmtk/bin');

Save class_dicom.php and you’re done with it.

4. Finishing up

All of the scripts in the examples directory for class_dicom.php are meant to run on the UNIX command line. This won’t work out too well when you try to run them under a web server on Windows. We need to change up one of the examples to run in this environment so you can see that it works. Take the code below and copy it into the C:\wamp\www\class_dicom\examples\get_tags.php file.

<?PHP
#
# Prints out the DICOM tags in a file specified on the command line
#

require_once('../class_dicom.php');

$file = 'dean.dcm';

if(!file_exists($file)) {
  print "$file: does not exist\n";
  exit;
}

$d = new dicom_tag;
$d->file = $file;
print "TEST: " . $d->load_tags();

print "<pre>";

print_r($d->tags);

$name = $d->get_tag('0010', '0010');
print "Name: $name\n";

?>

Once that is done go to http://localhost/class_dicom/examples/get_tags.php. You’ll see a header dump of the dean.dcm sample DICOM file.

(Or skip all of that and open get_tags_webbased.php in your browser instead.)

You now have a functional install of class_dicom.php to work with!

27 comments

  1. It worked perfectly on dicom files which use jpeg baseline.
    can I convert dicom files which use jpeg2000 to jpeg images?

    1. Hi, you have to modify get_tags.php a bit as outlined in step 4. The line you have a question about is used to get the name of the DICOM file from the command line, which won’t work via the web. If you change the line to:

      $file = ‘dean.dcm’;

      You should see a header dump of dean.dcm.

  2. Sir,
    Can please provide some sites containing dicom image set which use jpeg baseline.so that I can use this library only.

  3. sir,
    can u please provide some urls containing PACS which is done in php.I would like to implement Client side PACS,so that i want to view dicom files in browser.
    Sir,is it possible to view dicom files as it in browser ?? Or before viewing we need to convert to jpg??

    1. I don’t know of any PACS systems you can download that are completely written in PHP. You are correct that browsers cannot open a DICOM file, to do so you would need to convert them to another format such as JPEG first. It is possible to write flash or perhaps even HTML 5 apps that can read and display DICOM doing so would allow you to display a DICOM file in the browser.

  4. sir,

    In the examples, when store_server.php received a dcm file, the event script of store_server_handler.php cannot be executed. And store_server.php gave the following messages:
    E: cannot execute command ‘./store_server_handler.php ./dcm_temp NM.1.3.12.2.1107.5.6.1.7101.15307.0.1033631623863142.dcm “nmwork” “DEANO”‘
    There was nothing changed in file of the store_server.log.
    where is the problem going? Thank you!

    1. Hello,

      Sounds like store_server.php can’t find store_server_handler.php and/or run it. When you run store_server.php are you in the same directory as the script? Is your PHP installed in such a way that you can PHP scripts from the command line or via a double click in Explorer?

  5. Hi!
    I followed up all your instructions about changing code if I want to run from Windows based webserver in get_tags.php, but it displays only white page, without any tags

    file = $file;
    print “TEST: ” . $d->load_tags();

    print “”;

    print_r($d->tags);

    $name = $d->get_tag(‘0010’, ‘0010’);
    print “Name: $name\n”;

    ?>

    1. What is the output of get_tags.php when you run it from the command line?

      My thoughts are there is something going on with the PHP parser or maybe a parse error due to line feeds. Either way running it from the command line will get you some good information.

  6. Nice tutorial.. I am getting those line of output(when i am running http://localhost/class_dicom/examples/get_tags_webbased.php) ..but how to convert this output to image…and other thing is how to run this code on remote server..specially ( 2. You’ll need the Windows binaries of the DCMTK.) because we cant tell user that download this zip file and install…

    Array
    (
    [0002,0000] => 210
    [0002,0001] => 00\01
    [0002,0002] => ComputedRadiographyImageStorage
    [0002,0003] => 1.2.826.0.1.3680043.2.1074.90089.1.71.10001008.1
    [0002,0010] => JPEGBaseline
    [0002,0012] => 1.2.276.0.7230010.3.0.3.5.5
    [0002,0013] => OFFIS_DCMTK_355
    [0002,0016] => SXR_DEMO
    [0008,0016] => ComputedRadiographyImageStorage
    [0008,0018] => 1.2.826.0.1.3680043.2.1074.90089.1.71.10001008.1
    [0008,0020] => 20110310
    [0008,0030] => 104637
    [0008,0050] => demofry80666
    [0008,0060] => CR
    [0008,0064] => DI
    [0008,0070] => iCRco, Inc.
    [0008,0080] => DEANLAND, AR
    [0008,0090] =>
    [0008,1010] => SXR
    [0008,1030] =>
    [0008,1090] => CR1
    [0010,0010] => VAUGHAN^DEAN
    [0010,0020] => 345345
    [0010,0030] => 19800301
    [0010,0040] => M
    [0018,0015] =>
    [0018,1004] => 123
    [0018,1164] => 0.357750\0.357750
    [0018,1400] => [APO:(0,-1,-1)]~
    [0018,5101] => Invalid
    [0020,000d] => 1.2.826.0.1.3680043.2.1074.90089.10003.100.19318.3121114637
    [0020,000e] => 1.2.826.0.1.3680043.2.1074.90089.10003100.19318.1
    [0020,0010] => 10003100
    [0020,0011] => 1001
    [0020,0013] => 1
    [0020,0020] =>
    [0028,0002] => 1
    [0028,0004] => MONOCHROME2
    [0028,0010] => 2008
    [0028,0011] => 2444
    [0028,0034] => 1\1
    [0028,0100] => 8
    [0028,0101] => 8
    [0028,0102] => 7
    [0028,0103] => 0
    [0028,1050] => 128.000000
    [0028,1051] => 252.000000
    [0028,2110] => 01
    [0038,0500] => HI
    [7fe0,0010] => 2)
    )
    Name: VAUGHAN^DEAN

  7. Hi Dean. Great tutorial! However, I tried using this script onto another DCM file and for the most part I’m getting the tag values, except for two parameter tags for which the result shows “[0020,4000] => (not loaded)”. What could be the reason ??

Leave a Reply

Your email address will not be published. Required fields are marked *