create
Makes a DICOM file from DICOM JSON, from Native DICOM Model XML, from a PNG or JPEG picture (as a Secondary Capture image), or from a PDF (as an Encapsulated PDF).
When to use it
Use create to:
- turn DICOM JSON back into files: what convert
--format dicom-jsonwrote, or what a DICOMweb server returned for wado-metadata, after editing it in a script; - read DICOM XML written by
convert --format dicom-xmlor dcmtk'sdcm2xml --native-format; - add a screenshot, a photo or a scanned report to a patient's study, joined
to it by
-templateor by the patient and study flags.
It does not make images of other IODs from pictures, and it does not fetch
anything: a JSON BulkDataURI that is http: or https: is refused.
The closest tools are dcmtk's xml2dcm, img2dcm and pdf2dcm, and
pydicom's Dataset.from_json.
Examples
DICOM JSON back to a file
go-dicom convert ct.dcm ct.json --format dicom-json
go-dicom create ct.json copy.dcmWrote ct.json: DICOM JSON, 258 top-level elements
Wrote copy.dcm: from DICOM JSON, 1.2.840.10008.1.2.1JSON writes DS and IS values as numbers, so a value such as 5.000000 comes
back as 5. DICOM XML keeps them as written:
go-dicom create ct.xml copy-xml.dcmWrote copy-xml.dcm: from the Native DICOM Model, 1.2.840.10008.1.2.1Compressed pixel data needs its syntax
go-dicom create j2k.json j2k-copy.dcm
go-dicom create -syntax 1.2.840.10008.1.2.4.91 j2k.json j2k-copy.dcmError: create: j2k.json: its Pixel Data is encapsulated fragments; give -syntax with the transfer syntax they are in
Wrote j2k-copy.dcm: from DICOM JSON, 1.2.840.10008.1.2.4.91JSON carries no transfer syntax; convert prints the -syntax to give when
it writes such a file.
An array of instances, one file each
go-dicom create study.json instances/Wrote instances/1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322.dcm: from DICOM JSON, 1.2.840.10008.1.2.1
Wrote instances/1.3.6.1.4.1.5962.1.1.4.1.1.20040826185059.5457.dcm: from DICOM JSON, 1.2.840.10008.1.2.1
Wrote 2 files to instances/Each file is named <SOP Instance UID>.dcm, as wado names them. Two
objects with one UID, or one object that is refused, make no file at all.
A screenshot into a patient's study
go-dicom create -template ct.dcm ct.png sc.dcmWrote sc.dcm: a Secondary Capture image from a PNG, 1.2.840.10008.1.2.1-template copies the Patient module and the General Study attributes of
the file named, so the new image sits in that study, in a new series. A PNG
is decoded (gray as MONOCHROME2, color and palette as RGB); one that is
not fully opaque is refused.
A photo, with patient details given on the line
go-dicom create -patient-name 'Doe^Jane' -patient-id 12345 rgb.jpg photo.dcmWrote photo.dcm: a Secondary Capture image from a JPEG, 1.2.840.10008.1.2.4.50A JPEG goes in as it is, in JPEG Baseline, with nothing decoded or encoded again, and is recorded as lossily compressed. Only a baseline 8-bit JPEG fits; a progressive one is refused.
A PDF report
go-dicom create -template ct.dcm -title 'Radiology report' report.pdf report-pdf.dcmWrote report-pdf.dcm: an Encapsulated PDF, 1.2.840.10008.1.2.1The document's bytes go in as they are. -burned-in no records that the
document does not identify the patient (the default is yes).
Notes
- The source type comes from its extension (
.json,.xml,.png,.jpg,.jpeg,.pdf), or from-from json|xml|picture|pdf. - The patient and study flags (
-patient-name,-patient-id,-birth-date,-sex,-study-uid,-study-id,-accession,-study-date,-study-time,-study-description,-referring-physician,-series-description,-modality) replace what the template or the JSON gives. What nothing gives is present and empty, as Type 2 asks. - A picture or PDF gets new Series and SOP Instance UIDs (
2.25UUID UIDs), and a new Study Instance UID unless-templateor-study-uidgives one. - A JSON
BulkDataURIis read only for a binary VR, only as afile:URI or a path, and only from inside-bulk-dir(default: the JSON file's directory). - Exit status is 0 when every file was written, 1 otherwise.
See also
Options
Make a DICOM file from DICOM JSON, a PNG or JPEG picture, or a PDF
USAGE:
go-dicom create [options] <source> <output>
go-dicom create [options] <array.json> <directory>
What the source is comes from its extension (.json, .xml, .png, .jpg,
.jpeg, .pdf), or from -from.
SOURCES:
json A DICOM JSON object (PS3.18 Annex F), or an array of them, as a
DICOMweb metadata response or 'convert --format dicom-json'
writes it. An array of one object makes <output>, as an object
does. An array of more makes one file for each, in the directory
<output> (made if it is not there), named <SOP Instance UID>.dcm
as 'wado' names them; two objects with one UID, or an object that
is refused, make no file at all. Binary values come from
InlineBinary, or from a BulkDataURI that is a file: URI or a path
(relative to -bulk-dir, by default the JSON file's directory):
the whole file is the value, in the little endian a data set
holds it, and for encapsulated Pixel Data it holds the fragments
with their item headers. A BulkDataURI is read only for a binary
VR, and only from inside -bulk-dir, links followed. A http: or
https: BulkDataURI is refused and not fetched: a command that
makes a file does not reach the network unasked. Fetch it first
(curl) and name the file. The JSON has no transfer syntax,
so its pixel data is taken as native unless -syntax names another
(one for every object). A missing SOP Instance UID is made;
everything else is the JSON's.
xml A Native DICOM Model document (PS3.19 Annex A), as
'convert --format dicom-xml' or dcmtk's dcm2xml --native-format
writes it: one data set, read as a DICOM JSON object is. A
BulkData uri is read as a BulkDataURI is, from -bulk-dir; a
BulkData uuid, which names no file, is refused.
picture A Secondary Capture image (PS3.3 A.8.1). A PNG is decoded: gray
at 8 or 16 bits is MONOCHROME2, color and palette images RGB, and
an image that is not fully opaque is refused, since DICOM has no
transparency. A JPEG is put in the file as it is, compressed, in
JPEG Baseline (1.2.840.10008.1.2.4.50), with nothing decoded or
encoded again, and recorded as lossily compressed; only a baseline
8-bit JPEG fits that syntax, and a progressive one is refused.
pdf An Encapsulated PDF (PS3.3 A.45.1), the document's bytes as they
are, its length in Encapsulated Document Length.
OPTIONS:
-from json|xml|picture|pdf
What the source is, when the extension does not say.
-template <file.dcm> Join the patient and study of this file: its
Patient module (group 0010) and its General Study
attributes are copied.
-syntax <uid> For json and xml: the transfer syntax of its pixel
data.
-bulk-dir <dir> For json and xml: the directory a BulkDataURI may
name a file in (default: the source's directory).
-title <text> For pdf: Document Title (default: the file's name).
-burned-in yes|no For pdf: whether the document identifies the patient
(Burned In Annotation, Type 1; default yes).
-h, -help Show this help message
PATIENT AND STUDY (each replaces the template's or the JSON's value):
-patient-name, -patient-id, -birth-date, -sex, -study-uid, -study-id,
-accession, -study-date, -study-time, -study-description,
-referring-physician, -series-description, -modality
A picture or a PDF is a new instance in a new series: Series and SOP
Instance UIDs are made with the library's generator (2.25 UUID UIDs), and
so is a Study Instance UID when neither -template nor -study-uid gives
one. Patient and study attributes nothing gives are present and empty, as
their Type 2 asks.
EXAMPLES:
go-dicom convert scan.dcm scan.json --format dicom-json
go-dicom create scan.json copy.dcm
go-dicom wado -study 1.2.840.1 -metadata <url> > study.json
go-dicom create study.json instances/ # one file for each instance
go-dicom create -template ct.dcm screenshot.png sc.dcm
go-dicom create -patient-name 'Doe^Jane' -patient-id 12345 photo.jpg sc.dcm
go-dicom create -template ct.dcm -title 'Radiology report' report.pdf report.dcm