GDCMCONV(1)

โœจ NAME โœจ

okay bestie, welcome to gdcmconv(1) from the DICOM Manipulation manual โ€” this is literally the tool to convert DICOM to DICOM. No cap. ๐Ÿ’…


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

gdcmconv [options] file-in file-out

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

So the gdcmconv command-line program takes a DICOM file (file-in) as input, processes it, and generates an output DICOM file (file-out). The command-line option you pick dictates which operation(s) gdcmconv uses to make that output file. Main character energy: a converter that actually listens to your flags. โœจ

๐ŸŒธ PARAMETERS ๐ŸŒธ

  • file-in โ€” DICOM input filename
  • file-out โ€” DICOM output filename

๐Ÿ’… OPTIONS ๐Ÿ’…

  • -i, --input โ€” DICOM filename
  • -o, --output โ€” DICOM filename

๐Ÿฆ‹ SPECIFIC OPTIONS ๐Ÿฆ‹

  • -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.

๐ŸŽ€ IMAGE OPTIONS ๐ŸŽ€

  • -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)

๐Ÿ“ JPEG OPTIONS ๐Ÿ“

  • -q, --quality %*f โ€” set quality.

๐Ÿงš JPEG-LS OPTIONS ๐Ÿงš

  • -e, --allowed-error %*i โ€” set allowed error.

๐Ÿ’œ J2K OPTIONS ๐Ÿ’œ

  • -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.

๐ŸŒˆ GENERAL OPTIONS ๐ŸŒˆ

  • -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

โญ SPECIAL OPTIONS โญ

  • -I, --ignore-errors โ€” convert even if file is corrupted (advanced users only, see disclaimers).

๐Ÿซถ ENVIRONMENT VARIABLE ๐Ÿซถ

  • GDCM_ROOT_UID โ€” Root UID

๐Ÿ‘‘ SIMPLE USAGE ๐Ÿ‘‘

gdcmconv is a great tool to convert broken DICOM implementation into properly parsable DICOM file. Usage is simply:

$ gdcmconv input.dcm output.dcm

or if you prefer being explicit:

$ gdcmconv -i input.dcm -o output.dcm

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. Like, do the safe little test conversion first, bestie โ€” your future self says thank you. ๐Ÿ’–

Typical cases where you would want to use gdcmconv in its simple form:

  • convert non-cp246 conforming file into conforming cp246,
  • convert implicit little endian transfer syntax file meta header into proper explicit little endian transfer syntax,
  • convert the GE-13 bytes bug,
  • convert dual syntax file: implicit/explicit,
  • convert Philips dual Little Endian/Big Endian file,
  • convert GDCM 1.2.0 broken UN-2-bytes fields,
  • ...
  • All other broken files listed in the supported refsection.

When no other option is used, only the dataset is inspected. So encapsulated Pixel Data, for instance, is not inspected for well known bugs. It's giving "look but don't touch" energy. ๐Ÿ™ˆ

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). โœจ

๐ŸŒŸ TYPICAL USAGE ๐ŸŒŸ

๐ŸŒธ File Meta Header ๐ŸŒธ

Running

$ gdcmconv input.dcm output.dcm

is not enough to recompute file meta header, when input file is buggy. You may want to use --check-meta:

$ gdcmconv --check-meta input.dcm output.dcm

See typical cases such as: GE_DLX-8-MONO2-PrivateSyntax.dcm or PICKER-16-MONO2-No_DicomV3_Preamble.dcm from gdcmData.

๐Ÿฆ‹ Conversion to Explicit Transfer Syntax ๐Ÿฆ‹

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

$ gdcmconv --explicit uncompressed.dcm compressed.dcm

๐ŸŽ€ Compressing to lossless JPEG ๐ŸŽ€

To compress an uncompressed DICOM file to a JPEG Lossless encapsulated format:

$ gdcmconv --jpeg uncompressed.dcm compressed.dcm

๐Ÿ’… Compressing to lossy JPEG ๐Ÿ’…

To compress an uncompressed DICOM file to a JPEG Lossy encapsulated format:

$ gdcmconv --lossy --jpeg -q 90 uncompressed.dcm compressed.dcm
Note: -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. iykyk โ€” lossy quality has layers.

๐Ÿ“ Compressing to lossless JPEG-LS ๐Ÿ“

To compress an uncompressed DICOM file to a JPEG-LS Lossless encapsulated format:

$ gdcmconv --jpegls uncompressed.dcm compressed.dcm

๐Ÿงš Compressing to lossy JPEG-LS ๐Ÿงš

To compress an uncompressed DICOM file to a JPEG-LS Lossy encapsulated format:

$ gdcmconv --lossy --jpegls -e 2 uncompressed.dcm lossy_compressed.dcm
Note: -e (or --lossy-error) means that the maximum tolerate error is 2 for each pixel value. That's the vibe check for your pixels.

๐Ÿ’œ Compressing to lossless J2K ๐Ÿ’œ

To compress an uncompressed DICOM file to a JPEG-2000 Lossless encapsulated format:

$ gdcmconv --j2k uncompressed.dcm compressed.dcm

๐ŸŒˆ Compressing to lossy J2K ๐ŸŒˆ

To compress an uncompressed DICOM file to a JPEG-2000 Lossy encapsulated format:

$ gdcmconv --lossy -q 55,50,45 --j2k uncompressed.dcm lossy_compressed.dcm
Note: -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. Same note, different compressor โ€” the lore continues.

โญ Compressing to lossless RLE โญ

To compress an uncompressed DICOM file to a RLE Lossless encapsulated format:

$ gdcmconv --rle uncompressed.dcm compressed.dcm

