- 环境:
VS2013 + DCMTK3.6.2 32bit 准备:
1). 模板dicom图像.用于复制metainfo.
2). RAW数据, 这里用的是256X256大小的u16 raw文件.源代码:
#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");
}
}