<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>RE: [Tutor] DICOM Header</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>I have a directory that is filled with DICOM files that I obtained by using the Offis DICOM tool kit.<BR>
<BR>
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<BR>
included only the first section.<BR>
<BR>
dicomdict = {<BR>
# meta tags<BR>
(0x0002,0x0001):('OB', &quot;FileMetaInformationVersion&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0002):('UI', &quot;MediaStorageSOPClassUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0003):('UI', &quot;MediaStorageSOPInstanceUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0010):('UI', &quot;TransferSyntaxUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0012):('UI', &quot;ImplementationClassUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0013):('SH', &quot;ImplementationVersionName&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0016):('AE', &quot;SourceApplicationEntityTitle&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0100):('UI', &quot;PrivateInformationCreatorUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0002,0x0102):('OB', &quot;PrivateInformation&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
# directory tags<BR>
(0x0004,0x1130):('CS', &quot;FileSetID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1141):('CS', &quot;FileSetDescriptorFileID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1-8', ''),<BR>
(0x0004,0x1142):('CS', &quot;SpecificCharacterSetOfFileSetDescriptorFile&quot;, '1', ''),<BR>
(0x0004,0x1200):('UL', &quot;OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity&quot;, '1', ''),<BR>
(0x0004,0x1202):('UL', &quot;OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity&quot;, '1', ''),<BR>
(0x0004,0x1212):('US', &quot;FileSetConsistencyFlag&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1220):('SQ', &quot;DirectoryRecordSequence&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1400):('UL', &quot;OffsetOfTheNextDirectoryRecord&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1410):('US', &quot;RecordInUseFlag&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1420):('UL', &quot;OffsetOfReferencedLowerLevelDirectoryEntity&quot;, '1', ''),<BR>
(0x0004,0x1430):('CS', &quot;DirectoryRecordType&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1432):('UI', &quot;PrivateRecordUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1500):('CS', &quot;ReferencedFileID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1-8', ''),<BR>
(0x0004,0x1504):('UL', &quot;MRDRDirectoryRecordOffset&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1510):('UI', &quot;ReferencedSOPClassUIDInFile&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1511):('UI', &quot;ReferencedSOPInstanceUIDInFile&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1512):('UI', &quot;ReferencedTransferSyntaxUIDInFile&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
(0x0004,0x1600):('UL', &quot;NumberOfReferences&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
# data tags<BR>
<BR>
......<BR>
......<BR>
<BR>
.....}<BR>
<BR>
Correct I have no idea how to use the dictionaries to help me complete my task.<BR>
<BR>
<BR>
Currently I have the following<BR>
<BR>
#!/usr/bin/python<BR>
##################################################<BR>
import os,linecache&nbsp;&nbsp;&nbsp;&nbsp; # import the os and linecache module<BR>
import string<BR>
# First thing is to look at a directory and list<BR>
# out its contents.<BR>
# open a config file to determine the directory, only use a<BR>
# specific line in this case line #7.<BR>
dir = linecache.getline('./config',7)<BR>
# os.listdir(pathname) will list the pathname.<BR>
files = os.listdir(dir[:-1]) # remove the \n from the end of dir.<BR>
for file in files:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dfile = dir[:-1]+file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print dfile<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dicom_file = open(dfile, &quot;rb&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elem = dicom_file.readlines()<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print elem<BR>
dicom_file.close() # close DICOM Files<BR>
<BR>
I can open each DICOM file but it reads everything from beginning to end which is not very efficient.&nbsp; I only want to pop out the elements that I am interested in.<BR>
Hope this makes a little more sense.<BR>
<BR>
Andrew<BR>
<BR>
-----Original Message-----<BR>
From: tutor-bounces@python.org on behalf of Bill Sconce<BR>
Sent: Thu 2/22/2007 1:07 PM<BR>
To: tutor@python.org<BR>
Subject: Re: [Tutor] DICOM Header<BR>
<BR>
On Thu, 22 Feb 2007 11:56:19 -0700<BR>
&quot;Andrew Liimatta&quot; &lt;Andrew.Liimatta@hsc.utah.edu&gt; wrote:<BR>
<BR>
&gt;<BR>
&gt; Hello,<BR>
&gt;<BR>
&gt;<BR>
&gt; I am having a hard time figuring something out.<BR>
&gt;<BR>
&gt; I have Files that are written in DICOM format.&nbsp; I want to be able<BR>
&gt; to pull out select elements from the header of these files<BR>
&gt;<BR>
&gt; I have a dictionary file that contains enteries like this.<BR>
&gt;<BR>
&gt; dicomdict = {<BR>
&gt; # meta tags<BR>
&gt; (0x0002,0x0001):('OB', &quot;FileMetaInformationVersion&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0002):('UI', &quot;MediaStorageSOPClassUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0003):('UI', &quot;MediaStorageSOPInstanceUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0010):('UI', &quot;TransferSyntaxUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0012):('UI', &quot;ImplementationClassUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0013):('SH', &quot;ImplementationVersionName&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0016):('AE', &quot;SourceApplicationEntityTitle&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0100):('UI', &quot;PrivateInformationCreatorUID&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; (0x0002,0x0102):('OB', &quot;PrivateInformation&quot;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '1', ''),<BR>
&gt; }<BR>
&gt;<BR>
&gt; I do understand how to use the dictionary file to help parse out the<BR>
&gt; element that I want from the DICOM file.&nbsp; For example how do I only grab<BR>
&gt; the SourceApplicationEntityTitle from the DICOM header.<BR>
&gt;<BR>
&gt; Any help would be appreciated.<BR>
<BR>
<BR>
I'd like to help.&nbsp; (I have an interest in DICOM files myself, for a<BR>
client's needs.)<BR>
<BR>
Unfortunately, I do NOT yet have knowledge of how a DICOM file is<BR>
made.&nbsp; (This is an &quot;opportunity&quot;.)&nbsp; So first we should ask a couple<BR>
of questions -- for everyone's benefit, since the method of attack<BR>
on your problem has merit beyond DICOM files.<BR>
<BR>
1. Is the dictionary file which you have part of the DICOM file?<BR>
<BR>
2. Or is the dictionary file which you have part of the description<BR>
&nbsp;&nbsp; of what you wish to EXTRACT from the DICOM file?<BR>
<BR>
I could start with a suggested solution, since I think your status<BR>
is &quot;2.&quot; (and that you mean &quot;do NOT understand how to use the dictionary&quot;)<BR>
but I might be wrong, so it's better to nail down your requirement first.<BR>
Feel free to write me directly if it's going to get into a lot of DICOM<BR>
details.<BR>
<BR>
-Bill<BR>
<BR>
<BR>
_______________________________________________<BR>
Tutor maillist&nbsp; -&nbsp; Tutor@python.org<BR>
<A HREF="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</A><BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>