使用dcmtk覆盖dicom文件中的图像/像素数据 [英] Overwrite an image/pixel data in the dicom file using dcmtk
问题描述
我使用dcmtk读取dicom文件并将图像提取为.tiff格式。做了一些图像处理后,我有一个图像,我想保存在源dicom文件中。这是用我的新图像覆盖旧的图像/像素数据,同时保留其余的数据(uid,患者姓名等)相同。
I use dcmtk to read a dicom file and extract the image into a .tiff format. After doing some image processing I have an image which I would like to save in the source dicom file.That is overwriting the old image/pixel data with my new ones, while keeping rest of the data(uid,patient name,,etc) same.
我使用以下代码阅读dicom
I use the following code to read dicom
OFCondition status = src_fileformat.loadFile(src_path);
if (status.good())
{
Sint32 instanceNumber = 0;
if (src_fileformat.getDataset()->findAndGetSint32(DCM_InstanceNumber, instanceNumber).good())
{
cout << "instance Number N: " << instanceNumber << endl;
sprintf(instanceNum, "%d", instanceNumber);
printf("%s\n", instanceNum);
}
else
cerr << "Error: cannot access Instance Number!" << endl;
}
else
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
src_dcm = new DicomImage(src_path);
if (src_dcm != NULL)
{
if (src_dcm->getStatus() == EIS_Normal)
{
if (src_dcm->isMonochrome())
{
src_dcm->setMinMaxWindow();
Uint8 *pixelData = (Uint8 *)(src_dcm->getOutputData(16 /* bits */));
if (pixelData != NULL)
{
src_dcm->writeBMP("source.tiff", 24); /* do something useful with the pixel data */
}
}
}
else
cerr << "Error: cannot load DICOM image (" << DicomImage::getString(src_dcm->getStatus()) << ")" << endl;
}
图像处理完成后,我想要覆盖此源码的图像文件。我查看了image2dcm,但我无法获得正确的语法/方法。任何人帮助我.. :)
After image processing I have an image that I want to overwrite onto this source dicom file. I looked into image2dcm,but I couldn't get the correct syntax/method to do. any one help me out.. :)
编辑-1
Image2Dcm i2d;
I2DOutputPlug *outPlug = new I2DOutputPlugSC();
I2DImgSource *inputPlug = new I2DJpegSource();
E_TransferSyntax writeXfer;
inputPlug->setImageFile(jpgFile);
DcmDataset *dataset = NULL;
OFCondition result = i2d.convert(inputPlug, outPlug, dataset, writeXfer);
// Saving output DICOM image
if (result.good())
{
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");
DcmFileFormat dcmff(dataset);
result = dcmff.saveFile(dcmFile, writeXfer);
}
我尝试了上面显示的语法,但无法完全理解
I tried the above shown syntax,but couldn't exactly understand it
这是已处理的图片(上图)
This is the processed image(above)
这是我想要的原始dicom图像覆盖。伙计们,任何想法或帮助??
This is the original dicom image that I want to overwrite. Guys ,any idea or help??
推荐答案
基本方法应该是:
- 从文件加载DICOM数据集
- 替换数据集中的像素数据
- 修改其他各种元素值(例如SOP实例UID)
- 将修改后的DICOM数据集保存到新文件
- load the DICOM dataset from file
- replace the pixel data in the dataset
- modify various other element values (e.g. SOP Instance UID)
- save the modified DICOM dataset to a new file
在未压缩图像的情况下,第二步可以以与第三步相同的方式执行,即通过在数据集上适当调用putAndInsertXXX()方法。当然,Pixel Data属性的元素值应该是正确的DICOM格式。有关详细信息,请参阅 DICOM标准第3部分和第5部分。
In case of uncompressed images, the second step could be performed in the same manner as the third step, i.e. by an appropriate call of a putAndInsertXXX() method on the dataset. Of course, the element value of the Pixel Data attribute should be in correct DICOM format. See DICOM standard part 3 and 5 for details.
这篇关于使用dcmtk覆盖dicom文件中的图像/像素数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!