GDCMIMG(1)
πΈ GDCMIMG(1) β DICOM Manipulation πΈ
okay so this is the gdcmimg page from the DICOM Manipulation manual, and bestie, it's a whole vibe. buckle up π
β¨ NAME β¨
gdcmimg β Manipulate DICOM image file.
gdcmimg is a low level tool to allow de-/encapsulation from/to DICOM image. Lowkey important: this tool does not understand Transfer Syntax conversion. It will encapsulate the raw data as-is. That has some impact in some cases, see special warnings below π
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. no cap, that's the move π
π SYNOPSIS π
gdcmimg [options] file-in file-out
π¦ DESCRIPTION π¦
The gdcmimg command line tool can be used in two fashions:
- Converting a recognized file format into its encapsulated DICOM counterpart,
- Anonymizing a rectangular portion of a DICOM file.
two modes, both iconic, pick your fighter π«Ά
π PARAMETERS π
file-inβ input filename (non-DICOM)file-outβ DICOM output filename
β OPTIONS β
-i,--inputβ Input filename-o,--outputβ Output filename
π₯ SPECIFIC OPTIONS π₯
--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.
π FILL OPTIONS π
-R,--region %d,%dβ Region.-F,--fill %dβ Fill with pixel value specified.
π GENERAL OPTIONS π
-h,--helpprint this help text and exit-v,--versionprint version information and exit-V,--verboseverbose mode (warning+error).-W,--warningwarning mode, print warning information-E,--errorerror mode, print error information-D,--debugdebug mode, print debug information
π§ ENVIRONMENT VARIABLE π§
GDCM_ROOT_UIDβ Root UID
π SUPPORTED FILE FORMAT (APPROPRIATE FILE EXTENSION) π
gdcmimg will base it's conversion process based on the file extension. Follows the list of recognized file extension. When no extension is found, DICOM file is assumed. (literally reading the vibes off your filename β¨)
input format
- 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 β ()
output format:
- PGM β (
pgm,pnm,ppm) - DICOM β ()
For RAW file format, you should take special care of the --endian option. For the (old) JPEG file format, both the lossy and lossless format are supported, user should pay attention to the --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. (the file just tells you, slay π₯)
PNM file are supposed to be big endian (important for depth > 8)
π TYPICAL USAGE π
π€ Remove a rectangular part of the image
To fill the region [0,100]x[0,100] of a DICOM image simply do:
$ gdcmimg --fill 0 --region 0,100,0,100 -i input.dcm -o output_black.dcm
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. β οΈ
π€ Convert RAW to DICOM
Recognized extension is .raw, .rawl, .gray or .rgb (case insensitive)
$ gdcmimg --size 512,512 --depth 16 -i input.raw -o output.dcm
the image will be a Secondary Capture.
When the input is 3 component, one need to specify explicitly the Samples Per Pixel:
$ gdcmimg --size 512,512 --spp 3 input_rgb.raw output_rgb.dcm
When the filename contains .rgb as file extension output is automatically recognized as RGB no need to specify --spp
$ gdcmimg --size 512,512 input.rgb output_rgb.dcm
You can use the dd 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:
$ dd skip=108 bs=1 if=input.raw of=output.raw
.raw and .rawl extension are equivalent. You need to explicitly specify the endianness manually:
$ gdcmimg --endian MSB --size 512,512 --depth 16 -i input.raw -o output.dcm
or
$ gdcmimg --endian LSB --size 512,512 --depth 16 -i input.raw -o output.dcm
π€ Convert PGM/PNM/PPM to DICOM
Recognized extensions are .pgm, .pnm, .ppm (case insensitive)
$ gdcmimg -i input.pgm -o output.dcm
the image will be a Secondary Capture
π€ Convert RLE to DICOM
Recognized extension is .rle (case insensitive)
$ gdcmimg --size 512,512 --depth 16 -i input.rle -o output.dcm
the image will be a Secondary Capture
π€ Convert JPEG to DICOM
Recognized extensions are .jpg, .jpeg, .ljpg, .ljpeg (case insensitive)
$ gdcmimg -i input.ljpeg -o output.dcm
the image will be a Secondary Capture
π€ Convert J2K to DICOM
Recognized extensions are .j2k, .jp2, .jpc, jpx, j2c (case insensitive)
$ gdcmimg -i input.j2k -o output.dcm
the image will be a Secondary Capture.
All Pixel information (Bits Stored/Allocated...) will be derived from the image itself, and not from the command line options. (the file already knows, bestie, let it cook π)
π€ Specifying a SOP Class UID
Instead of the default Secondary Capture Image Storage, one may want to specify, say VL Photographic Image Storage.
$ gdcmimg --sop-class-uid 1.2.840.10008.5.1.4.1.1.77.1.4 input.jpg output.dcm
π€ Specifying a template DICOM file
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.
$ gdcmimg --sign 1 --template template.dcm input.jpg output.dcm
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. π
π MULTIPLE FILES π
gdcmimg handle nicely a set of files (for instance jpeg):
$ gdcmimg -C 1.2.840.10008.5.1.4.1.1.12.1 1.jpg 2.jpg 3.jpg 4.jpg output.dcm
It is important to specify an SOP Class that supports multi-frames images otherwise gdcmimg will fail. fr fr, don't skip this one π
π START OFFSET π
In some case, one may want to create a 2D slice from an arbitrary volume (e.g 3D). In which case --offset becomes handy:
$ gdcmimg --offset 4954104330 --size 1673,1673 Input3D_1673_1673_1775.raw slice_1770.dcm
β οΈ WARNING β οΈ
There are a couple of issues with gdcmimg implementation:
- For RAW file, one should pay attention that when using
--endian MSBthe Pixel Data will be encapsulated as is (not touched bygdcmimg). 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:
$ gdcmconv --raw --force input_big_endian_dlx.raw -o output_implicit_vr_little_endian.dcm
- For JFIF file and JP2 file (with header) the header is copied into the Pixel Data element which is illegal for JP2. Use
gdcmconvto properly re-encode a JP2/JFIF file into J2K/JPG.
$ gdcmimg input.jp2 output_jp2.dcm
$ gdcmconv --j2k --force output_jp2.dcm output_j2k.dcm
- For RLE file, no check is done for crossing the row boundary. It is recommended to use
gdcmconv --rleto re-encode into a proper RLE file in case of doubt. - 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:
$ gdcmconv --raw input_jpeg.dcm output_raw.dcm
π«Ά SEE ALSO π«Ά
gdcmdump(1), gdcm2vtk(1), gdcmraw(1), convert(1), dd(1)
πΈ AUTHOR πΈ
Mathieu Malaterre Main developer
π COPYRIGHT π
Copyright Β© 2006, 2011 Mathieu Malaterre
and that's the whole page bestie, go encapsulate something π¦β¨ this was GDCM 3.0.24, dated 12/25/2025 β merry reading, mwah ππ
π¦ where this page comes from
- opensuse-leap 16.0: gdcm-applications 3.0.24-bp160.2.1 Β· BSD-3-Clause
- opensuse-leap 16.0: gdcm-applications 3.0.24-bp160.2.1 Β· BSD-3-Clause
- opensuse-leap 16.0: gdcm-applications 3.0.24-bp160.2.1 Β· BSD-3-Clause
- opensuse-leap 16.0: gdcm-applications 3.0.24-bp160.2.1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms