DCMTK从DICOM数据集中删除私有数据

阅读更多

 

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.

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

Note2:DCMStack类:

this class manages a stack of pointers to DcmObject instances.

The objects pointed to are never touched, e.g. deleted.

你可能感兴趣的:(DCMTK,DICOM,数据集,DateSet)