<?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>gdcmimg</refentrytitle>
    <manvolnum>1</manvolnum>
    <refmiscinfo class="source">GDCM</refmiscinfo>
    <refmiscinfo class="version">&version;</refmiscinfo>
    <refmiscinfo class="manual">DICOM Manipulation.</refmiscinfo>
  </refmeta>
  <refnamediv><refname>gdcmimg</refname>
    <refpurpose>Manipulate DICOM image file.</refpurpose>
</refnamediv>

<para>gdcmimg is a low level tool to allow de-/encapsulation from/to DICOM image. This tool does not understand Transfer Syntax conversion. It will encapsulate the raw data as-is. This has some impact in some cases, see special warnings below.</para>

<para>It is important to note that gdcmimg can only encapsulate proper input file, for instance JPG and or JP2 are accepted since an associated DICOM Transfer Syntax can be found. However input such as TIFF and/or PNG are not, since DICOM does not support those. See instead a tool such as gdcm2vtk.</para>
<refsection xml:id="gdcmimg_1synopsis">
<title>SYNOPSIS</title>

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

<para>The <emphasis role="bold">gdcmimg</emphasis> command line tool can be used in two fashions: <itemizedlist>
<listitem>
<para>1. Converting a recognized file format into its encapsulated DICOM counterpart, </para>
</listitem>
<listitem>
<para>2. Anonymizing a rectangular portion of a DICOM file.</para>
</listitem>
</itemizedlist>
</para>
</refsection>
<refsection xml:id="gdcmimg_1parameters">
<title>PARAMETERS</title>

<para><literallayout>file-in   input filename (non-DICOM)

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

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

<para><literallayout>     --endian %s       Endianness (LSB/MSB).
  -d --depth %d        Depth (Either 8/16/32 or BitsAllocated eg. 12 when known).
     --sign %s         Pixel sign (0/1).
     --spp  %d         Sample Per Pixel (1/3).
     --pc [01]         Change planar configuration.
     --pi [str]        Change photometric interpretation.
     --pf %d,%d,%d     Change pixel format: (BA,BS,HB).
  -s --size %d,%d      Size.
     --offset %ull     Start Offset.
  -C --sop-class-uid   SOP Class UID (name or value).
  -T --study-uid       Study UID.
  -S --series-uid      Series UID.
     --template        Template DICOM file.
     --keep-meta       Keep meta info from template file (advanced users only).
     --root-uid        Root UID.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1fill_options">
<title>fill options</title>

<para><literallayout>  -R --region %d,%d    Region.
  -F --fill %d         Fill with pixel value specified.
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_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="gdcmtar_1environment_variable">
<title>environment variable</title>

<para><literallayout>  GDCM_ROOT_UID Root UID
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1supported">
<title>Supported File Format (appropriate file extension)</title>

<para>gdcmimg will base it&apos;s conversion process based on the file extension. Follows the list of recognized file extension. When no extension is found, DICOM file is assumed.</para>

<para>input format <literallayout>  * RAW       (raw, rawl, gray, rgb)
  * RLE       (rle)
  * PNM       (pgm, pnm, ppm)
  * JPEG-LS   (jls)
  * JPEG 2000 (jp2, j2k, j2c, jpx, jpc)
  * JPEG      (jpg, jpeg, ljpg, ljpeg)
  * DICOM     ()
</literallayout></para>

<para>output format: <literallayout>  * PGM       (pgm, pnm, ppm)
  * DICOM     ()
</literallayout></para>

<para>For RAW file format, you should take special care of the &#8211;endian option. For the (old) JPEG file format, both the lossy and lossless format are supported, user should pay attention to the &#8211;sign option. For file format such as RLE or RAW, user is expected to fill in information required to find the dimension and type of input data as there is no other way to find this information. For all other file format, the properties are derived from the file format itself.</para>

<para>PNM file are supposed to be big endian (important for depth &gt; 8)</para>
</refsection>
<refsection xml:id="gdcmviewer_1usage">
<title>Typical usage</title>
<refsection xml:id="gdcmimg_1blank_out">
<title>Remove a rectangular part of the image</title>

<para>To fill the region [0,100]x[0,100] of a DICOM image simply do:</para>

<para><literallayout>$ gdcmimg --fill 0 --region 0,100,0,100 -i input.dcm -o output_black.dcm
</literallayout></para>

<para>Warning: if the Pixel Data is compressed, the image is first decompressed so that pixel can be set to 0, but it is not re-compressed.</para>
</refsection>
<refsection xml:id="gdcmimg_1convert_raw">
<title>Convert RAW to DICOM</title>

<para>Recognized extension is .raw, .rawl, .gray or .rgb (case insensitive)</para>

<para><literallayout>$ gdcmimg --size 512,512 --depth 16 -i input.raw -o output.dcm
</literallayout></para>

<para>the image will be a Secondary Capture.</para>

<para>When the input is 3 component, one need to specify explicitly the Samples Per Pixel:</para>

<para><literallayout>$ gdcmimg --size 512,512 --spp 3  input_rgb.raw output_rgb.dcm
</literallayout></para>

<para>When the filename contains .rgb as file extension output is automatically recognized as RGB no need to specify &#8211;spp</para>

<para><literallayout>$ gdcmimg --size 512,512 input.rgb output_rgb.dcm
</literallayout></para>

<para>You can use the <emphasis role="bold">dd</emphasis> cmd line to skip any header you would like to discard, for instance, if you would like to skip the first 108 bytes, simply do:</para>

