Command-line tools provided with vtk-dicom:

dicomdump

usage:
  dicomdump file1.dcm [file2.dcm ...]

options:
  -k tag          Provide a key to be printed.
  -q <query.txt>  Provide a file that lists which elements to print.
  --help          Print a brief help message.
  --version       Print the software version.

Dump the metadata from a DICOM series as text. If only a few attributes are to be dumped, then their tags can be given with "-k" (the "-k" option can be repeated as many times as needed). Tags can given in hexadecimal GGGG,EEEE format, or in text format as specified in the DICOM dictionary. Alternately, the tags can be listed in a query file given with the "-q" option (one tag per line). Attributes nested within sequences can be specified by giving a tag path e.g. "-k Tag1/Tag2/Tag3". Either a forward slash or a backslash can be used to separate the components of the path.

dicomfind

usage:
  dicomfind [options] <directory> ...

options:
  -L              Follow symbolic links (default).
  -P              Do not follow symbolic links.
  -k tag=value    Provide an attribute to be queried and matched.
  -q <query.txt>  Provide a file to describe the find query.
  -u <uids.txt>   Provide a file that contains a list of UIDs.
  -maxdepth n     Set the maximum directory depth.
  -name pattern   Set a pattern to match (with "*" or "?").
  -image          Restrict the search to files with PixelData.
  -series         Find all files in series if even one file matches.
  -print          Print the filenames of all matched files (default).
  -print0         Print the filenames with terminating null, for xargs.
  -exec ... +     Execute the given command for every series matched.
  -exec ... \;    Execute the given command for every file matched.
  -execdir ... +  Go to directory and execute command on every series.
  -execdir ... \; Go to directory and execute command on every file.
  --help          Print a brief help message.
  --version       Print the software version.

This command can be used to locate DICOM files. It shares many features with the UNIX "find" command. When searching for files with a specific attribute (with "-k"), the tag can be specified in the form GGGG,EEEE or with its canonical name e.g. Modality=MR from the DICOM dictionary. Alternately, the tags can be listed in a query file given with the "-q" option (one tag per line). Attributes nested within sequences can be specified by giving a tag path e.g. "-k Tag1/Tag2/Tag3". Either a forward slash or a backslash can be used to separate the components of the path. Private tags should be preceded by the private dictionary name in square brackets.

The "-exec" and "-execdir" arguments cause dicomfind to run the specified program on the found files. For example, to dump each file one would use "-exec dicomdump {} \;" where each instance of {} will be replaced by a found file, and ";" indicates the end of the args to dicomdump. Alternately, if "+" is used to end the args, then the program will be run on each DICOM series and {} will be replaced by all files in the series. The "-execdir" argument is similar, except that it runs the program from within the directory of the file (or files), and {} is replaced by just the filenames instead of with the full paths.

dicompull

usage:
  dicompull [options] <directory> ...

options:
  -L              Follow symbolic links (default).
  -P              Do not follow symbolic links.
  -k tag=value    Provide an attribute to be queried and matched.
  -q <query.txt>  Provide a file to describe the find query.
  -u <uids.txt>   Provide a file that contains a list of UIDs.
  -o <directory>  Directory to place the files into.
  -maxdepth n     Set the maximum directory depth.
  -name pattern   Set a pattern to match (with "*" or "?").
  -image          Restrict the search to files with PixelData.
  -series         Find all files in series if even one file matches.
  --silent        Do not report any progress information.
  --help          Print a brief help message.
  --version       Print the software version.

Find dicom files in one directory and copy them to a new directory.

The output directory given with "-o" can use DICOM attributes, by naming those attributes within curly braces. For example, consider "{PatientID}/{StudyDescription}/{SeriesDescription}-{SeriesNumber}" or something similar to produce a hierarchichal directory structure. The attributes used in the path should be from the following list:

  PatientID, PatientName, PatientBirthDate, PatientSex,
  StudyID, StudyDescription, StudyDate, StudyTime, StudyInstanceUID,
  SeriesNumber, SeriesDescription, SeriesInstanceUID,
  Modality, AccessionNumber.

The files to be copied are specified with search keys, which take the form "-k key=value" where keys can either use the standard names given in the DICOM dictionary, e.g. Modality or SeriesDescription, or can be in the form GGGG,EEEE with hexadecimal group and element values. The tags can also be listed in a query file with the "-q" option (one tag per line). Private tags should be preceded by the private dictionary name in square brackets.

The values used for "-k key=value" can use the wildcards * and ?, and can also use date ranges of the form "19990103-19990105".

The "-u" option can be used to provide a list of UIDs. Provide a file where the first line of the file is the key (e.g. SeriesInstanceUID) and the rest of the file is the UIDs to match, one UID per line.

