<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet type="text/xsl" href="http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl" ?>
<!DOCTYPE Data [ <!ENTITY version SYSTEM 'version.txt'> ]>
<refentry xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink">
<info>
<author><personname><firstname>Mathieu</firstname><surname>Malaterre</surname></personname><contrib>Main developer</contrib></author>
<copyright><year>2006</year><year>2011</year><holder>Mathieu Malaterre</holder></copyright>
</info>
  <refmeta>
    <refentrytitle>gdcmconv</refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo class="source">GDCM</refmiscinfo>
    <refmiscinfo class="version">&version;</refmiscinfo>
    <refmiscinfo class="manual">DICOM Manipulation.</refmiscinfo>
  </refmeta>
  <refnamediv><refname>gdcmconv</refname>
    <refpurpose>Tool to convert DICOM to DICOM.</refpurpose>
</refnamediv>
<refsection xml:id="gdcmconv_1synopsis">
<title>SYNOPSIS</title>

<para><literallayout>gdcmconv [options] file-in file-out
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1description">
<title>DESCRIPTION</title>

<para>The <emphasis role="bold">gdcmconv</emphasis> command line program takes as input a DICOM file (file-in) and process it to generate an output DICOM file (file-out). The command line option dictate the type of operation(s) gdcmconv will use to generate the output file.</para>
</refsection>
<refsection xml:id="gdcmconv_1parameters">
<title>PARAMETERS</title>

<para><literallayout>file-in   DICOM input filename

file-out  DICOM output filename
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1options">
<title>OPTIONS</title>

<para><literallayout>  -i --input      DICOM filename
  -o --output     DICOM filename
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1specific_options">
<title>specific options</title>

<para><literallayout>  -X --explicit            Change Transfer Syntax to explicit.
  -M --implicit            Change Transfer Syntax to implicit.
  -U --use-dict            Use dict for VR (only public by default).
     --with-private-dict   Use private dict for VR (advanced user only).
  -C --check-meta          Check File Meta Information (advanced user only).
     --root-uid            Root UID.
     --remove-gl           Remove group length (deprecated in DICOM 2008).
     --remove-private-tags Remove private tags.
     --remove-retired      Remove retired tags.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1image_options">
<title>image options</title>

<para><literallayout>  -l --apply-lut                      Apply LUT (non-standard, advanced user only).
  -8 --apply-lut8                     Apply LUT/RGB8 (non-standard, advanced user only).
     --decompress-lut                 Decompress LUT (linearize segmented LUT).
  -P --photometric-interpretation %s  Change Photometric Interpretation (when possible).
  -w --raw                            Decompress image.
  -d --deflated                       Compress using deflated (gzip).
  -J --jpeg                           Compress image in jpeg.
  -K --j2k                            Compress image in j2k.
  -L --jpegls                         Compress image in jpeg-ls.
  -R --rle                            Compress image in rle (lossless only).
  -F --force                          Force decompression/merging before recompression/splitting.
     --generate-icon                  Generate icon.
     --icon-minmax %d,%d              Min/Max value for icon.
     --icon-auto-minmax               Automatically compute best Min/Max values for icon.
     --compress-icon                  Decide whether icon follows main TransferSyntax or remains uncompressed.
     --planar-configuration [01]      Change planar configuration.
  -Y --lossy                          Use the lossy (if possible) compressor.
  -S --split %d                       Write 2D image with multiple fragments (using max size)
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1jpeg_options">
<title>JPEG options</title>

<para><literallayout>  -q --quality %*f           set quality.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1jpegls_options">
<title>JPEG-LS options</title>

<para><literallayout>  -e --allowed-error %*i       set allowed error.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1j2k_options">
<title>J2K options</title>

<para><literallayout>  -r --rate    %*f           set rate.
  -q --quality %*f           set quality.
  -t --tile %d,%d            set tile size.
  -n --number-resolution %d  set number of resolution.
     --irreversible          set irreversible.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1general_options">
<title>general options</title>

<para><literallayout>  -h   --help
         print this help text and exit

  -v   --version
         print version information and exit

  -V   --verbose
         verbose mode (warning+error).

  -W   --warning
         warning mode, print warning information

  -E   --error
         error mode, print error information

  -D   --debug
         debug mode, print debug information
</literallayout></para>
</refsection>
<refsection xml:id="gdcmdump_1special_options">
<title>special options</title>

