status = data->putAndInsertUint8Array(DCM_PixelData, pSource, sizeBuffer);
我需要将pSource中包含的未压缩像素数据进行翻译。随后,我会添加图像DICOM标签(组28),并通过进行压缩来处理数据。
status = data->chooseRepresentation(EXS_JPEGProcess14SV1, ¶m);
从这个数据集开始,我想访问压缩数据。
status = data->findAndGetElement(DCM_PixelData, element);
DcmPixelData *dpix = NULL;
dpix = OFstatic_cast(DcmPixelData*, element);
/* Since we have compressed data, we must utilize DcmPixelSequence
in order to access it in raw format, e. g. for decompressing it
with an external library.
*/
DcmPixelSequence *dseq = NULL;
E_TransferSyntax xferSyntax = EXS_Unknown;
const DcmRepresentationParameter *rep = NULL;
// Find the key that is needed to access the right representation of the data within DCMTK
dpix->getOriginalRepresentationKey(xferSyntax, rep);
// Access original data representation and get result within pixel sequence
status = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq);
Uint32 length;
if (status.good())
{
DcmPixelItem* pixitem = NULL;
// Access first frame (skipping offset table)
dseq->getItem(pixitem, 1);
if (pixitem == NULL)
return 1;
Uint8* pixData = NULL;
// Get the length of this pixel item (i.e. fragment, i.e. most of the time, the lenght of the frame)
length = pixitem->getLength();
if (length == 0)
return 1;
// Finally, get the compressed data for this pixel item
status = pixitem->getUint8Array(pixData);
// Metto i Pixel Data compressi su pSorgCompr
pSorgCompr = (LPBYTE)pixData;
}
////////////////////////////
DJEncoderRegistration::cleanup();
DJDecoderRegistration::cleanup();
但行 status = dpix->getEncapsulatedRepresentation(xferSyntax, rep, dseq); 返回失败,错误信息为“未找到像素表示”,我不明白为什么。
奇怪的是,在访问压缩数据之前,如果我使用 fileformat.saveFile("compressedPixelData.dcm", EXS_JPEGProcess14SV1); 将压缩文件保存并使用 result = fileformat.loadFile("compressedPixelData.dcm"); 加载该文件,一切都完美地工作。
好像 loadfile 函数解决了问题,我不知道是怎么做到的,也许填充了一些标签?
在调用 chooseRepresentation 函数之前,我填充的标签包括:
- DCM_Rows
- DCM_Columns
- DCM_BitsStored
- DCM_SamplesPerPixel
- DCM_PlanarConfiguration
- DCM_HighBit
- DCM_BitsAllocated
- DCM_PixelRepresentation
- DCM_RescaleIntercept
- DCM_RescaleSlope
- DCM_PhotometricInterpretation
- DCM_PixelAspectRatio
- DCM_ImagerPixelSpacing
- DCM_PixelSpacing
// Access first frame (skipping offset table) dseq->getItem(pixitem, 1);
但这并没有回答我的问题。对于我的问题,似乎当我选择表示时,原始数据仍然保持不变,我需要将其删除才能访问压缩数据。 - GiordiX