dicomtocsv

usage:
  dicomtocsv [options] <directory>

options:
  -k tag=value     Provide a key to be queried and matched.
  -q <query.txt>   Provide a file to describe the find query.
  -u <uids.txt>    Provide a file that contains a list of UIDs.
  -o <data.csv>    Provide a file for the query results.
  --first-nonzero  Search series for first nonzero value of each key.
  --directory-only Use directory scan only, do not re-scan files.
  --study          Print one row for each study.
  --series         Print one row for each series (default).
  --image          Print one row for each image.
  --silent         Do not report any progress information.
  --help           Print a brief help message.
  --version        Print the software version.

Dump selected metadata from a DICOM directory to a csv file. For each attribute to be extracted, the tag can be given with "-k" (the "-k" option can be repeated as many times as needed). Tags can given in hexadecimal GGGG,EEEE format, or in text format as specified in the DICOM dictionary. Alternately, the tags can be listed in a query file given with the "-q" option (one tag per line). Attributes nested within sequences can be specified by giving a tag path e.g. "-k Tag1/Tag2/Tag3". Either a forward slash or a backslash can be used to separate the components of the path. Private tags should be preceded by the private dictionary name in square brackets.

If the same tag is given more than once with "-k" (or if the tag is listed multiple times in the query file, or appears in both the query file and as a "-k" option), then its first appearance will set the column number that it appears in. Also, with regards to the search, the value specified in the final appearance of the tag as an option will be the value used for the search.

# This is my query file
SeriesDate=2011-2014    # date range
SeriesTime
SeriesDescription="*T1*"
PatientName
[GEMS_ACQU_01]0019,1084:DS # PeakSAR private tag with VR of DS
NumberOfReferences      # 0004,1600
ReferencedFileID        # 0004,1500

The query file consists of one attribute tag per line (in hexadecimal), along with the allowed values of the attribute and an optional comment. If the attribute is private, then it must be preceded by the name of its private dictionary in square brackets. There are two special attributes, NumberOfReferences (0004,1600) and ReferencedFileID (0004,1500), that must be included in the query in order to output the number of files in the series and the first filename in the series to the csv file.

Attribute tags in the query file that are followed by "=" and a value are used to select which DICOM files to include in the output. For example, SeriesDate=2011-2014 means that the SeriesDate must be between 2011-Jan-01 and 2014-Dec-31 inclusive. And SeriesDescription="*T1*" means that the SeriesDescription must contain the text "T1". Attribute matching follows these rules:

  1. Date, Time, and DateTime attributes can specify a range by using a hyphen.
  2. Other text attributes can be matched with a wildcard string, where "*" and "?" are the wildcards.
  3. If no wildcards are present, the match must be exact.
  4. Patient name matching does not require case (i.e. capitalization) to match.
  5. All text matching is done in utf-8 (non-utf8 text is converted to utf8 for matching).
  6. If the attribute is multi-valued, then it matches as long as one value matches.

If a desired attribute is buried within a sequence, then it can be specified as follows:

0040,0260\0008,0100    # PerformedProtocolCodeSequence\CodeValue

dicomtonifti

usage:
  dicomtonifti -o file.nii file1.dcm [file2.dcm ...]
  dicomtonifti -o directory --batch file1.dcm [file2.dcm ...]

options:
  -o <output.nii[.gz]>    The output file (or directory, if --batch).
  -z --compress           Compress output files.
  -r --recurse            Recurse into subdirectories.
  -b --batch              Do multiple series at once.
  -s --silent             Do not echo output filenames.
  -v --verbose            Verbose error reporting.
  -L --follow-symlinks    Follow symbolic links when recursing.
  --fsl                   Format axial image for use in FSL.
  --reformat-to-axial     Reformat the image into axial orientation.
  --no-slice-reordering   Never reorder the slices.
  --no-row-reordering     Never reorder the rows.
  --no-column-reordering  Never reorder the columns.
  --no-reordering         Never reorder slices, rows, or columns.
  --no-qform              Don't include a qform in the NIFTI file.
  --no-sform              Don't include an sform in the NIFTI file.
  --version               Print the version and exit.
  --volume N              Set the volume to output (starts at 0).
  --build-version         Print source and build version.
  --help                  Documentation for dicomtonifti.

This program will convert a DICOM series into a NIfTI file.

It reads the DICOM Position and Orientation metadata, and uses this information to generate qform and sform entries for the NIfTI header, after doing a conversion from the DICOM coordinate system to the NIfTI coordinate system.