<para><literallayout>$ dd skip=108 bs=1 if=input.raw of=output.raw
</literallayout></para>

<para>.raw and .rawl extension are equivalent. You need to explicitly specify the endianness manually:</para>

<para><literallayout>$ gdcmimg --endian MSB --size 512,512 --depth 16 -i input.raw -o output.dcm
</literallayout></para>

<para>or</para>

<para><literallayout>$ gdcmimg --endian LSB --size 512,512 --depth 16 -i input.raw -o output.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1pnm">
<title>Convert PGM/PNM/PPM to DICOM</title>

<para>Recognized extensions are .pgm, .pnm, .ppm (case insensitive)</para>

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

<para>the image will be a Secondary Capture</para>
</refsection>
<refsection xml:id="gdcmimg_1rle">
<title>Convert RLE to DICOM</title>

<para>Recognized extension is .rle (case insensitive)</para>

<para><literallayout>$ gdcmimg --size 512,512 --depth 16 -i input.rle -o output.dcm
</literallayout></para>

<para>the image will be a Secondary Capture </para>
</refsection>
<refsection xml:id="gdcmimg_1jpeg">
<title>Convert JPEG to DICOM</title>

<para>Recognized extensions are .jpg, .jpeg, .ljpg, .ljpeg (case insensitive)</para>

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

<para>the image will be a Secondary Capture</para>
</refsection>
<refsection xml:id="gdcmimg_1j2k">
<title>Convert J2K to DICOM</title>

<para>Recognized extensions are .j2k, .jp2, .jpc, jpx, j2c (case insensitive)</para>

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

<para>the image will be a Secondary Capture.</para>

<para>All Pixel information (Bits Stored/Allocated...) will be derived from the image itself, and not from the command line options.</para>
</refsection>
<refsection xml:id="gdcmimg_1sopclassuid">
<title>Specifying a SOP Class UID</title>

<para>Instead of the default Secondary Capture Image Storage, one may want to specify, say VL Photographic Image Storage.</para>

<para><literallayout>$ gdcmimg --sop-class-uid 1.2.840.10008.5.1.4.1.1.77.1.4 input.jpg output.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1template">
<title>Specifying a template DICOM file</title>

<para>Instead of the default Secondary Capture Image Storage, generated with default values, one may want to specify a DICOM file that will serve as template to fill in the DICOM attributes.</para>

<para><literallayout>$ gdcmimg --sign 1 --template template.dcm input.jpg output.dcm
</literallayout></para>
<para>Pay attention that any values from template.dcm that are not consistent with what is found inside the reference image will be overridden (eg. image size). On particular case should be of concern: the Pixel Representation for the JPEG family.</para>

</refsection>
</refsection>
<refsection xml:id="gdcmimg_1multiple_files">
<title>Multiple Files</title>

<para>gdcmimg handle nicely a set of files (for instance jpeg):</para>

<para><literallayout>$ gdcmimg -C 1.2.840.10008.5.1.4.1.1.12.1 1.jpg 2.jpg 3.jpg 4.jpg output.dcm
</literallayout></para>

<para>It is important to specify an SOP Class that supports multi-frames images otherwise gdcmimg will fail.</para>
</refsection>
<refsection xml:id="gdcmimg_1start_offset">
<title>Start Offset</title>

<para>In some case, one may want to create a 2D slice from an arbitrary volume (e.g 3D). In which case &#8211;offset becomes handy:</para>

<para><literallayout>$ gdcmimg --offset 4954104330 --size 1673,1673 Input3D_1673_1673_1775.raw slice_1770.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1warning">
<title>Warning</title>

<para>There are a couple of issues with gdcmimg implementation:</para>

<para>For RAW file, one should pay attention that when using &#8211;endian MSB the Pixel Data will be encapsulated as is (not touched by gdcmimg). Therefore the only possible transfer syntax available is Implicit VR Big Endian DLX (G.E Private). GDCM does handle this private Transfer Syntax. So if you need to convert this Transfer Syntax to another one (and allow Pixel Data manipulation), you can use:</para>

<para><literallayout>$ gdcmconv --raw --force input_big_endian_dlx.raw -o output_implicit_vr_little_endian.dcm
</literallayout></para>

<para>For JFIF file and JP2 file (with header) the header is copied into the Pixel Data element which is illegal for JP2. Use gdcmconv to properly re-encode a JP2/JFIF file into J2K/JPG.</para>

<para><literallayout>$ gdcmimg input.jp2 output_jp2.dcm
$ gdcmconv --j2k --force output_jp2.dcm output_j2k.dcm
</literallayout></para>

<para>For RLE file, no check is done for crossing the row boundary. It is recommended to use gdcmconv &#8211;rle to re-encode into a proper RLE file in case of doubt.</para>

<para>Of course if the compression is not ok with your setup, you can always de-encapsulated the DICOM file (typically JPEG) to a non-encapsulated form, using gdcmconv:</para>

<para><literallayout>$ gdcmconv --raw input_jpeg.dcm output_raw.dcm
</literallayout></para>
</refsection>
<refsection xml:id="gdcmimg_1see_also">
<title>SEE ALSO</title>

<para><emphasis role="bold">gdcmdump</emphasis>(1), <emphasis role="bold">gdcm2vtk</emphasis>(1), <emphasis role="bold">gdcmraw</emphasis>(1), <emphasis role="bold">convert</emphasis>(1), <emphasis role="bold">dd</emphasis>(1)</para>
</refsection>
</refentry>
