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

本文介绍了一个用于从DICOM数据集中删除所有私有标签的示例函数。该函数利用了DCMTK库中DcmItem类的API,并通过检查标签组号来识别并移除私有数据。此外,还提供了获取DICOM文件中数据集的方法及DCMTK中堆栈类的使用说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值