Port Dicom files to ROOT
I made a pluging that allows manipulation of images stored in the Dicom
file format in ROOT. Basically, it is an IO (import/export) facility that
reads and stores dicom images.
The software is loadable via git:
git clone http://www-f9.ijs.si/~studen/git/dicom2ROOT.git
Once extracted to a working directory, cd to that directory and run root. The software should compile.
Possible problems
A message saying
Dcmtk unset. Exit ROOT and do
#>export DCMTK=/location/to/installed/dcmtk
appears if DCMTK is not found. If you haven't installed DCMTK yet, this
would be a good time. Go to DCMTK and install following their
instructions. Because I am working on a multiuser machine, I tend to
install software away from the common locations, hence the DCMTK
enviromental variable, which you can also use. The software assumes that
$DCMTK/include
points to location of headers and $DCMTK/lib
to
libraries.
Typical usage
Once the root is open without errors, you should be able to create an object of dicomHeader type:
root[0] dicomHeader hd;
The object can load and store dicom files, so you can do:
root[1] hd.read_dicom_file("fname");
where fname is the path to your dicom file. If you want to see the obtained image, do
root[2] TH2D h2;
root[3] hd.Draw(h2);
root[4] h2.Draw("COL");
Most often than not, the whole image is loaded as a series of slices in a single directory. To get the full set, do:
root[5] dicomList data;
root[6] readDataset("directory",data);
where "directory" is the path to the directory (and not to a particular file). The whole image should then be loaded in a 3D structure, so:
root[7] TH3D h3;
root[8] Draw(data,h3);
accomplishes that. A particular axial or trans-axial slice is then extracted via ROOT's TH3D manipulation routines. For example, getting I-th transaxial projection/slice, you should do:
root[9] h3.GetZaxis()->SetRange(I+1,I+1);
root[10] h3.Project3D("YX")->Draw("COL");
You can also store a particular image by:
root[11] hd.save_dicom_file("fname");
Usually, a subset of the original dicom parameters will be stored. If you require more, let me know and I can add them.
Todo
Just now I think that manipulation of the image in the dicomHeader might be useful, something like:
root[X] hd.Adopt(h2);
where h2 is a TH2D histogram. The actual content
of the stored pixel $p_i$, stored in Uint16
format would be:
$$ p_i=\frac{h_i-O}{S} $$
where O is RescaleOffset
and S RescaleSlope
DICOM parameter. They can
be directly manipulated via hd.rescale_slope
and hd.rescale_offset
parameters, say:
root[X] hd.rescale_slope=19.3;
root[X] hd.rescale_offset=100;
One probably shouldn't change their value between Adopt
and
save_dicom_file
routines.
Using from other projects
This script lets you use Dicom2ROOT from different directories, if you don't want to add files to the Dicom2ROOT directory, say. From your project, you should first execute
root[0] .x loadDicom2ROOT.C
and you should have all functionality of the dicom2ROOT. You should again set shell enviromental variables prior to calling root:
DCMTK=/path/to/dcmtk
DICOM2ROOT=/path/to/dicom2ROOT