<div>Thanks for the immediate response!<br><br></div>
<div class="gmail_quote">On Dec 12, 2007 5:57 PM, John Fouhy <<a href="mailto:john@fouhy.net">john@fouhy.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="Ih2E3d">On 13/12/2007, Bryan Fodness <<a href="mailto:bryan.fodness@gmail.com">bryan.fodness@gmail.com</a>> wrote:<br>> I am new to doing anything like this. I have looked at<br>> <a href="http://www.leadtools.com/SDK/Medical/DICOM/ltdc1.htm" target="_blank">
http://www.leadtools.com/SDK/Medical/DICOM/ltdc1.htm</a> and am<br>> not sure how to proceed.<br><br></div>I haven't much experience here, but this is how I'd proceed, I think:<br><br>1. Start by reading the file. It's binary data (I guess) so there's
<br>no point in reading lines.:<br> rawData = open('file.dcm', 'rb').read()<br><br>2. Write a function to parse the preamble:<br><br> def parsePreamble(data):<br> preamble = data[:128]<br> dicm = data[128:132]
<br><br> # you might need to read up on encodings and things to make sure<br>this test is valid<br> if dicm == 'DICM':<br> return preamble, 132<br> else:<br> raise NotAPreambleException<br><br>3. Write functions to parse data elements. The functions are going to
<br>try to parse a data element starting at a particular position, and if<br>successful, return the position of the end of the element.<br><br> def parseDataelement(data, start):<br> # do stuff -- the web page you linked didn't have enough information here
<br> return element, pos<br><br>4. Parse the whole thing;<br><br> def parseDICOM(data):<br> elements = []<br> try:<br> preamble, next = parsePreamble(data)<br> except NotAPreambleException:<br> preamble, next = None, 0
<br><br> while True:<br> element, next = parseDataElement(data, next)<br> elements.append(element)<br> # you will need some way of breaking out of this loop, either by<br>checking the structure of<br> # element for an end condition, or by parseDataElement raising
<br>an exception.<br><br> return elements # and maybe preamble too if you want it<br><br>HTH!<br></blockquote></div><br><br clear="all"><br>-- <br>"The game of science can accurately be described as a never-ending insult to human intelligence." - Joćo Magueijo