img2dcm(1)

🌸 NAME 🌸

hey bestie, welcome to img2dcm(1) from OFFIS DCMTK πŸ’– the whole vibe is: Convert standard image formats into DICOM format. that's the NAME line, and it ate.

✨ SYNOPSIS ✨

img2dcm [options] imgfile-in... dcmfile-out

πŸ’… DESCRIPTION πŸ’…

okay so img2dcm is literally your conversion bestie from a standard image format like JPEG (including JPEG-LS) or BMP into DICOM πŸŽ€ Different output SOP Classes can be selected, which is iconic. The extra info (patients, series, etc.) stored in the DICOM output file can be extracted from other DICOM files that serve as a β€œtemplate” for the resulting DICOM object. and yes, img2dcm can also be configured to invent missing DICOM type 1 and type 2 attributes so it works even without any template dataset. no cap. πŸ’…

πŸŽ€ PARAMETERS πŸŽ€

  • imgfile-in β€” image input filename
  • dcmfile-out β€” DICOM output filename ("-" for stdout)

πŸ¦‹ OPTIONS πŸ¦‹

🌈 general options 🌈

  • -h, --help β€” print this help text and exit
  • --version β€” print version information and exit
  • --arguments β€” print expanded command line arguments
  • -q, --quiet β€” quiet mode, print no warnings and errors
  • -v, --verbose β€” verbose mode, print processing details
  • -d, --debug β€” debug mode, print debug information
  • -ll, --log-level β€” [l]evel: string constant β€” levels are fatal, error, warn, info, debug, trace; use level l for the logger
  • -lc, --log-config β€” [f]ilename: string β€” use config file f for the logger

🌸 input options 🌸

general:

  • -i, --input-format β€” [i]nput file format: string β€” supported formats: JPEG (default), BMP
  • -df, --dataset-from β€” [f]ilename: string β€” use dataset from DICOM file f
  • -dx, --dataset-from-xml β€” [f]ilename: string β€” use dataset from XML file f
  • -stf, --study-from β€” [f]ilename: string β€” read patient/study from DICOM file f
  • -sef, --series-from β€” [f]ilename: string β€” read patient/study/series from DICOM file f
  • -ii, --instance-inc β€” increase instance number read from DICOM file

JPEG format:

  • -dp, --disable-progr β€” disable support for progressive JPEG
  • -de, --disable-ext β€” disable support for extended sequential JPEG
  • -jf, --insist-on-jfif β€” insist on JFIF header existence
  • -ka, --keep-appn β€” keep APPn sections (except JFIF)
  • --keep-app β€” [n]umber: integer (0..15) β€” keep single APPn marker, e.g. 14 (Adobe)
  • -rc, --remove-com β€” remove COM segment

XML validation:

  • +Vd, --validate-document β€” validate XML document against DTD
  • +Vn, --check-namespace β€” check XML namespace in document root

πŸ“ processing options πŸ“

attribute checking:

  • --do-checks β€” enable attribute validity checking (default)
  • --no-checks β€” disable attribute validity checking
  • +i2, --insert-type2 β€” insert missing type 2 attributes (default) (only with --do-checks)
  • -i2, --no-type2-insert β€” do not insert missing type 2 attributes (only with --do-checks)
  • +i1, --invent-type1 β€” invent missing type 1 attributes (default) (only with --do-checks)
  • -i1, --no-type1-invent β€” do not invent missing type 1 attributes (only with --do-checks)

character set conversion of study/series file:

  • -Ct, --transliterate β€” try to approximate characters that cannot be represented through similar looking characters
  • -Cd, --discard-illegal β€” discard characters that cannot be represented in destination character set

other processing options:

  • -k, --key β€” [k]ey: gggg,eeee="str", path or dictionary name="str" β€” add further attribute

πŸ‘‘ output options πŸ‘‘