By default, it will also reorder the columns of the image so that columns with higher indices are further to the patient's right (or in the case of sagittal images, further anterior). Likewise, rows will be rearranged so that rows with higher indices are superior (or anterior for axial images). Finally, it will reorder the slices so that the column direction, row direction, and slice direction follow the right-hand rule.

It is also possible to reformat the images into the axial orientation via the --reformat-to-axial option. This option is mutually exclusive with the no-reordering options. The resulting orientation matrix will be the identity matrix.

If the output NIFTI files are to be used with the FMRIB FSL package, then use the --fsl option to reformat the images to match the standard FSL orientation: axial images with the slices arranged from inferior to superior, column number increasing from right to left, and row number increasing from posterior to anterior. This will also convert the data type from unsigned 16-bit to signed 16-bit if necessary.

If batch mode is selected, the output file given with "-o" can be constructed from DICOM attributes, by providing the attribute names within curly braces. For example, consider the following: "{PatientID}-{StudyDate}/{SeriesDescription}-{SeriesNumber}.nii" or something similar to produce a hierarchical directory structure. The attributes used in the path should be from the following list:

  PatientID, PatientName, PatientBirthDate, PatientSex,
  StudyID, StudyDescription, StudyDate, StudyTime, StudyInstanceUID,
  SeriesNumber, SeriesDescription, SeriesInstanceUID,
  Modality, AccessionNumber.

Here is an example of batch mode that recurses into subdirectories and compresses the output files, putting the results in the current directory:

  dicomtonifti -brz -o {SeriesDescription}-{SeriesNumber}.nii /path/to/dicom/files

niftitodicom

usage:
  niftitodicom -o directory file.nii [file.dcm ...]

options:
  -o directory            The output directory.
  -s --silent             Do not print anything while executing.
  -v --verbose            Verbose error reporting.
  --no-reordering         Never reorder slices, rows, or columns.
  --axial                 Produce axial slices.
  --coronal               Produce coronal slices.
  --sagittal              Produce sagittal slices.
  --series-description    Textual description of the series.
  --series-number         The series number ot use.
  --modality              The modality: MR or CT or SC.
  --uid-prefix            A DICOM uid prefix (optional).
  --version               Print the version and exit.
  --build-version         Print source and build version.
  --help                  Documentation for niftitodicom.

This program will convert a NIfTI file into a DICOM series.

It reads the NIfTI file header and does the best job that it can to generate a series of DICOM files. To help it along, you can provide a DICOM file from the same series on the command line after the NIfTI file, or even better, list all of the DICOM files that were used as the source of the data in the NIfTI file. Study-related meta data will be copied from these DICOM files into the output DICOM files.

Unless the --no-reordering option is provided, it will ensure that the images are in the usual orientation (right is left, posterior is down) by reordering the columns or rows as compared to the NIFTI file.

If the NIFTI file is floating-point, then the data might be rescaled when written to DICOM as 16-bit integers. If any data values are too large to fit into 16 bits, then all the data will be scaled down. If the data values all have a magnitude smaller than 2.05, then all the data will be scaled up by a factor of 1000.

dicomtodicom

usage:
  dicomtodicom -o directory file.dcm ...

options:
  -o directory            The output directory.
  -s --silent             Do not print anything while executing.
  -v --verbose            Verbose error reporting.
  --axial                 Produce axial slices.
  --coronal               Produce coronal slices.
  --sagittal              Produce satittal slices.
  --series-description    Textual description of the series.
  --series-number         The series number to use.
  --modality              The modality: MR or CT or SC.
  --uid-prefix            A DICOM uid prefix (optional).
  --version               Print the version and exit.
  --build-version         Print source and build version.
  --help                  Documentation for dicomtodicom.

This program allows adjustment of a DICOM series.

In its most basic functionality, this command reads a DICOM series and then writes it out with a new UID. It strips out any meta data that is not recognized as part of the SOP class that it is writing. In other words, its main purpose is to coerce the data to fit the requested SOP class.

Currently, only three output SOP classes can be written: Secondary Capture, CT, and MR. Enhanced CT and Enhanced MR cannot be written, but they can be read, therefore this program can be used to convert enhanced single-file CT and MR DICOM into a series of DICOM files.

The written data has the ImageType set to DERIVED\SECONDARY\OTHER and has a new series number and name. It isn't meant to replace the original data, it is simply meant to coerce the data into a format that might be more compatible with other software.

Reformatting of the data (MPR) is permitted during the conversion. This is an experimental feature and causes much of the per-instance meta data to be discarded.

niftidump

usage:
  niftidump file.nii[.gz]

options:
  --help      Print a brief help message.
  --version   Print the software version.

Dump the header from a NIfTI file.