Skip to Content
go-dicom(3)
Command line

convert

Writes a DICOM file in another format: DICOM JSON, DICOM XML, a flat JSON or CSV listing of its elements, a NIfTI-1 volume, or a PNG or JPEG picture.

When to use it

Use convert to hand a file's contents to a tool that does not read DICOM: a picture for a report or a web page, a listing for a spreadsheet, NIfTI for analysis software, or DICOM JSON and XML for a DICOMweb client or a script.

DICOM JSON (--format dicom-json) and DICOM XML (--format dicom-xml) hold the whole data set and can be read back into a file with create. The json and csv formats are flat listings for reading; they leave out sequences and binary values and cannot be read back.

A picture holds pixels only, but text burned into the image is still in it. To hand a picture on, use share, which refuses an image that may hold burned-in text unless told where it is.

The closest dcmtk tools are dcm2json, dcm2xml --native-format and dcm2pnm / dcmj2pnm.

Examples

A picture, with a window

go-dicom convert ct.dcm ct.png --format png --window 40,400
Wrote ct.png

--window takes center and width in the image's output units (Hounsfield units for CT). Without it the file's own window is used, or the full range of the data when there is none. The picture is what a viewer shows: lookup tables or rescale and window applied, MONOCHROME1 inverted, color converted to RGB, at 8 bits.

Every frame, or a JPEG

go-dicom convert cine.dcm frames.png --format png --frame all
go-dicom convert rgb.dcm rgb.jpg --format jpeg --quality 85
Wrote frames-0001.png
Wrote frames-0002.png
Wrote rgb.jpg

--frame counts from 1. With all, each frame goes beside the output name as name-0001.png, name-0002.png and so on. --quality applies to JPEG (default 90); PNG is lossless.

DICOM JSON, to read back later

go-dicom convert ct.dcm ct.json --format dicom-json
go-dicom convert j2k.dcm j2k.json --format dicom-json
Wrote ct.json: DICOM JSON, 258 top-level elements
Wrote j2k.json: DICOM JSON, 151 top-level elements
  its Pixel Data is compressed, in 1.2.840.10008.1.2.4.91; create it back with -syntax 1.2.840.10008.1.2.4.91

This is the PS3.18 Annex F model DICOMweb serves, binary values as InlineBinary. JSON carries no transfer syntax, so for compressed pixel data the command prints the -syntax that create needs to rebuild the file. Text is written as UTF-8, and Specific Character Set says ISO_IR 192.

DICOM XML

go-dicom convert ct.dcm ct.xml --format dicom-xml
Wrote ct.xml: Native DICOM Model XML, 258 top-level elements

The Native DICOM Model of PS3.19 Annex A, as dcm2xml --native-format writes it.

A listing, or NIfTI

go-dicom convert ct.dcm ct.csv --format csv
go-dicom convert rtdose.dcm dose.nii --format nifti
Tag,Name,VR,Length,Value
"0002,0001",File Meta Information Version,OB,2,<2 bytes>
"0002,0002",Media Storage SOP Class UID,UI,26,1.2.840.10008.5.1.4.1.1.2
…

NIfTI output is a single-file NIfTI-1 image of the decoded pixels, every frame, with pixel spacing and position taken from the file.

A smaller listing

go-dicom convert ct.dcm ct.json.z --compress
…
Compression ratio: 16.0% (23986 -> 3826 bytes)
Writing output: ct.json.z
Output size: 3826 bytes
Conversion completed successfully (compressed)!

--compress applies to json, csv and nifti. The output is a zlib stream (RFC 1950), not gzip.

Notes

Important

The format comes from --format only, never from the output's extension. The default is json: go-dicom convert ct.dcm ct.png writes JSON into ct.png.

  • --icc srgb (or adobergb, rommrgb, displayp3) converts the picture through the image's ICC profile and embeds the target profile. Without it, an image's own ICC profile is embedded as it is and the samples are not converted. A profile built from lookup tables is refused.
  • A file with no image (a structured report, say) cannot be written as PNG, JPEG or NIfTI: Error: convert: the instance has no image to convert. NIfTI also refuses color images at more than 8 bits per sample.
  • --compress is refused for dicom-json, dicom-xml, png and jpeg.
  • The input is never changed. Exit status is 0 on success and 1 on any error.

See also

Options

COMMAND: convert - Convert DICOM to other formats

USAGE:
  go-dicom convert <input> <output> [options]

DESCRIPTION:
  Convert a DICOM file to another format for integration with other tools
  or for data analysis.

OPTIONS:
  -h, --help          Show help for this command
  --format <format>   Output format: json, dicom-json, dicom-xml, csv, nifti,
                      png, jpeg (default: json)
  --compress          Apply compression to output (json, csv, nifti)

DICOM JSON (--format dicom-json):
  The DICOM JSON Model of PS3.18 Annex F, as DICOMweb serves it: every
  element, sequences and binary values (as InlineBinary) included, which
  "go-dicom create" reads back into a file. "json" is a flat rendering for
  reading, without sequences or binary values, and cannot be read back.

DICOM XML (--format dicom-xml):
  The Native DICOM Model of PS3.19 Annex A, as dcmtk's dcm2xml
  --native-format writes it: the same data set as dicom-json, in XML, with
  DS and IS kept as written. "go-dicom create" reads it back into a file.

IMAGES (--format png or jpeg):
  --window <c,w>      Window center and width, in the image's output units
                      (Hounsfield units for CT). Default: the file's own
                      window, or the full range of the data when it has none.
  --frame <n|all>     The frame to write, counted from 1 (default: 1). With
                      "all", each frame is written beside the output name as
                      name-0001.png, name-0002.png and so on.
  --quality <1-100>   JPEG quality (default: 90). PNG is lossless.
  --icc <space>       Convert the picture through the image's ICC profile
                      into srgb, adobergb, rommrgb or displayp3, and embed
                      that color space's profile instead of the image's. An
                      image without a profile is taken to be sRGB. Matrix
                      and tone curve profiles are applied; one built from
                      lookup tables is refused.

  The image is what a viewer shows: through the file's lookup tables or its
  rescale and window, inverted where MONOCHROME1 or Presentation LUT Shape
  says, and color converted to RGB, at 8 bits. An image's ICC profile goes
  into the PNG or JPEG as it is, so a viewer that manages color shows it as
  the image means; the samples are not converted unless --icc asks. Apart
  from that profile, which describes a device, it holds pixels only, so
  none of the file's attributes are in it. Text burned into the picture
  itself still is.

EXAMPLES:
  go-dicom convert patient.dcm output.json
  go-dicom convert patient.dcm output.json --format json
  go-dicom convert patient.dcm dicom.json --format dicom-json
  go-dicom convert patient.dcm dicom.xml --format dicom-xml
  go-dicom convert patient.dcm data.csv --format csv
  go-dicom convert patient.dcm image.nii --format nifti
  go-dicom convert ct.dcm ct.png --format png --window 40,400
  go-dicom convert cine.dcm frame.jpg --format jpeg --frame all
  go-dicom convert slide.dcm slide.png --format png --icc srgb
  go-dicom convert patient.dcm output.json --compress
  go-dicom convert -h

On this page