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).

DCMTK读取DICOM文件头信息的三种方法的更多相关文章

  1. python获取网页信息的三种方法

    import urllib.request import http.cookiejar url = 'http://www.baidu.com/' # 方法一 print('方法一') req_one ...

  2. 用Python获取Linux资源信息的三种方法

    方法一:psutil模块 #!usr/bin/env python # -*- coding: utf-8 -*- import socket import psutil class NodeReso ...

  3. HTML元素脱离文档流的三种方法

    一.什么是文档流? 将窗体自上而下分成一行一行,并在每行中按从左至右依次排放元素,称为文档流,也称为普通流. 这个应该不难理解,HTML中全部元素都是盒模型,盒模型占用一定的空间,依次排放在HTML中 ...

  4. 简析Geoserver中获取图层列表以及各图层描述信息的三种方法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 实际项目中需要获取到Geoserver中的图层组织以及各图层 ...

  5. SQL Server删除表信息的三种方法

    1.使用DELETE实现SQL Server删除表信息 (1)删除表中的全部信息 USE student GO DELETE student      --不加where条件,删除表中的所有记录 go ...

  6. Win7系统与它的Virtualbox中安装的Ubuntu14.04共享信息的几种方法

    虚拟机是每一个程序猿必备的工具.本文依据最新版VirtualBox用户手冊的提示,通过自己的亲自实践,给出了Win7系统与执行在当中的VirtualBox 5.0.2中的Ubuntu 14.04共享信 ...

  7. sublime 设置新建文件自动添加author(作者)等文件头信息

    很多时候, sublime 自带自动添加文件头信息, 但是并不是我们想要比如下面这样的:新建一个python文件 自动添加的author 信息== 上面并不是我想要的, 我想要下面这样的效果:== 这 ...

  8. 服务器文档下载zip格式 SQL Server SQL分页查询 C#过滤html标签 EF 延时加载与死锁 在JS方法中返回多个值的三种方法(转载) IEnumerable,ICollection,IList接口问题 不吹不擂,你想要的Python面试都在这里了【315+道题】 基于mvc三层架构和ajax技术实现最简单的文件上传 事件管理

    服务器文档下载zip格式   刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Co ...

  9. 三种方法解决android帮助文档打开慢

    三种方法解决android帮助文档打开慢   经查是因为本地文档中的网页有如下两段js代码会联网加载信息,将其注释掉后就好了 <link rel="stylesheet" h ...

随机推荐

  1. Host 'XXX' is not allowed to connect to this MySQL server解决方案

    如何允许远程连接mysql数据库呢,操作如下: 首先登录账号 mysql -uroot -p 使用mysql用户 use mysql 如果报此类错:ERROR 1820 (HY000): You mu ...

  2. 数据结构之C语言模拟整数数组实现

    #include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct Arr { in ...

  3. 用一层for循环初始化三维数组

    ][][]; ; i < * * ; i++) { a[i / ][(i / ) % ][i % ] = i; printf(, (i / ) % , i % ); // printf(&quo ...

  4. GitKraken使用教程-基础部分(8)

    9.  远程(Remote)仓库 1) 添加远程仓库 一般在本地新建仓库后,需要添加一个远程仓库用于push/pull代码.鼠标移至GitKraken左侧区域的REMOTE栏,点击 该栏右边出现的 按 ...

  5. 划分用户故事(user-story)的原则

    在敏捷开发过程中是通过用户故事来将需求具体化成可以进行迭代开发的一个个现实的可见的开发任务.因此在敏捷软件的开发过程中,用户故事的划分对于迭代和开发起着举足轻重的作用. 用户故事从其名字来看是站在用户 ...

  6. fetch技术

    Snandy If you cannot hear the sound of the genuine in you, you will all of your life spend your days ...

  7. OPEN(SAP) UI5 学习入门系列之二: 最佳实践练习(下)

    上期我们完成了一个简单的主从页面,但是页面是静态的,不能交互,功能也很简单,只有一个销售订单的列表. 我们今天就一鼓作气把代码全都写完,由于本次的代码量较大,所以只对重点代码部分进行讲解. 具体每个文 ...

  8. 文件监控只FileSystemWatcher控件

    FileSYstemWatcher控件是用来监控一个文件系统或监控文件变化.该控件会通知文件创建.修改.删除的消息,分别通过Created事件.Changed事件和Deleted事件来处理对应的操作 ...

  9. SQLSERVER 2012的多维数据库浏览 ,不能多维的显示

    网上搜索后发现,原来ssms2012不支持这种方式,要使用Excel的方式 参考地址:http://www.flybi.net/question/12567

  10. [LeetCode]17. Letter Combinations of a Phone Number电话号码的字母组合

    Given a string containing digits from 2-9 inclusive, return all possible letter combinations that th ...