0

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?

Community
  • 1
  • 1
alle_meije
  • 2,424
  • 1
  • 19
  • 40

1 Answers1

1

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).

E_net4
  • 27,810
  • 13
  • 101
  • 139
J. Riesmeier
  • 1,641
  • 10
  • 14
  • Thanks! So the 'lightweight representation' means that only the offsets can be used? Will try to get `dcm2xml $dcmfile | xml2json -x -` to work before returning to coding. – alle_meije Aug 25 '22 at 14:14
  • You mean the Attribute Tag, e.g. "00201041" in your example? Yes, the official JSON format from the DICOM standard only supports this numerical representation and not the keywords. I've never used xml2json, so I don't know whether it works and how this tool deals with XML attributes. – J. Riesmeier Aug 25 '22 at 14:29
  • Ah yes, sorry. that is the tag itself. Thanks! – alle_meije Aug 26 '22 at 07:26