Generate a excel-table!!!

171 views
Skip to first unread message

MMoury

unread,
Dec 5, 2008, 6:16:22 AM12/5/08
to pydicom
Hi all,

I separed the tags and the values from a dicomfile.

>>> import dicom
>>> dataset=dicom.ReadFile(dicomfile1.dcm")
>>> I=dataset.items()
>>> v=I[0][1]
>>> for v in I:
x=v[1].description()
y=v[1].value
print x, "=", y


And now I have to generate with this "news" Informations(Tags and
Value) a excel-table.
For example:

File Tag1 Tag2
Tag................
DCMFile1 Value1 Value2
Value............

Can someone help me?






Darcy Mason

unread,
Dec 6, 2008, 2:23:42 PM12/6/08
to pydicom
For python2.3 and later, I'd suggest creating comma-separated value
files using the csv module in python (http://www.python.org/doc/2.5.2/
lib/module-csv.html). The files are simple text files that you can
inspect and edit if necessary, and Excel reads them in easily.

If you must create Excel files directly, then there is the xlwt
library (http://pypi.python.org/pypi/xlwt) that has replaced the older
pyExcelerator package.
Help is available at the google group http://groups.google.com/group/python-excel.

One other point about your code below. The items coming back from a
python dictionary can be in any order, so you may want to sort them.
See the _PrettyStr() method in dataset.py for an example of going
through the dataset values in DICOM order, in a more 'pythonic' way.

Darcy

MMoury

unread,
Dec 9, 2008, 10:07:49 AM12/9/08
to pydicom
Hi Darcy,

The order in my items isn't much important!!!
But i wand to delete the Pixel Data and this value...and return the
others informations as text.
I tried with this code but the pixel data appear always:

import dicom

def extract():
"""Return the tags and the value as text"""
dataset=dicom.ReadFile('CTCA4D001.dcm')
I=dataset.items()
v=I[0][1]
f=open('CTCA4D001.txt','w')
for v in I:

if v[1].description != "Pixel Data":
f.write(v[1].description())
f.write(",")
f.write(str(v[1].value))
f.write("\n")

f.close()

I think my items() ist a type 'tuple'...is it possible to delete the
pixel data in my text?

thanks in advance!!!

Darcy Mason

unread,
Dec 9, 2008, 10:23:23 AM12/9/08
to pydicom
On Dec 9, 9:07 am, MMoury <marc.mo...@yahoo.fr> wrote:
>     for v in I:
>
>        if v[1].description != "Pixel Data":

Looks like you are missing the parentheses -- should be v
[1].description(). (I probably should change that code so it is a
property rather than a function call)

> I think my items() ist a type 'tuple'...is it possible to delete the
> pixel data in my text?

Since Dataset is derived from python dict, the del method can remove
an item from a Dataset. Now that I try this, though, I realized the
key is not quite right unless you specifically say it is a Tag or use
the long value directly. So:
>>> from dicom.tag import Tag
>>> del dataset[Tag(0x7fe0,0x0010)]
Or another way:
>>> del dataset[0x7fe00010]

Reply all
Reply to author
Forward
0 new messages