[Tutor] DICOM Header

Andrew Liimatta Andrew.Liimatta at hsc.utah.edu
Thu Feb 22 21:51:35 CET 2007


I have a directory that is filled with DICOM files that I obtained by using the Offis DICOM tool kit.

The dictionary file I have is not included in the DICOM file. I have a flat file that has all of the DICOM fields defined as a python dictionary. In my initial post I 
included only the first section.
 
dicomdict = {
# meta tags
(0x0002,0x0001):('OB', "FileMetaInformationVersion",             '1', ''),
(0x0002,0x0002):('UI', "MediaStorageSOPClassUID",                '1', ''),
(0x0002,0x0003):('UI', "MediaStorageSOPInstanceUID",             '1', ''),
(0x0002,0x0010):('UI', "TransferSyntaxUID",                      '1', ''),
(0x0002,0x0012):('UI', "ImplementationClassUID",                 '1', ''),
(0x0002,0x0013):('SH', "ImplementationVersionName",              '1', ''),
(0x0002,0x0016):('AE', "SourceApplicationEntityTitle",           '1', ''),
(0x0002,0x0100):('UI', "PrivateInformationCreatorUID",           '1', ''),
(0x0002,0x0102):('OB', "PrivateInformation",                     '1', ''),
# directory tags
(0x0004,0x1130):('CS', "FileSetID",                              '1', ''),
(0x0004,0x1141):('CS', "FileSetDescriptorFileID",                '1-8', ''),
(0x0004,0x1142):('CS', "SpecificCharacterSetOfFileSetDescriptorFile", '1', ''),
(0x0004,0x1200):('UL', "OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity", '1', ''),
(0x0004,0x1202):('UL', "OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity", '1', ''),
(0x0004,0x1212):('US', "FileSetConsistencyFlag",                 '1', ''),
(0x0004,0x1220):('SQ', "DirectoryRecordSequence",                '1', ''),
(0x0004,0x1400):('UL', "OffsetOfTheNextDirectoryRecord",         '1', ''),
(0x0004,0x1410):('US', "RecordInUseFlag",                        '1', ''),
(0x0004,0x1420):('UL', "OffsetOfReferencedLowerLevelDirectoryEntity", '1', ''),
(0x0004,0x1430):('CS', "DirectoryRecordType",                    '1', ''),
(0x0004,0x1432):('UI', "PrivateRecordUID",                       '1', ''),
(0x0004,0x1500):('CS', "ReferencedFileID",                       '1-8', ''),
(0x0004,0x1504):('UL', "MRDRDirectoryRecordOffset",              '1', ''),
(0x0004,0x1510):('UI', "ReferencedSOPClassUIDInFile",            '1', ''),
(0x0004,0x1511):('UI', "ReferencedSOPInstanceUIDInFile",         '1', ''),
(0x0004,0x1512):('UI', "ReferencedTransferSyntaxUIDInFile",      '1', ''),
(0x0004,0x1600):('UL', "NumberOfReferences",                     '1', ''),
# data tags

......
......

.....}

Correct I have no idea how to use the dictionaries to help me complete my task.


Currently I have the following

#!/usr/bin/python
##################################################
import os,linecache     # import the os and linecache module
import string 
# First thing is to look at a directory and list
# out its contents. 
# open a config file to determine the directory, only use a 
# specific line in this case line #7.
dir = linecache.getline('./config',7)
# os.listdir(pathname) will list the pathname.
files = os.listdir(dir[:-1]) # remove the \n from the end of dir.
for file in files:
        dfile = dir[:-1]+file
        print dfile
        dicom_file = open(dfile, "rb")
        elem = dicom_file.readlines()
        print elem
dicom_file.close() # close DICOM Files

I can open each DICOM file but it reads everything from beginning to end which is not very efficient.  I only want to pop out the elements that I am interested in.
Hope this makes a little more sense.

Andrew

-----Original Message-----
From: tutor-bounces at python.org on behalf of Bill Sconce
Sent: Thu 2/22/2007 1:07 PM
To: tutor at python.org
Subject: Re: [Tutor] DICOM Header
 
On Thu, 22 Feb 2007 11:56:19 -0700
"Andrew Liimatta" <Andrew.Liimatta at hsc.utah.edu> wrote:

> 
> Hello,
> 
> 
> I am having a hard time figuring something out.
> 
> I have Files that are written in DICOM format.  I want to be able
> to pull out select elements from the header of these files
> 
> I have a dictionary file that contains enteries like this.
> 
> dicomdict = {
> # meta tags
> (0x0002,0x0001):('OB', "FileMetaInformationVersion",             '1', ''),
> (0x0002,0x0002):('UI', "MediaStorageSOPClassUID",                '1', ''),
> (0x0002,0x0003):('UI', "MediaStorageSOPInstanceUID",             '1', ''),
> (0x0002,0x0010):('UI', "TransferSyntaxUID",                      '1', ''),
> (0x0002,0x0012):('UI', "ImplementationClassUID",                 '1', ''),
> (0x0002,0x0013):('SH', "ImplementationVersionName",              '1', ''),
> (0x0002,0x0016):('AE', "SourceApplicationEntityTitle",           '1', ''),
> (0x0002,0x0100):('UI', "PrivateInformationCreatorUID",           '1', ''),
> (0x0002,0x0102):('OB', "PrivateInformation",                     '1', ''),
> }
> 
> I do understand how to use the dictionary file to help parse out the
> element that I want from the DICOM file.  For example how do I only grab
> the SourceApplicationEntityTitle from the DICOM header.
> 
> Any help would be appreciated.


I'd like to help.  (I have an interest in DICOM files myself, for a
client's needs.)

Unfortunately, I do NOT yet have knowledge of how a DICOM file is
made.  (This is an "opportunity".)  So first we should ask a couple
of questions -- for everyone's benefit, since the method of attack
on your problem has merit beyond DICOM files.

1. Is the dictionary file which you have part of the DICOM file?

2. Or is the dictionary file which you have part of the description
   of what you wish to EXTRACT from the DICOM file?

I could start with a suggested solution, since I think your status
is "2." (and that you mean "do NOT understand how to use the dictionary")
but I might be wrong, so it's better to nail down your requirement first.
Feel free to write me directly if it's going to get into a lot of DICOM
details.

-Bill


_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070222/bb9dec78/attachment.html 


More information about the Tutor mailing list