1、读取File Meta-Header
原文:http://support.dcmtk.org/redmine/projects/dcmtk/wiki/Howto_LoadMetaHeader
首先定义状态变量和dicom文件路径
OFCondition status;方法一:通过DcmMetaInfo类
const char* filepath=“test.dcm”;
DcmMetaInfo metainfo;方法二:通过DcmFileFormat类
status = metainfo.loadFile(filepath);
if (status.good())
{
OFString sopClassUID, xferUID;
if (metainfo.findAndGetOFString(DCM_MediaStorageSOPClassUID, sopClassUID).good())
COUT << "SOP Class UID: " << sopClassUID << OFendl;
if (metainfo.findAndGetOFString(DCM_TransferSyntaxUID, xferUID).good())
COUT << "Transfer Syntax UID: " << xferUID << OFendl;
metainfo.print(COUT);
}
DcmFileFormat fileformat;
status = fileformat.loadFile(filepath, EXS_Unknown, EGL_noChange, DCM_MaxReadLength, ERM_metaOnly);
if (status.good())
{
OFString sopClassUID, xferUID;
if (fileformat.getMetaInfo()->findAndGetOFString(DCM_MediaStorageSOPClassUID, sopClassUID).good())
COUT << "SOP Class UID: " << sopClassUID << OFendl;
if (fileformat.getMetaInfo()->findAndGetOFString(DCM_TransferSyntaxUID, xferUID).good())
COUT << "Transfer Syntax UID: " << xferUID << OFendl;
fileformat.print(COUT);
}
方法三:通过DcmFileFormat类
DcmFileFormat fileformat;
DcmInputFileStream fileStream(filepath);
status = fileStream.status();
if (status.good())
{
/* first, read meta-header */
fileformat.setReadMode(ERM_metaOnly);
fileformat.transferInit();
status = fileformat.read(fileStream);
if (status.good())
{
OFString sopClassUID, xferUID;
if (fileformat.getMetaInfo()->findAndGetOFString(DCM_MediaStorageSOPClassUID, sopClassUID).good())
COUT << "SOP Class UID: " << sopClassUID << OFendl;
if (fileformat.getMetaInfo()->findAndGetOFString(DCM_TransferSyntaxUID, xferUID).good())
COUT << "Transfer Syntax UID: " << xferUID << OFendl;
/* then read dataset if certain criteria are met */
if (sopClassUID == UID_SecondaryCaptureImageStorage)
{
fileformat.setReadMode(ERM_autoDetect);
status = fileformat.read(fileStream);
if (status.good())
{
fileformat.print(COUT);
}
}
}
fileformat.transferEnd();
}
2、