zoukankan      html  css  js  c++  java
  • DCMTK读取DICOM文件头信息的三种方法

    Howto: Load File Meta-Header

    Here's an example that shows how to load the File Meta Information Header of a DICOMfile without reading the dataset. This could be useful if you are e.g. only interested in theSOP Class UID and Transfer Syntax UID of the file.

    There are three different approaches:

    1. Use the loadFile() method of the DcmMetaInfo class.

    2. Use the loadFile() method of the DcmFileFormat class with read mode ERM_metaOnly.

    3. Use the read() method of the DcmFileFormat class in order to successively load the meta-header and the dataset.

    The third approach allows for reading the dataset only if certain criteria (based on the data elements in the meta-header) are met. Please note that in this case the same input stream is used and that the meta-header is only read once.

    Source Code

    #include "dcmtk/config/osconfig.h"
    #include "dcmtk/dcmdata/dctk.h"
    #include "dcmtk/dcmdata/dcistrmf.h"   int main(int argc, char *argv[])
    {
        OFCondition status;   /* approach 1 */
        DcmMetaInfo metainfo;
        status = metainfo.loadFile("test.dcm");
        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);
        }   /* approach 2 */
        DcmFileFormat fileformat;
        status = fileformat.loadFile("test.dcm", 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);
        }   /* approach 3 */
        fileformat.clear();
        DcmInputFileStream fileStream("test.dcm");
        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();
        }   return 0;
    }
    Note

    Please note that the above sample code requires DCMTK 3.5.5 (20100608 or newer).

  • 相关阅读:
    unity3d热更新插件uLua学习整理
    结合axios对项目中的api请求进行封装
    移动端适配剖析
    vscode如何调试node项目(给node项目打断点)
    mac上使用cnpm搭建npm私有仓库,并上传/下载私有npm包
    前端常见的兼容性问题--web端和移动端
    react树形选择组(支持:单选,多选,全选)
    MongoDB 与 Mysql 的对比
    使用div 的 contenteditable属性,实现输入编辑,输入 "#" 出现下拉选择
    前端单元测试,以及给现有的vue项目添加jest + Vue Test Utils的配置
  • 原文地址:https://www.cnblogs.com/bayzhang/p/5484321.html
Copyright © 2011-2022 走看看