target SOP class:

  • -sc, --sec-capture β€” write Secondary Capture SOP class (default)
  • -nsc, --new-sc β€” write new Secondary Capture SOP classes
  • -vlp, --vl-photo β€” write Visible Light Photographic SOP class
  • -oph, --oph-photo β€” write Ophthalmic Photography SOP classes

output file format:

  • +F, --write-file β€” write file format (default)
  • -F, --write-dataset β€” write data set without file meta information

group length encoding:

  • +g=, --group-length-recalc β€” recalculate group lengths if present (default)
  • +g, --group-length-create β€” always write with group length elements
  • -g, --group-length-remove β€” always write without group length elements

length encoding in sequences and items:

  • +e, --length-explicit β€” write with explicit lengths (default)
  • -e, --length-undefined β€” write with undefined lengths

data set trailing padding (not with --write-dataset):

  • -p, --padding-off β€” no padding (implicit if --write-dataset)
  • +p, --padding-create β€” [f]ile-pad [i]tem-pad: integer β€” align file on multiple of f bytes and items on multiple of i bytes

πŸ’œ NOTES πŸ’œ

🌟 Attribute Sources 🌟

For converting a general image format into DICOM format, the img2dcm application may be fed with some additional input for filling mandatory (and optional) attributes in the new DICOM file like patient, study and series information 🫢 This information can be collected using different approaches, which can be combined and are applied to the result file in the following order:

  • Using the --dataset-from option img2dcm is forced to import attributes from an existing DICOM file. The given DICOM file is fully imported and serves as the basis for all further export operations. As an exception, the SOP Instance UID is not copied by this option. Also image related data like Rows, Columns etc. is exchanged during conversion. Note that img2dcm does not check any other attribute values for validity, e.g. it does not look into sequences to adapt any attributes to the new object (referenced images etc.). Therefore, it is recommended to use the templates in the data directory for (old) SC and VLP objects. See also section β€œInput Templates”. As an alternative to option --dataset-from the mutually exclusive option --dataset-from-xml can be used. In this case, however, the file must contain XML data in the format as produced by dcm2xml.
  • The --study-from and --series-from options can be used to import patient, study and series information from an existing DICOM file. If --series-from is specified, then the given DICOM file is opened by img2dcm and all mandatory information down to the series level is imported. Note that this includes patient, study and series information. In case of --study-from, the series information is excluded. Using --study-from and --series-from at the same time does make sense. If both options are provided on the command line, the rightmost option wins. The following attributes are taken over:
    • Patient Level:
      • Patient's Name
      • Patient ID
      • Patient's Sex
      • Patient's Birth Date
      • Specific Character Set
    • Study Level:
      • Study Instance UID
      • Study Date
      • Study Time
      • Referring Physician's Name
      • Study ID
      • Accession Number
    • Series Level (only in case of option --series-from):
      • Series Instance UID
      • Series Number
      • Manufacturer
  • With the --insert-type2 and --invent-type1 options (both enabled per default), missing attributes (type 2 attributes) and/or missing attribute values (for type 1 attributes) are automatically added and invented by img2dcm. Please note that these options are only evaluated if option --do-checks is enabled (default). If the --no-checks options is enabled, no automatic attribute insertion will take place.
  • The --key option can be used to add further attributes to the DICOM output file. It is also possible to specify sequences, items and nested attributes using the --key option. In these cases, a special β€œpath” notation has to be used. Details on this path notation can be found in the documentation of dcmodify. The --key option can be present more than once. The value part (after the '=') may be absent causing the attribute to be set with zero length. Please be advised that the --key option is applied at the very end, just before saving the DICOM file, so there is no value checking whatsoever. 😭

🌟 UIDs 🌟

New Study and Series Instance UIDs are generated if necessary after applying the --study-from and --series-from options. If Study Instance UID or Series Instance UID are not present after these steps, they are newly generated, independently from each other.

