Howto: Remove private data from a DICOM dataset

There is no ready-to-use function in DCMTK to delete all private data from a DICOM dataset. However, using the API of DcmItem and the fact that all private data has an odd group number, it is pretty easy to do this. Here is some sample code for a corresponding function (not fully tested). It searches the given item recursively for private data and removes it if found:

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
 
void removeAllPrivateTags(DcmItem& dset)
{
  DcmStack stack;
  DcmObject *dobj = NULL;
  DcmTagKey tag;
  OFCondition status = dset.nextObject(stack, OFTrue);
  while (status.good())
  {
    dobj = stack.top();
    tag = dobj->getTag();
    if (tag.getGroup() & 1) // private tag ?
    {
      stack.pop();
      delete ((DcmItem *)(stack.top()))->remove(dobj);
    }
    status = dset.nextObject(stack, OFTrue);
  }
}

See documentation of DcmFileFormat and example in dcmdata documentation how to get a DcmDataset (which is also an DcmItem object) from an existing DICOM file.

Note: In the current DCMTK release, there is also an isPrivate() method which can be used with the above sample code.

 
dcmtk/howto/removeprivatedata.txt · Last modified: 2011/08/22 17:45 by riesmeier
 
Except where otherwise noted, content on this wiki is licensed under the following license:Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Run by Debian Driven by DokuWiki