<para><literallayout>  -I --ignore-errors   convert even if file is corrupted (advanced users only, see disclaimers).
</literallayout></para>
</refsection>
<refsection xml:id="gdcmtar_1environment_variable">
<title>environment variable</title>

<para><literallayout>  GDCM_ROOT_UID Root UID
</literallayout></para>
</refsection>
<refsection xml:id="gdcmviewer_1simple_usage">
<title>Simple usage</title>

<para><emphasis role="bold">gdcmconv</emphasis> is a great tool to convert broken DICOM implementation into properly parsable DICOM file. Usage is simply:</para>

<para><literallayout>$ gdcmconv input.dcm output.dcm
</literallayout></para>

<para>or if you prefer being explicit:</para>

<para><literallayout>$ gdcmconv -i input.dcm -o output.dcm
</literallayout></para>

<para>Even though gdcmconv can overwrite directly on the same file (input.dcm = output.dcm), it is recommended that user should first convert into a different file to make sure the bug is properly handled by GDCM.</para>

<para>Typical cases where you would want to use gdcmconv in its simple form:</para>

<para><itemizedlist>
<listitem>
<para>convert non-cp246 conforming file into conforming cp246, </para>
</listitem>
<listitem>
<para>convert implicit little endian transfer syntax file meta header into proper explicit little endian transfer syntax, </para>
</listitem>
<listitem>
<para>convert the GE-13 bytes bug, </para>
</listitem>
<listitem>
<para>convert dual syntax file: implicit/explicit, </para>
</listitem>
<listitem>
<para>convert Philips dual Little Endian/Big Endian file, </para>
</listitem>
<listitem>
<para>convert GDCM 1.2.0 broken UN-2-bytes fields, </para>
</listitem>
<listitem>
<para>... </para>
</listitem>
<listitem>
<para>All other broken files listed in the supported refsection.</para>
</listitem>
</itemizedlist>
When no option other is used, only the dataset is inspected. So encapsulated Pixel Data, for instance, is not inspected for well known bugs.</para>

<para>When doing this kind of work, this is usually a good idea to perform some kind of quality control, see gdcmconv Quality Control refsection (down below).</para>
</refsection>
<refsection xml:id="gdcmviewer_1usage">
<title>Typical usage</title>
<refsection xml:id="gdcmconv_1file_meta">
<title>File Meta Header</title>

<para>Running</para>

<para><literallayout>$ gdcmconv input.dcm output.dcm
</literallayout></para>

<para>Is not enough to recompute file meta header, when input file is buggy. You may want to use: &#8211;check-meta</para>

<para><literallayout>$ gdcmconv --check-meta input.dcm output.dcm
</literallayout></para>

<para>See typical cases such as: GE_DLX-8-MONO2-PrivateSyntax.dcm or PICKER-16-MONO2-No_DicomV3_Preamble.dcm from gdcmData.</para>
</refsection>
<refsection xml:id="gdcmconv_1explicit">
<title>Conversion to Explicit Transfer Syntax</title>

<para>To convert a file that was written using Implicit Transfer Syntax into Explicit Transfer Syntax simply use:</para>

<para><literallayout>$ gdcmconv --explicit uncompressed.dcm compressed.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossless_jpeg">
<title>Compressing to lossless JPEG</title>

<para>To compress an uncompressed DICOM file to a JPEG Lossless encapsulated format:</para>

<para><literallayout>$ gdcmconv --jpeg uncompressed.dcm compressed.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossy_jpeg">
<title>Compressing to lossy JPEG</title>

<para>To compress an uncompressed DICOM file to a JPEG Lossy encapsulated format:</para>

<para><literallayout>$ gdcmconv --lossy --jpeg -q 90 uncompressed.dcm compressed.dcm
</literallayout></para>

<para>Note: <literallayout>  -q is just one of the many way to specify lossy quality, you need to inspect the other cmd line flag to specify lossyness properties.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossless_jpegls">
<title>Compressing to lossless JPEG-LS</title>

<para>To compress an uncompressed DICOM file to a JPEG-LS Lossless encapsulated format:</para>

<para><literallayout>$ gdcmconv --jpegls uncompressed.dcm compressed.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossy_jpegls">
<title>Compressing to lossy JPEG-LS</title>

<para>To compress an uncompressed DICOM file to a JPEG-LS Lossy encapsulated format:</para>

