使用DCMTK将RAW数据保存为Dicom图

  1. 环境:
    VS2013 + DCMTK3.6.2 32bit
  2. 准备:
    1). 模板dicom图像.用于复制metainfo.
    2). RAW数据, 这里用的是256X256大小的u16 raw文件.

  3. 源代码:

#include"dcmtk/config/osconfig.h"  
#include"dcmtk/dcmdata/dctk.h"  
#include<iostream>  
using namespace std;

int main()
{
    // 读Raw
    /*将256X256大小的u16 raw文件数据读入pusImgSrc, 省略不写*/

    // 读模板dicom
    DcmFileFormat fileformat;
    OFCondition oc = fileformat.loadFile("template.dcm");

    if (oc.good()) {
        OFString strTagValue;
        // 原名字
        if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, strTagValue).good())
        {
            cout << "Patient Old Name:" << strTagValue.data() << endl;
        }
        // 新名字
        if (fileformat.getDataset()->putAndInsertString(DCM_PatientName, "John Doe").good())
        {
            fileformat.getDataset()->findAndGetOFString(DCM_PatientName, strTagValue);
            cout << "Patient New Name:" << strTagValue.data() << endl;
        }
        // 修改窗宽窗位
        if (fileformat.getDataset()->putAndInsertString(DCM_WindowCenter, "30000").good())
        {
            fileformat.getDataset()->findAndGetOFString(DCM_WindowCenter, strTagValue);
            cout << "窗位:" << strTagValue.data() << endl;
        }
        if (fileformat.getDataset()->putAndInsertString(DCM_WindowWidth, "60000").good())
        {
            fileformat.getDataset()->findAndGetOFString(DCM_WindowCenter, strTagValue);
            cout << "窗宽:" << strTagValue.data() << endl;
        }
        // 修改宽高
        if (fileformat.getDataset()->putAndInsertString(DCM_Rows, "256").good())
        {
            fileformat.getDataset()->findAndGetOFString(DCM_Rows, strTagValue);
            cout << "Rows:" << strTagValue.data() << endl;
        }
        if (fileformat.getDataset()->putAndInsertString(DCM_Columns, "256").good())
        {
            fileformat.getDataset()->findAndGetOFString(DCM_Columns, strTagValue);
            cout << "Columns:" << strTagValue.data() << endl;
        }

        // 保存新的dcm
        if (fileformat.getDataset()->putAndInsertUint16Array(DCM_PixelData, pusImgSrc, iWidth*iHeight, true).good())
        {
            fileformat.saveFile("Out.dcm");
        }
    }
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值