diff
Compares two DICOM files element by element, into sequences and items, and prints what one file has that the other lacks and what both have with a different VR or value. It prints nothing when the files are equal.
When to use it
Use diff to see what a tool changed: what anonymize
removed, what modify set, what a PACS altered on the way back.
Its exit status answers "do these differ?" for a script.
It compares values as what they mean, not as bytes: the padding of a text, the character set a text is in and the byte order of a number do not make files differ. It does not compare pixels as images; Pixel Data is compared as bytes (encapsulated Pixel Data fragment by fragment), so a file and its losslessly compressed copy differ.
The closest tools are dcmtk's dcmdump run on both files and fed to
diff(1), or pydicom's Dataset comparison in a script.
Examples
What anonymize changed
go-dicom diff ct.dcm ct-anon.dcm --ignore-meta --ignore-private--- ct.dcm
+++ ct-anon.dcm
(0008,0005) Specific Character Set
- CS ISO_IR 100
+ CS ISO_IR 192
…
(0008,0201) Timezone Offset From UTC
- SH -0500
(0008,1010) Station Name
- SH CT01_OC0
+ SH
…
(0010,0010) Patient's Name
- PN CompressedSamples^CT1
+ PN
…Each difference is the element's path and name, then the element in the
first file after - and in the second after +. An element only one file
has shows one line. Inside a sequence the path names each item:
(0008,1140)[0]/(0008,1150).
Leave out what you expect to differ
go-dicom diff ct.dcm ct-jane.dcm --ignore-meta --ignore SpecificCharacterSet--- ct.dcm
+++ ct-jane.dcm
(0010,0010) Patient's Name
- PN CompressedSamples^CT1
+ PN Doe^Jane--ignore takes a keyword or a tag ((0010,0010), 0010,0010,
00100010), repeated or separated by commas, and leaves the element out at
every depth. --ignore-meta leaves out the file meta group (0002), which any
writer changes (Implementation Class UID, Implementation Version Name).
In a script
go-dicom diff -q ct.dcm scan.dcm && echo samesame-q prints nothing; the exit status is the answer.
As JSON
go-dicom diff ct.dcm ct-jane.dcm --json{
"schemaVersion": 1,
"a": "ct.dcm",
"b": "ct-jane.dcm",
"equal": false,
…
"differences": [
…
{
"path": "(0010,0010)",
"tag": "(0010,0010)",
"keyword": "PatientName",
"name": "Patient's Name",
"kind": "changed",
"differs": [
"value"
],
"a": {
"vr": "PN",
"value": "CompressedSamples^CT1",
"length": 22
},
"b": {
"vr": "PN",
"value": "Doe^Jane",
"length": 8
}
}
]
}kind is onlyInA, onlyInB or changed. The document is printed whether
or not the files differ.
Notes
- Exit status: 0 when the files are equal, 1 when they differ, 2 when the
comparison could not be made (a file missing or not DICOM, or wrong
arguments), as
diff(1)does. - Elements are matched by tag, and sequence items by position: an item inserted at the front makes every later item differ.
- A VR is compared only where both files state one; an implicit VR file states none.
- File Meta Information Group Length (0002,0000) is never compared.
- Bulk values are read in chunks and never held whole, so large files compare in little memory.
See also
Options
COMMAND: diff - Compare two DICOM files element by element
USAGE:
go-dicom diff <a> <b> [options]
DESCRIPTION:
Compare the elements of two files, into sequences and items, the file
meta group included. It reports the elements only one file has, and those
both have whose VR or value differ, and prints nothing when there is no
difference.
Elements are matched by tag, and the items of a sequence by position. A
value is compared as what it means: the padding of a text value, the
character set a text is in and the byte order of a number do not make
files differ. Bulk values, Pixel Data above all, are read from the two
files in chunks and never held whole; encapsulated Pixel Data is compared
fragment by fragment. A VR is compared where both files state one: an
implicit VR file states none. The File Meta Information Group Length
(0002,0000) is not compared: it counts the bytes of the group, which a
writer works out.
Each difference is printed as a path, then the element in the first file
after a minus and in the second after a plus. A path is the tags of the
sequences an element is in, each with its item's index:
(0008,1140)[0]/(0008,1150).
EXIT STATUS:
0 the files are equal
1 the files differ
2 the comparison could not be made: a file is missing or is not DICOM,
or the arguments are wrong
OPTIONS:
-h, --help Show help for this command
--json Print the differences as JSON, with "schemaVersion" 1,
each with its path, tag, kind (onlyInA, onlyInB or
changed), what differs ("vr", "value") and the element
as each file has it. The document is printed whether
or not the files differ; "equal" says which.
-q, --quiet Print nothing; the exit status is the answer
--ignore <tag> Leave an element out, at every depth. A tag as
(0010,0010), 0010,0010 or 00100010, or a keyword such
as PatientName. Repeat the option, or separate tags
with commas.
--ignore-meta Leave the file meta group (0002) out
--ignore-private Leave private elements out
EXAMPLES:
go-dicom diff original.dcm anonymized.dcm
go-dicom diff a.dcm b.dcm --ignore-meta --ignore SOPInstanceUID,StudyDate
go-dicom diff a.dcm b.dcm --json
go-dicom diff -q a.dcm b.dcm && echo same
go-dicom diff -h