A contrary behavior is chosen for the SOP Instance UID that one could expect to be taken over when using the --dataset-from or --dataset-from-xml option. This is not the case, the SOP Instance UID is not copied to the new object. This should be the desirable behavior for most use cases. However, if a certain SOP Instance UID should be inserted into the new object, the --key option should be used.

🌟 Input Templates 🌟

For supporting the conversion into DICOM, img2dcm comes with some pre-defined templates which can be used for the --dataset-from option (see sample files SC.dump and VLP.dump). These templates should be filled with the desired values and then must be dumped (converted) to a DICOM file before actually being used with img2dcm. Use dump2dcm to convert the dump to DICOM. Example:

dump2dcm SC.dump SC.dcm

For Ophthalmic Photography images, XML templates are provided (see sample file OP_template_utf_8.xml and OP_template_latin_1.xml). πŸ¦‹

It is possible to use any DICOM file as a template. Please note that the complete DICOM dataset is imported; hence, it should be assured that only attributes are present which should be part of the constructed DICOM object. The SOP Class UID and the Pixel Data attributes (including attributes like Rows, Columns etc.) are not copied but replaced by img2dcm during conversion.

🌟 Multiframe Images 🌟

It is possible to convert multiple input files into one DICOM multiframe image if the selected DICOM SOP class supports multiframe. In particular, the Multi-frame Secondary Capture SOP Classes support this feature. They are selected through the --new-sc command line option. πŸ’…

πŸ’– Character Sets πŸ’–

okay bestie, character-set tea time β˜•βœ¨. When an input template is loaded using --dataset-from or --dataset-from-xml, the specific character set of that template is used for the generated DICOM file. If the --study-from or --series-from options are used additionally, img2dcm will try to convert the character set of these attributes to that of the template, and will report an error if that is not possible.

If the --study-from or --series-from options are used without a template, the specific character set of this source is used for the generated DICOM file. Any keys specified on the command line with the --key option are treated as raw bytes and override any attributes that may already be present due to a template or study/series file. Therefore, care should be taken to not specify a specific character set on the command line if one might be loaded from another file. It is also the user's responsibility to ensure that attribute values specified on the command line use the correct encoding, as no conversion will take place before the values are stored in the DICOM file.

bestie pls don't raw-byte your way into an encoding mess 😭 the command line does not auto-convert for you.

πŸ–ΌοΈ Input Plugins πŸ–ΌοΈ

The img2dcm application currently supports the JPEG, JPEG-LS and the BMP image format as input. Iconic little trio honestly 🫢.

🌈 JPEG Input Plugin 🌈

For JPEG, the original JPEG from the source file is not decoded but extracted and slightly transformed (e.g. JFIF header is cut off) to allow fast conversion of even big JPEG files without the need of decoding and re-encoding. The JPEG plugin chooses the necessary output transfer syntax automatically depending on the actual encoding of the data inside the JPEG file. Therefore, the following Transfer Syntaxes (and their corresponding JPEG encodings) are used by the JPEG plugin:

  • JPEG Coding Process 1 β€” Baseline, Lossy, Non-Hierarchical, Sequential, DCT, Huffman, 8 Bit. Transfer Syntax UID = 1.2.840.10008.1.2.4.50
  • JPEG Coding Process 2 (8-bit) and 4 (12-bit) β€” Extended, Lossy, Non-Hierarchical, Sequential, DCT, Huffman, 8/12 Bit. Transfer Syntax UID = 1.2.840.10008.1.2.4.51
  • JPEG Coding Process 10 (8-bit) and 12 (12-bit) β€” Full Progression, lossy, Non-Hierarch., Progressive, DCT, Huffman, 8/12 Bit. Transfer Syntax UID = 1.2.840.10008.1.2.4.55

Color and grayscale images are supported πŸ’….

The support for the Extended JPEG Transfer Syntax can be disabled (--disable-ext option) as well as the support for the (retired) Progressive JPEG Transfer Syntax (--disable-progr option). JPEG lossless encoding as well as any arithmetic or hierarchical JPEG encoding modes are not supported by the plugin.

