欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python 读取DICOM头文件的实例

程序员文章站 2023-01-01 11:04:55
用dicompyler软件打开dicom图像,头文件如图所示: 当然也可以直接读取: ds = dicom.read_file('h:\data\data\...

用dicompyler软件打开dicom图像,头文件如图所示:

python 读取DICOM头文件的实例

当然也可以直接读取:

ds = dicom.read_file('h:\data\data\\21662\\2.16.840.1.113662.2.0.105002416.1489146183.701\ct\\ct#0#21662#e7ab693d.dcm')
print ds
>>
(0008, 0008) image type       cs: ['original', 'secondary', 'axial']
(0008, 0016) sop class uid      ui: ct image storage
(0008, 0018) sop instance uid     ui: 2.16.840.1.113662.2.0.105002416.1489146183.501.0
(0008, 0020) study date       da: '20170310'
(0008, 0021) series date       da: '20170310'
(0008, 0023) content date      da: '20060505'
(0008, 0030) study time       tm: '1942'
(0008, 0031) series time       tm: '1942'
(0008, 0033) content time      tm: ''
(0008, 0050) accession number     sh: '63071'
(0008, 0060) modality       cs: 'ct'
(0008, 0070) manufacturer      lo: 'nomos'
(0008, 0090) referring physician's name   pn: ''
(0008, 1010) station name      sh: ''
(0008, 1090) manufacturer's model name   lo: 'corvus 6.4'
(0010, 0010) patient's name      pn: '*m32-2^chenjun^^^'
(0010, 0020) patient id       lo: '21662'
(0010, 0030) patient's birth date    da: ''
(0010, 0040) patient's sex      cs: ''
(0018, 0050) slice thickness      ds: '4.75'
(0018, 0060) kvp         ds: '0'
(0018, 1020) software version(s)     lo: 'corvus 6.4'
(0018, 5100) patient position     cs: 'hfs'
(0020, 000d) study instance uid     ui: 2.16.840.1.113662.2.0.105002416.1489146183.701
(0020, 000e) series instance uid     ui: 2.16.840.1.113662.2.0.105002416.1489146183.501
(0020, 0010) study id       sh: '63071'
(0020, 0011) series number      is: '0'
(0020, 0012) acquisition number     is: '0'
(0020, 0013) instance number      is: '0'
(0020, 0020) patient orientation     cs: ['l', 'p']
(0020, 0032) image position (patient)   ds: ['0.73437356948853', '0', '3.25']
(0020, 0037) image orientation (patient)   ds: ['1', '0', '0', '0', '1', '0']
(0020, 0052) frame of reference uid    ui: 2.16.840.1.113662.2.0.105002416.1489146183.601
(0020, 0060) laterality       cs: ''
(0020, 1040) position reference indicator  lo: ''
(0020, 1041) slice location      ds: '3.25'
(0028, 0002) samples per pixel     us: 1
(0028, 0004) photometric interpretation   cs: 'monochrome2'
(0028, 0010) rows        us: 330
(0028, 0011) columns        us: 339
(0028, 0030) pixel spacing      ds: ['0.734375', '0.734375']
(0028, 0100) bits allocated      us: 16
(0028, 0101) bits stored       us: 12
(0028, 0102) high bit       us: 11
(0028, 0103) pixel representation    us: 0
(0028, 1052) rescale intercept     ds: '-1024'
(0028, 1053) rescale slope      ds: '1'
(7fe0, 0010) pixel data 

发现一套图的第一张和最后一张的slice thickness往往和中间层的值是不同的。

path = 'h:\data\data\\21662\\2.16.840.1.113662.2.0.105002416.1489146183.701\ct\\a.dcm'
slices = dicom.read_file(path)
spacing = slices.pixelspacing

读取头文件信息方法:

slices.上图头文件中的name列。

这时要注意的是,name大小写不变,去掉空格,去掉符号,比如括号。

举例:

origin = slices.softwareversions
print origin
>>corvus 6.4
spacing = slices[1].pixelspacing
print spacing
>>['0.734375', '0.734375']

以上这篇python 读取dicom头文件的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。