I am using the DCMTK library in my program, which among others writes a JSON. With the DcmDataset::writeJson()
function I can put the whole header in the JSON in one call, which is very handy, but the tags are listed by offset not name.
This is the same as with the command-line program dcm2json
, which writes a JSON file where each tag is represented by an 8-digit string of the offset.
The other command-line tool for getting this information, dcmdump
gives this for the slice location:
$ dcmdump $dcmfile | grep SliceLocation
(0020,1041) DS [-67.181462883113] # 16, 1 SliceLocation
and I can do
$ dcm2json $dcmfile | grep -n3 67.181462883113
1552- "00201041": {
1553- "vr": "DS",
1554- "Value": [
1555: -67.181462883113
1556- ]
1557- },
1558- "00280002": {
to find it in the JSON stream, or even (the C++ equivalent of)
$ dcm2json $dcmfile | grep -n3 $(dcmdump $dcmfile | grep SliceLocation | awk '{print $1}' | tr "()," " " | awk '{print $1$2}')
but that feels like a very roundabout way to do things.
Is there a way to write out a JSON directly with the name of the DICOM tags, or another way to combine the DcmDataset::writeJson()
and dcmdump
functionality?
The output format of dcm2json is defined by the DICOM standard (see PS3.18 Chapter F), so there is no way to add the Attribute Names/Keywords. However, you might want to try dcm2xml, which supports both a DCMTK-specific output format and the Native DICOM Model (see PS3.19 Chapter A.1). Both formats make use of the official Keywords that are associated with each DICOM Attribute (see PS3.6 Section 6).