JFIF (JPEG File Interchange Format) information facilitates optional APPn markers in a JPEG file. Many digital cameras do not integrate such JFIF information into the JPEG output they create. For example, JFIF contains information about the pixel aspect ratio of the compressed image. If you want the img2dcm application to insist on a JFIF header in the JPEG stream, you can use the option --insist-on-jfif which will abort if no JFIF information can be found. By default, missing JFIF information is ignored.

For DICOM it is kind of a "gray zone", whether the integration of JFIF (or any other APPn) data into the DICOM object's internal JPEG stream is allowed or not. However, the most reliable approach is to cut those markers and their information off the JPEG stream. This approach is also taken by the img2dcm application. By default, all APPn markers are cut off from the original JPEG stream. However, if you want to keep other APPn markers than JFIF (e.g. EXIF information) inside the DICOM stream, the option --keep-appn does the trick ✨. It should also be slightly faster than cutting off APPn information, because it is not necessary to scan the whole JPEG stream for such data. As stated before, JFIF information is always removed by img2dcm. However, when using this option, the APP2 marker is retained, but img2dcm does not create an equivalent ICC Profile (0028,2000) attribute. In particular, it does not embed an sRGB ICC Profile for untagged or unprofiled JFIF inputs, which may be necessary for a calibrated display.

If you only want to retain specific APPn markers instead of all of them, the option --keep-app followed by the marker number (0 to 15) can be used, and it may be repeated to keep several markers. The marker is kept by its number, irrespective of its actual application identifier. A typical use case is keeping APP14 (--keep-app 14), which usually holds the Adobe color transform marker whose transform flag some JPEG decoders and viewers rely on to decide whether a YCbCr to RGB conversion has to be applied during decoding. Without that marker such decoders may render the image with wrong colors, while keeping it is harmless otherwise. Note that the default behavior (removing all APPn markers) is unchanged.

πŸ¦‹ JPEG-LS Input Plugin πŸ¦‹

The JPEG-LS plugin has been integrated directly into the main JPEG plugin. There is no need for the user to explicitly state in advance if input is JPEG or JPEG-LS. lowkey convenient 🫢.

For JPEG-LS, the original JPEG-LS from the source file is not decoded but extracted and slightly transformed (e. g. APP8 marker is cut off) to allow fast conversion of even big JPEG-LS files without the need of decoding and re-encoding.

The JPEG-LS plugin chooses the necessary output transfer syntax automatically depending on the actual encoding of the data inside the JPEG-LS file. Therefore, the following Transfer Syntaxes (and their corresponding JPEG-LS encodings) are used by the JPEG-LS plugin:

  • JPEG-LS Lossless Image Compression β€” Transfer Syntax UID = 1.2.840.10008.1.2.4.80
  • JPEG-LS Lossy (Near-Lossless) Image Compression β€” Transfer Syntax UID = 1.2.840.10008.1.2.4.81

Color and grayscale images are supported. CP-1843 enforce that the value of Planar Configuration (0028,0006) is irrelevant since the manner of encoding components is specified in the JPEG-LS bit stream as component, line or sample interleaved, hence it shall be set to 0. Since no color transformation specific for JPEG-LS is currently defined in DICOM, it is assumed that the JPEG-LS stream is encoded in RGB color space.

For DICOM it is clear that SPIFF header should not be present in the DICOM object's internal JPEG-LS stream. The plugin will simply reject any input JPEG-LS file containing a SPIFF header at marker APP8.

By default, all APPn markers are cut off from the original JPEG-LS stream. However, if you want to keep APPn markers (e.g. APP8/HP color transform information, aka 'mrfx') inside the DICOM stream, the option --keep-appn does the trick. Pay attention that the plugin will check the actual color transform specified in the APP8/HP marker. Since DICOM does not allow any color transform to be specified in the APP8 marker, only a value of 0 (no color transform) is accepted.

