<div>Thanks for the immediate response!<br><br></div>
<div class="gmail_quote">On Dec 12, 2007 5:57 PM, John Fouhy &lt;<a href="mailto:john@fouhy.net">john@fouhy.net</a>&gt; 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 &lt;<a href="mailto:bryan.fodness@gmail.com">bryan.fodness@gmail.com</a>&gt; wrote:<br>&gt; I am new to doing anything like this. &nbsp;I have looked at<br>&gt; <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>&gt; not sure how to proceed.<br><br></div>I haven&#39;t much experience here, but this is how I&#39;d proceed, I think:<br><br>1. Start by reading the file. &nbsp;It&#39;s binary data (I guess) so there&#39;s
<br>no point in reading lines.:<br>&nbsp;rawData = open(&#39;file.dcm&#39;, &#39;rb&#39;).read()<br><br>2. Write a function to parse the preamble:<br><br>&nbsp;def parsePreamble(data):<br>&nbsp; &nbsp;preamble = data[:128]<br>&nbsp; &nbsp;dicm = data[128:132]
<br><br>&nbsp; &nbsp;# you might need to read up on encodings and things to make sure<br>this test is valid<br>&nbsp; &nbsp;if dicm == &#39;DICM&#39;:<br>&nbsp; &nbsp; &nbsp;return preamble, 132<br>&nbsp; &nbsp;else:<br>&nbsp; &nbsp; &nbsp;raise NotAPreambleException<br><br>3. Write functions to parse data elements. &nbsp;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>&nbsp;def parseDataelement(data, start):<br>&nbsp; &nbsp;# do stuff -- the web page you linked didn&#39;t have enough information here
<br>&nbsp; &nbsp;return element, pos<br><br>4. Parse the whole thing;<br><br>&nbsp;def parseDICOM(data):<br>&nbsp; &nbsp;elements = []<br>&nbsp; &nbsp;try:<br>&nbsp; &nbsp; &nbsp;preamble, next = parsePreamble(data)<br>&nbsp; &nbsp;except NotAPreambleException:<br>&nbsp; &nbsp; &nbsp;preamble, next = None, 0
<br><br>&nbsp; &nbsp;while True:<br>&nbsp; &nbsp; &nbsp;element, next = parseDataElement(data, next)<br>&nbsp; &nbsp; &nbsp;elements.append(element)<br>&nbsp; &nbsp; &nbsp;# you will need some way of breaking out of this loop, either by<br>checking the structure of<br>&nbsp; &nbsp; &nbsp;# element for an end condition, or by parseDataElement raising
<br>an exception.<br><br>&nbsp; &nbsp;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