<!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', "FileMetaInformationVersion", '1', ''),<BR>
(0x0002,0x0002):('UI', "MediaStorageSOPClassUID", '1', ''),<BR>
(0x0002,0x0003):('UI', "MediaStorageSOPInstanceUID", '1', ''),<BR>
(0x0002,0x0010):('UI', "TransferSyntaxUID", '1', ''),<BR>
(0x0002,0x0012):('UI', "ImplementationClassUID", '1', ''),<BR>
(0x0002,0x0013):('SH', "ImplementationVersionName", '1', ''),<BR>
(0x0002,0x0016):('AE', "SourceApplicationEntityTitle", '1', ''),<BR>
(0x0002,0x0100):('UI', "PrivateInformationCreatorUID", '1', ''),<BR>
(0x0002,0x0102):('OB', "PrivateInformation", '1', ''),<BR>
# directory tags<BR>
(0x0004,0x1130):('CS', "FileSetID", '1', ''),<BR>
(0x0004,0x1141):('CS', "FileSetDescriptorFileID", '1-8', ''),<BR>
(0x0004,0x1142):('CS', "SpecificCharacterSetOfFileSetDescriptorFile", '1', ''),<BR>
(0x0004,0x1200):('UL', "OffsetOfTheFirstDirectoryRecordOfTheRootDirectoryEntity", '1', ''),<BR>
(0x0004,0x1202):('UL', "OffsetOfTheLastDirectoryRecordOfTheRootDirectoryEntity", '1', ''),<BR>
(0x0004,0x1212):('US', "FileSetConsistencyFlag", '1', ''),<BR>
(0x0004,0x1220):('SQ', "DirectoryRecordSequence", '1', ''),<BR>
(0x0004,0x1400):('UL', "OffsetOfTheNextDirectoryRecord", '1', ''),<BR>
(0x0004,0x1410):('US', "RecordInUseFlag", '1', ''),<BR>
(0x0004,0x1420):('UL', "OffsetOfReferencedLowerLevelDirectoryEntity", '1', ''),<BR>
(0x0004,0x1430):('CS', "DirectoryRecordType", '1', ''),<BR>
(0x0004,0x1432):('UI', "PrivateRecordUID", '1', ''),<BR>
(0x0004,0x1500):('CS', "ReferencedFileID", '1-8', ''),<BR>
(0x0004,0x1504):('UL', "MRDRDirectoryRecordOffset", '1', ''),<BR>
(0x0004,0x1510):('UI', "ReferencedSOPClassUIDInFile", '1', ''),<BR>
(0x0004,0x1511):('UI', "ReferencedSOPInstanceUIDInFile", '1', ''),<BR>
(0x0004,0x1512):('UI', "ReferencedTransferSyntaxUIDInFile", '1', ''),<BR>
(0x0004,0x1600):('UL', "NumberOfReferences", '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 # 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>
dfile = dir[:-1]+file<BR>
print dfile<BR>
dicom_file = open(dfile, "rb")<BR>
elem = dicom_file.readlines()<BR>
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. 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>
"Andrew Liimatta" <Andrew.Liimatta@hsc.utah.edu> wrote:<BR>
<BR>
><BR>
> Hello,<BR>
><BR>
><BR>
> I am having a hard time figuring something out.<BR>
><BR>
> I have Files that are written in DICOM format. I want to be able<BR>
> to pull out select elements from the header of these files<BR>
><BR>
> I have a dictionary file that contains enteries like this.<BR>
><BR>
> dicomdict = {<BR>
> # meta tags<BR>
> (0x0002,0x0001):('OB', "FileMetaInformationVersion", '1', ''),<BR>
> (0x0002,0x0002):('UI', "MediaStorageSOPClassUID", '1', ''),<BR>
> (0x0002,0x0003):('UI', "MediaStorageSOPInstanceUID", '1', ''),<BR>
> (0x0002,0x0010):('UI', "TransferSyntaxUID", '1', ''),<BR>
> (0x0002,0x0012):('UI', "ImplementationClassUID", '1', ''),<BR>
> (0x0002,0x0013):('SH', "ImplementationVersionName", '1', ''),<BR>
> (0x0002,0x0016):('AE', "SourceApplicationEntityTitle", '1', ''),<BR>
> (0x0002,0x0100):('UI', "PrivateInformationCreatorUID", '1', ''),<BR>
> (0x0002,0x0102):('OB', "PrivateInformation", '1', ''),<BR>
> }<BR>
><BR>
> I do understand how to use the dictionary file to help parse out the<BR>
> element that I want from the DICOM file. For example how do I only grab<BR>
> the SourceApplicationEntityTitle from the DICOM header.<BR>
><BR>
> Any help would be appreciated.<BR>
<BR>
<BR>
I'd like to help. (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. (This is an "opportunity".) 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>
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 "2." (and that you mean "do NOT understand how to use the dictionary")<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 - 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>