DCMTK简单应用示例【集锦】

1、读取File Meta-Header

原文:http://support.dcmtk.org/redmine/projects/dcmtk/wiki/Howto_LoadMetaHeader

首先定义状态变量和dicom文件路径

OFCondition status;
const char* filepath=“test.dcm”;
方法一:通过DcmMetaInfo类

DcmMetaInfo metainfo;
	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类

    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、

你可能感兴趣的:(医疗设备,dcmtk)