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?