Reading DICOM files

Converting a DICOM file to a simulation file

GAMOS is able to read the patient data resulting from a CT scan in DICOM format. The first step is to change the DICOM format into a format readable by GAMOS converting the Hounsfield nubmers into material and density information. To do this you can use the utility at analysis/DICOM, which is based from the Geant4 example examples/extended/medical/DICOM.. We describe here the procedure you have to follow.

The first step is to write a file named Data.dat. This file has the following information:

Each .dcm corresponds to a Z slice. For each file a .g4dcm will be written with the material/density information. The Z slices may be merged at runtime to form a unique patient volume (in this case the different slices have to be contiguous in Z) if you set the enviromental variable DICOM_MERGE_ZSLICES to 1.

The DICOM images pixel values represent CT Hounsfield numbers (related to the electronic density) and they should be converted, first, to a given density and then to a material type. The relation between CT number and density is more or less linear. The file CT2Density.dat contains the calibration curve to convert CT (Hounsfield) number to phy sical density. The example Data.dat provided with the GAMOS distribution contains the assignment of material densities to materials as recommended by the International Commission on Radiation Units and measurements (ICRU) report 46.

In the class DicomDetectorConstruction, it is defined a density interval:

  G4double densityDiff = 0.1;

This means that the voxels of each material will be grouped in density intervals of 0.1 g/cm3 and a new material will be created for each group of voxels.

After filling your data files, you just have to run the executable:


DICOM file format

The DICOM files are converted to a simple text format. You may create your own file with the following format (see e.g. 1.g4dcm):

The same information is also used to fill a file in binary format, that contains the same information as the text format. Its name ends in .g4dcmb, instead of .g4dcm.

Reading a DICOM file in a GAMOS job

To read the file produced by the DICOM utility you should define as your geometry the class

/gamos/geometry GmReadPhantomG4Geometry

if you use the Geant4 text format, or

/gamos/geometry GmReadPhantomG4BinGeometry

if you use the Geant4 binary format

You should have then a file where your phantom is described, whose name is set with the parameter

/gamos/setParam GmReadPhantomGeometry:Phantom:FileName MY_FILENAME

and another file where you describe the rest of your geometry (at least the world volume where the phantom is placed). The name of this file is set with the parameter

/gamos/setParam GmReadPhantomGeometry:FileName MY_FILENAME

In a phantom file, the voxels of the same material may have a different density. GAMOS allows you to group densities in intervals. You have to set true the parameter

/gamos/setParam GmReadPhantomGeometry:RecalculateMaterialDensities 1

and choose the interval width with the parameter

/gamos/setParam GmReadPhantomGeometry:Phantom:DensityStep DENSITY_INTERVAL

so that that the voxels of each material will be grouped in density intervals of DENSITY_INTERVAL and a new material will be created for each group of voxels.

The navigation in the voxels is done using the Geant4 algorithm, G4RegularNavigation, that is the optimal one for regular geometries (see [ 8 ]). The user may select if when a track navigates through contiguous voxels with the same material the frontier between them will be skipped or not, with the parameter

/gamos/setParam GmReadPhantomGeometry:Phantom:SkipEqualMaterials VALUE

that by default takes a value of 1.

For testing purposes, other navigation algorithms may be selected, namely voxel navigation with 1-dimensional optimization (that occupies similar memory as RegularNavigation but is very slow)

/gamos/setParam GmReadPhantomGeometry:Phantom:RegularStructureID 0

or 3-dimensional optimization (that occupies a lot of memory but it is almost as fast as G4RegularNavigation when no equal materials skipping is used)

/gamos/setParam GmReadPhantomGeometry:Phantom:OptimAxis kUndefined

GAMOS is also able to read the EGSnrc/DOSXYZnrc format for DICOM files. Simply use

/gamos/geometry GmReadPhantomEGSGeometry

and the rest of parameters are the same as for the Geant4 DICOM files.

By default every phantom is placed in the world volume. If you want to place it into another physical volume, you can set the parameter

/gamos/setParam GmReadPhantomGeometry:MotherName PHYSVOL_NAME

