c++ - 如何从 dicom 文件中读取二进制数据?
问题描述
如何从未压缩的 DICOM 文件中读取原始图像数据并将其转储到文件中。我只是将以下代码用于压缩文件。使用 dcmtk 库
dataSet->findAndGetElement(DCM_PixelData, element);
pixDataElem = OFstatic_cast(DcmPixelData*, element);
DcmPixelSequence *pixelSequence = NULL;
E_TransferSyntax tran_Syntax = EXS_Unknown;
const DcmRepresentationParameter *representation = NULL;
// Find the key that is needed to access the right representation of the data within DCMTK
pixDataElem->getOriginalRepresentationKey(tran_Syntax, representation);
//pixDataElem->getCurrentRepresentationKey(tran_Syntax, representation);
// Access original data representation and get result within pixel sequence
pixDataElem->getEncapsulatedRepresentation(tran_Syntax, representation, pixelSequence);
DcmPixelItem *pixelItem = NULL;
//Access the First frame by skipping the offset table...
pixelSequence->getItem(pixelItem, 1);
Uint8 *pixels = NULL;
pixDataElem = (DcmPixelData*)pixelItem;
pixDataElem->getUint8Array(pixels);
Uint8 *pixels = NULL;
pixDataElem->getUint8Array(pixels);
//Writing the Raw data to a file...
FILE *file;
file = fopen("D:\\DicomImage.jpeg", "wb");
fwrite(pixels, sizeof(char), imageSize, file);
cout << "File write Completed and the File is closed Successfully" << endl;
如何使用 dcmtk 库从 C++ 中具有许多帧的未压缩文件中获取原始图像数据.....?
解决方案
基本上,您可以使用相同的代码,但无需压缩(这实际上是更简单的情况......)
dataSet->findAndGetElement(DCM_PixelData, element);
pixDataElem = OFstatic_cast(DcmPixelData*, element);
Uint8 *pixels = NULL;
pixDataElem->getUint8Array(pixels);
//Writing the Raw data to a file...
FILE *file;
file = fopen("D:\\DicomImage.raw", "wb");
// frameSize is the size of a single frame
fwrite(pixels + frameSize * frameIndex, sizeof(char), frameSize, file);
cout << "File write Completed and the File is closed Successfully" << endl;
(这不是我的想法,所以不能保证完整性)
你得到的是原始二进制数据。如果要从中创建像 JPG 这样的图像文件,则需要相应的图像功能,尽管这与 dcmtk 无关。
推荐阅读
- javascript - 谷歌地图显示失真
- javascript - 可以将命名变量用作多个参数吗?
- apache-spark - 什么是 datanucleus DELETEME* 表以及它们何时创建和删除
- css - 自定义 Mat-checkbox Indeterminate 图标
- javascript - Moment js:格式化日期没有零填充
- selenium - 如何在硒的框架中添加等待
- xcode - 无法运行导出的应用程序
- c# - ASP.NET MVC 5 仅保留一个唯一行
- image - 如何理解 .bitmap 格式编码。通过纸笔将 1 位位图转换为图像
- r - 使用 FFT 函数对 R 中的时间序列数据进行傅里叶平滑