There is no such thing as lossy RLE compression. Lossless only, periodt. ๐Ÿ’€

โœ‚๏ธ Split encapsulated DICOM: โœ‚๏ธ

To split an encapsulated stream into smaller chunk (1024 bytes each):

$ gdcmconv --split 1024 rle.dcm rle_1024.dcm

If an odd number of bytes is passed it will be rounded down to the next even number (eg. 1025 -> 1024) since DICOM only allow even number for Value Length. Math but make it DICOM. ๐Ÿงฎโœจ

๐Ÿ”ฅ Forcing (re)compression ๐Ÿ”ฅ

Sometime it is necessary to use the --force option. By default when user specify --j2k and input file is already in JPEG 2000 encapsulated DICOM format then no operation takes places. By using --force you make sure that (re)compression operation takes places. It's giving "do it again, but on purpose." ๐Ÿ’…

Real life example of why you would use --force:

  • When Pixel Data is missing data / is padded with junk
  • When you would like to make sure GDCM can handle decompression & recompression cycle

๐Ÿซถ Decompressing a Compressed DICOM ๐Ÿซถ

$ gdcmconv --raw compressed.dcm uncompressed.dcm

In the case of uncompress file (Explicit and Implicit) the behavior is to keep the original Transfer Syntax (so Implicit remains Implit). The original manpage really said "Implit" and honestly? Iconic. ๐Ÿ˜ญ

๐ŸŒธ Decompressing a Compressed DICOM as implicit ๐ŸŒธ

$ gdcmconv --raw --implicit compressed.dcm uncompressed_implicit.dcm

By symmetry it is also possible to use gdcmconv --raw --explicit to make sure that target file is always Explicit TS. Symmetry slay. โœจ

๐ŸŽ€ Compressing an uncompressed Icon ๐ŸŽ€

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.

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

$ gdcmconv --jpeg gdcmData/simpleImageWithIcon.dcm uncompressed_icon.dcm

In the following example we will explicitly compress the Icon Image Sequence Pixel Data attribute. 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:

$ gdcmconv --jpeg --compress-icon gdcmData/simpleImageWithIcon.dcm compressed_icon.dcm

๐Ÿฆ‹ Generating an Icon ๐Ÿฆ‹

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:

$ gdcmconv --raw --generate-icon gdcmData/test.acr test_icon.dcm

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:

$ gdcmconv --raw --generate-icon --icon-minmax 0,192 gdcmData/012345.002.050.dcm icon_minmax.dcm

๐Ÿ’œ Changing the planar Configuration ๐Ÿ’œ

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:

$ gdcmconv --raw --planar-configuration 0 compressed.dcm uncompressed1.dcm

To reinvert the planar configuration of file uncompressed1.dcm, simply do:

$ gdcmconv --raw --planar-configuration 1 uncompressed1.dcm uncompressed2.dcm

โœจ LOSSLESS CONVERSION โœจ

Okay bestie, we need to talk about the word "lossless" real quick because it's giving ambiguous and we can't have that. ๐Ÿ˜ญ

When people say lossless conversion they're being a lil vague, and you need to understand why. To get a higher compression ratio, the RGB color space is usually not used โ€” instead everyone reaches for a YBR one. But here's the tea: switching from one color space to the other is (at the bit level) not lossless. ๐Ÿ’€ Not even a little.

So if you want the full lore, go look at what the true lossless transformations actually are, as described here:

http://gdcm.sourceforge.net/wiki/index.php/Color_Space_Transformations

๐ŸŽ€ QUALITY CONTROL ๐ŸŽ€

One important part when using gdcmconv is having a way to quality control the output. Like, you gotta check your work, bestie. ๐Ÿ‘‘

You can use a 3rd party tool to check that the output of gdcmconv is correct. Very demure, very mindful. ๐Ÿซถ

๐ŸŒˆ DCMTK / dicom3tools

Using another DICOM implementation โ€” such as the one from DCMTK or dicom3tools โ€” can be a good process to check the output of gdcmconv. Cross-checking slays. โœจ

  • For DCMTK use: dcmdump
  • For dicom3tools use: dcdump

For reference, gdcmconv --raw will act as dcmdjpeg +cn +px, since it never tries to convert color space. That's the whole point, iykyk. ๐Ÿ’…

๐Ÿฆ‹ VIM: vimdiff

You can set up your favorite editor to compare the output, for instance in vim:

autocmd BufReadPre *.dcm set ro
autocmd BufReadPost *.dcm silent %!dcmdump -M +uc "%"

then simply do:

$ vimdiff input.dcm output.dcm

๐Ÿ“ vbindiff

On UNIX you can visually compare binary files using the vbindiff command:

$ vbindiff input.dcm output.dcm

Literally so satisfying to watch side-by-side. ๐Ÿ˜Œ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

gdcmdump(1), gdcmraw(1), gdcminfo(1), gdcmdiff(1)

(The whole friend group, fr fr. Go say hi. ๐Ÿ’–)


๐Ÿ’œ AUTHOR ๐Ÿ’œ

Mathieu Malaterre Main developer

(Yes, the icon himself. ๐ŸŽ€)


Copyright ยฉ 2006, 2011 Mathieu Malaterre


And that's a wrap on gdcmconv, bestie!! You made it to the end of the manual โ€” proud of you fr fr. ๐Ÿซถโœจ

This beauty is from GDCM 3.0.24, dated 12/25/2025. Christmas day release, main character energy honestly. ๐ŸŽ„๐Ÿ‘‘ Now go convert some DICOMs and slay. ๐Ÿ’…

๐Ÿ“ฆ where this page comes from