By default the name of the voxels is phantom, and this is the name that you should use in you commands. You may change it with the parameter

/gamos/setParam GmReadPhantomGeometry:VoxelName VOXEL_NAME

It is also possible to displace the phantom from its (0,0,0) position in the mother volume. To do it you have to set the parameter:

/gamos/setParam GmReadPhantomGeometry:InitialDisplacement DISP_X DISP_Y DISP_Z

And to rotate it around the X axis, then Y axis and finally Z axis around the phantom centre you can use the parameter:

/gamos/setParam GmReadPhantomGeometry:InitialRotAngles ANGLE_X ANGLE_Y ANGLE_Z

Partial phantom geometries

The DICOM files always describe a parallelepiped geometry, including air around the real patient, animal or phantom. It may be that you have a CT DICOM file that you want to simulated inside a PET scanner or a radiotherapy accelerator and it does not fit becuase this air overlaps with the machine. In this case you may use a part of your .g4dcm file , taking the parallelepipedal DICOM geometry and intersecting it with some volume to create a new file. The volume can be one in the Geant4 volume or a virtual one you create. To do this you can follow the example in analysis/DICOM/buildPartialDICOM. You have to run a GAMOS job with an input file similar to the one in that directory The physics and primary generator can be anyone, but for the geometry you have to use GmReadPhantomG4Geometry to read your .g4dcm file. Then you have to add a command:

/gamos/geometry/DICOM/intersectWithG4Volume VOLUME_NAME

where VOLUME_NAME is the name of a volume defined in your geometry.

Alternatively you may use a virtual volume you create for the accasion, in a similar way as it is doen at In this case you have to add a command:

/gamos/geometry/DICOM/intersectWithUserVolume POS_X POS_Y POS_Z ANG_X ANG_Y ANG_Z SOLID_TYPE SOLID_PARAM_1 SOLID_PARAM_2 ...

where POS_X POS_Y POS_Z is the position of the centre of the volume, ANG_X ANG_Y ANG_Z are the angles of rotation around X, Y and Z axis, and then it comes the solid type and paramter with the same format as the one used to define a solid in the geometry text file format.

The file format is slightly different than that of the .g4dcm files. The start is the same: list of materials, number of voxels and phantom dimensions (as if it were the original parallelepiped). Then it comes the information about which voxels are used and which not: for each Z slice and for each Y slice there is a line indicating the X index of the first voxel used and that of the last voxel used (-1 -1 if no voxel is used in that X row). The rest of the file is also similar: the list of voxel material indices and the list of voxel densities.

To read this file the geometry to be used is:

/gamos/geometry GmReadPhantomG4Geometry

Simple phantom geometries

The user may build simple regular phantom geometries without the need of writing a DICOM file by using

/gamos/geometry GmSimplePhantomGeometry

The number of voxels is defined with the parameter

/gamos/setParam GmSimplePhantomGeometry:NVoxels NVOXEL_X NVOXEL_Y NVOXEL_Z

The minimum and maximum extensions in the three axes are defined with the parameter

/gamos/setParam GmSimplePhantomGeometry:PhantomDims MIN_X MAX_X MIN_Y MAX_Y MIN_Z MAX_Z

Then you can divide the phantom in different regions along the Z axis with the parameter

/gamos/setParam GmSimplePhantomGeometry:MaterialZVoxels NZ_1 NZ_2 ...

where NZ_i is the number of voxels along Z of the i region.

Then you can assign the material and material densities of each Z region with the parameters

/gamos/setParam GmSimplePhantomGeometry:MaterialNames MATERIAL_1 MATERIAL_2 ...

/gamos/setParam GmSimplePhantomGeometry:MaterialDensities DENSITY\_1 DENSITY\_2 ...

Setting off visualization of phantom geometries

As the phantom geometry is not built with the text file format, the tag :VIS, that serves to set off the visualization, cannot be used for the phantom and the phantom container. Instead you may use the following parameters:

/gamos/setParam GmReadPhantomGeometry:Phantom:VisOff TRUE

/gamos/setParam GmReadPhantomGeometry:PhantomContainer:VisOff TRUE