πŸŽ€ BMP Input Plugin πŸŽ€

img2dcm supports BMP as input format. However, so far only the most common BMP images are supported. In particular, BMP images which use bit fields or run length encoding will be rejected. Such images are uncommon. Input images will either be converted into a DICOM image with RGB color model and a bit depth of 24, or into an image with MONOCHROME2 color model and 8 bits per pixel. There are no specific options for fine-tuning BMP format conversion.

πŸ‘‘ Output Plugins πŸ‘‘

The desired output SOP Class can be selected on the command line. Currently, export plugins for the Secondary Capture Image SOP Class (default, option -sc), the Multi-frame Secondary Capture Image SOP Classes (option -nsc), Visible Light Photographic Image SOP Class (option -vl), and the Ophthalmic Photography Image SOP Classes (option -oph) are available. Please note that the first one is deprecated according to the DICOM standard but is selected as a default because it is widely supported. Future versions of img2dcm might provide further output plugins for other SOP Classes.

For the new Secondary Capture SOP Classes, it is not possible to specify which specific SOP Class should be used for output. That is because these new SOP classes are differentiated from each other by color depth (1/8/16) and the fact whether the image is black/white or color. That is why img2dcm decides during conversion which output SOP Class is suitable for a given source image.


✨ EXAMPLES ✨

Here are some examples that show how the img2dcm application can be used. Scenario era πŸ’…βœ¨.

img2dcm image.jpg out.dcm

Read JPEG file "image.jpg", convert to the old Secondary Capture SOP Class and save the result to DICOM file "out.dcm". This is the easiest way of using img2dcm. Any type 1 and type 2 attributes required for writing valid objects of this SOP Class are inserted automatically.

img2dcm -i BMP image.bmp out.dcm

Same as above but tells img2dcm to read a BMP file instead of JPEG.

img2dcm image.jpg out.dcm -vlp -k "PatientName=Bond^James"

Same as first example, but writes Visible Light Photographic Image object to "out.dcm" and sets PatientName to "Bond^James" which otherwise would be left empty.

img2dcm image.jpg out.dcm --series-from template.dcm -k "PatientName=Bond^James"

Same as 1), but imports patient/study/series information from DICOM file "template.dcm". Please note that attribute PatientName will contain "Bond^James" at the end, any value from "template.dcm" will be overwritten. That is, because the -k option is applied at the very end of the conversion pipeline (see above).

img2dcm image.jpg out.dcm --no-checks

Same as 1), but does not perform any attribute checking and no type 1 and type 2 attribute insertion! So in this case, an invalid DICOM object would be generated. This can be interesting if the output file is not meant to be completed but will undergo further transformations, e.g. adding attributes using dcmodify. Only use option --no-checks if you know what you are doing!

bestie this one is giving risky behavior 😭 invalid DICOM object fr fr, do not casually ship it.
img2dcm image.jpg out.dcm --no-type1-invent

Same as 1), but does not insert missing type 1 attributes and/or their values. Type 2 attributes will be inserted. Note that in this case it must be assured that all type 1 attributes are provided by other means, i.e. by adding them with the --key option. Otherwise, img2dcm will report an error and will stop converting.

img2dcm image.jpg out.dcm --keep-appn --insist-on-jfif

Same as 1), but takes over APPn information like EXIF into the DICOM object's resulting JPEG stream. Further, --insist-on-jfif will force img2dcm to abort if no JFIF information is existent in the source file.

img2dcm image1.jpg image2.jpg out.dcm --new-sc

Read the JPEG files "image1.jpg" and "image2.jpg", convert to a multiframe image of the appropriate Multi-frame Secondary Capture SOP Class, and save the result to DICOM file "out.dcm".

🌸 LOGGING 🌸

okay so listen bestie, the amount of logging tea that gets spilled is literally up to you πŸ’…. You can set the level of logging output for all the various command line tools and the underlying libraries β€” your call, your vibe.