<para><literallayout>$ gdcmconv --lossy --jpegls -e 2 uncompressed.dcm lossy_compressed.dcm
</literallayout></para>

<para>Note:</para>

<para>-e (or &#8211;lossy-error) means that the maximum tolerate error is 2 for each pixel value</para>
</refsection>
<refsection xml:id="gdcmconv_1lossless_j2k">
<title>Compressing to lossless J2K</title>

<para>To compress an uncompressed DICOM file to a JPEG-2000 Lossless encapsulated format:</para>

<para><literallayout>$ gdcmconv --j2k uncompressed.dcm compressed.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossy_j2k">
<title>Compressing to lossy J2K</title>

<para>To compress an uncompressed DICOM file to a JPEG-2000 Lossy encapsulated format:</para>

<para><literallayout>$ gdcmconv --lossy -q 55,50,45 --j2k uncompressed.dcm lossy_compressed.dcm
</literallayout></para>

<para>Note: <literallayout>  -q is just one of the many way to specify lossy quality, you need to inspect the other cmd line flag to specify lossyness properties.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1lossless_rle">
<title>Compressing to lossless RLE</title>

<para>To compress an uncompressed DICOM file to a RLE Lossless encapsulated format:</para>

<para><literallayout>$ gdcmconv --rle uncompressed.dcm compressed.dcm
</literallayout></para>

<para>There is no such thing as lossy RLE compression.</para>
</refsection>
<refsection xml:id="gdcmconv_1split_encapsulated">
<title>Split encapsulated DICOM:</title>

<para>To split an encapsulated stream into smaller chunk (1024 bytes each):</para>

<para><literallayout>$ gdcmconv --split 1024 rle.dcm rle_1024.dcm
</literallayout></para>

<para>If an odd number of bytes is passed it will be rounded down to the next even number (eg. 1025 -&gt; 1024) since DICOM only allow even number for Value Length.</para>
</refsection>
<refsection xml:id="gdcmconv_1force">
<title>Forcing (re)compression</title>

<para>Sometime it is necessary to use the &#8211;force option. By default when user specify &#8211;j2k and input file is already in JPEG 2000 encapsulated DICOM format then no operation takes places. By using &#8211;force you make sure that (re)compression operation takes places.</para>

<para>Real life example of why you would use &#8211;force: <itemizedlist>
<listitem>
<para>When Pixel Data is missing data / is padded with junk </para>
</listitem>
<listitem>
<para>When you would like to make sure GDCM can handle decompression &amp; recompression cycle</para>
</listitem>
</itemizedlist>
</para>
</refsection>
<refsection xml:id="gdcmconv_1decompress_raw">
<title>Decompressing a Compressed DICOM</title>

<para><literallayout>$ gdcmconv --raw compressed.dcm uncompressed.dcm
</literallayout></para>
<para>In the case of uncompress file (Explicit and Implicit) the behavior is to keep the original Transfer Syntax (so Implicit remains Implit)</para>
</refsection>
<refsection xml:id="gdcmconv_1decompress_raw_imp">
<title>Decompressing a Compressed DICOM as implicit</title>

<para><literallayout>$ gdcmconv --raw --implicit compressed.dcm uncompressed_implicit.dcm
</literallayout></para>
<para>By symmetry it is also possible to use gdcmconv --raw --explicit to make sure that target file is always Explicit TS.</para>
</refsection>
<refsection xml:id="gdcmconv_1compress_icon">
<title>Compressing an uncompressed Icon</title>

<para>By default when compressing a DICOM Image file, gdcmconv will not compress the icon. A user option needs to be turned on to explicitly force the compression of the Icon Image Sequence Pixel Data</para>

<para>For example, by default we will not compress the Icon Image Sequence Pixel Data attribute:</para>

<para><literallayout>$ gdcmconv --jpeg gdcmData/simpleImageWithIcon.dcm uncompressed_icon.dcm
</literallayout></para>

<para>In the following example we will explicitly compress the Icon Image Sequence Pixel Data attibute. In that case the same Transfer Syntax is being used for both the main Pixel Data and the Pixel Data from the Icon Image Sequence:</para>

<para><literallayout>$ gdcmconv --jpeg --compress-icon gdcmData/simpleImageWithIcon.dcm compressed_icon.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1generate_icon">
<title>Generating an Icon</title>

<para>For some application it might be necessary to produce a small preview of the main image to be able to quickly load that short preview instead of the main image. In that case:</para>

<para><literallayout>$ gdcmconv --raw --generate-icon gdcmData/test.acr test_icon.dcm
</literallayout></para>

<para>In some cases the main Pixel Data element is expressed as pixel defined on 16bits. Since Icon can only store at most pixel of size 8bits, a rescale operation needs to take place. In order to properly select a better interval for doing the rescale operation user can specify the min max used for the rescale operation:</para>

<para><literallayout>$ gdcmconv --raw --generate-icon --icon-minmax 0,192 gdcmData/012345.002.050.dcm icon_minmax.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1planar_configuration">
<title>Changing the planar Configuration</title>

<para>Often RLE files are compressed using a different Planar Configuration (RRR ... GGG... BBB...) instead of the usual triplet (RGB ... RGB ... RGB ). So upon decompression the Planar Configuration is 1. This is perfectly legal in DICOM, however this is unconventional, and thus it may be a good idea to also change the planar configuration and set it to the default :</para>

<para><literallayout>$ gdcmconv --raw --planar-configuration 0 compressed.dcm uncompressed1.dcm
</literallayout></para>

<para>To reinvert the planar configuration of file &apos;uncompressed1.dcm&apos;, simply do:</para>

<para><literallayout>$ gdcmconv --raw --planar-configuration 1 uncompressed1.dcm uncompressed2.dcm
</literallayout></para>
</refsection>
</refsection>
<refsection xml:id="gdcmconv_1lossless_conversion">
<title>Lossless Conversion</title>

<para>When talking about lossless conversion, there is an ambiguity that need to be understood. To achieve higher compression ratio, the RGB color space is usually not used, in favor of a YBR one. Changing from one color space to the other is (bit level) not lossless.</para>

<para>For more detail, see what are the true lossless transformations as described:</para>

<para><link xlink:href="http://gdcm.sourceforge.net/wiki/index.php/Color_Space_Transformations">http://gdcm.sourceforge.net/wiki/index.php/Color_Space_Transformations</link></para>
</refsection>
<refsection xml:id="gdcmconv_1quality_control">
<title>Quality Control</title>

<para>One important part when using gdcmconv it to have a way to quality control the output.</para>

<para>You can use 3rd party tool to check the output of gdcmconv is correct.</para>
<refsection xml:id="gdcmconv_1other_toolkit">
<title>DCMTK / dicom3tools</title>

<para>Using another DICOM implementation such as the one from DCMTK or dicom3tools can be a good process to check the output of gdcmconv. <itemizedlist>
<listitem>
<para>For DCMTK use: dcmdump </para>
</listitem>
<listitem>
<para>For dicom3tools use: dcdump</para>
</listitem>
</itemizedlist>
For reference, gdcmconv --raw will act as dcmdjpeg +cn +px, since it never tries to convert color space.</para>
</refsection>
<refsection xml:id="gdcmconv_1vim">
<title>VIM: vimdiff</title>

<para>You can setup your favorite editor to compare the output, for instance in vim:</para>

<para><literallayout><computeroutput>autocmd&#32;BufReadPre&#32;*.dcm&#32;set&#32;ro
autocmd&#32;BufReadPost&#32;*.dcm&#32;silent&#32;%!dcmdump&#32;-M&#32;+uc&#32;"%"
</computeroutput></literallayout></para>

<para>then simply do:</para>

<para><literallayout><computeroutput>$&#32;vimdiff&#32;input.dcm&#32;output.dcm
</computeroutput></literallayout></para>
</refsection>
<refsection xml:id="gdcmconv_1binary_diff">
<title>vbindiff</title>

<para>On UNIX you can visually compare binary file using the vbindiff command:</para>

<para><literallayout><computeroutput>$&#32;vbindiff&#32;input.dcm&#32;output.dcm
</computeroutput></literallayout></para>
</refsection>
</refsection>
<refsection xml:id="gdcmconv_1see_also">
<title>SEE ALSO</title>

<para><emphasis role="bold">gdcmdump</emphasis>(1), <emphasis role="bold">gdcmraw</emphasis>(1), <emphasis role="bold">gdcminfo</emphasis>(1), <emphasis role="bold">gdcmdiff</emphasis>(1)</para>
</refsection>
</refentry>