By default? Only errors and warnings get written to the standard error stream. That's it, that's the baseline, very demure, very mindful ✨.

  • --verbose β€” turns it up a notch so you also get informational messages, like processing details. useful!!
  • --debug β€” now we're getting details on the internal activity, e.g. for debugging purposes πŸ”
  • --log-level β€” pick other logging levels with this one, lowkey the main character of log control πŸ‘‘

And in --quiet mode only fatal errors are reported. Heads up though 🫢: in such very severe error events, the application will usually terminate. so like… yeah, it's giving final boss energy, no cap 😭.

If you want the full lore on the different logging levels, go see the documentation of module "oflog".

Now β€” if the logging output should be written to file (optionally with logfile rotation), or to syslog (Unix), or to the event log (Windows), that's what --log-config is for 🌈. This configuration file also lets you direct only certain messages to a particular output stream, and filter certain messages based on the module or application where they are generated. Iconic. An example configuration file is provided in <etcdir>/logger.cfg πŸŽ€.


πŸ¦‹ COMMAND LINE πŸ¦‹

All command line tools use the following notation for parameters, bestie, memorize it:

  • square brackets enclose optional values (0-1)
  • three trailing dots indicate that multiple values are allowed (1-n)
  • a combination of both means 0 to n values

Command line options are distinguished from parameters by a leading '+' or '-' sign, respectively. Usually, order and position of command line options are arbitrary (i.e. they can appear anywhere) ✨. However β€” if options are mutually exclusive, the rightmost appearance is used. This behavior conforms to the standard evaluation rules of common Unix shells. it's giving rules are rules πŸ’….

In addition, one or more command files can be specified using an '@' sign as a prefix to the filename (e.g. @command.txt) πŸ“. Such a command argument is replaced by the content of the corresponding text file (multiple whitespaces are treated as a single separator unless they appear between two quotation marks) prior to any further evaluation. Little heads up though πŸ™ˆ: please note that a command file cannot contain another command file. This simple but effective approach allows one to summarize common combinations of options/parameters and avoids longish and confusing command lines β€” an example is provided in file <datadir>/dumppat.txt. slay, honestly πŸ‘‘


πŸ’œ ENVIRONMENT πŸ’œ

The img2dcm utility will attempt to load DICOM data dictionaries specified in the DCMDICTPATH environment variable 🧚.

By default, i.e. if the DCMDICTPATH environment variable is not set, the file <datadir>/dicom.dic will be loaded β€” unless the dictionary is built into the application (default for Windows).

ngl bestie, the default behavior should be preferred πŸ’–, and the DCMDICTPATH environment variable only used when alternative data dictionaries are required.

The DCMDICTPATH environment variable has the same format as the Unix shell PATH variable in that a colon (":") separates entries. On Windows systems, a semicolon (";") is used as a separator. The data dictionary code will attempt to load each file specified in the DCMDICTPATH environment variable. And yeah β€” it is an error if no data dictionary can be loaded 😭.


πŸŽ€ FILES πŸŽ€

  • <datadir>/SC.dump β€” Sample dump file for Secondary Capture images
  • <datadir>/VLP.dump β€” Sample dump file for Visible Light Photographic images
  • <datadir>/OP_template.xml β€” Sample XML template for Ophthalmic Photography images

⭐ SEE ALSO ⭐

dcm2pnm(1), dcmj2pnm(1), dump2dcm(1), dcmconv(1), dcmodify(1), dcm2xml(1)

go read those too, iykyk 🫢


Copyright (C) 2007-2026 by OFFIS e.V., Escherweg 2, 26121 Oldenburg, Germany.


and that's the whole page, bestie!! πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

This little masterpiece is Version 3.7.1, dated Sat Oct 17 2026 09:34:01 β€” so go forth, convert those images, and remember: the vibe check is eternal, the facts are unchanged, periodt πŸ’…

πŸ“¦ where this page comes from