Fields in DICOM NOT showing up when the file is read

97 views
Skip to first unread message

Jason Steffener

unread,
Sep 9, 2011, 2:10:27 PM9/9/11
to pyd...@googlegroups.com
Dear all,
I am working with enhanced 4-D dicom files from a 3T Philps Achieva MRI. I am using pydicom to read them in but there are a few fields that are not read.
Specifically, I do:
File = 'filename.dcm'
ds=dicom.read_file(File)

I am interested in the fields:
Rescale Slope
and
Number of Temporal Positions
This field shows up in the DICOM file as:

(0020,0105) IS #4 [150] Number of Temporal Positions

and is in the file for every slice, so it is there 4551 times because the dimensions are: [112 112 41 111] so the correct answer should be 111.

Is there anything I can do to read these two values?

Thank you,
Jason

Darcy Mason

unread,
Sep 11, 2011, 10:29:09 PM9/11/11
to pydicom
On Sep 9, 2:10 pm, Jason Steffener <steffe...@gmail.com> wrote:
> Dear all,
> I am working with enhanced 4-D dicom files from a 3T Philps Achieva MRI. I
> am using pydicom to read them in but there are a few fields that are not
> read.
> Specifically, I do:
> File = 'filename.dcm'
> ds=dicom.read_file(File)
>
> I am interested in the fields:
> Rescale Slope
> and
> Number of Temporal Positions
>...

Can you supply an example file with no confidential info? I'm not
familiar with the 4D dicom format, but will take a look and try to see
what is going on.

-Darcy

Jason Steffener

unread,
Sep 12, 2011, 8:48:55 AM9/12/11
to pyd...@googlegroups.com
I have solved my problem in a very slow way, but it works! Any better ways would be appreciated!
Jason.

I have done the following:
DicomObject = dicom.read_file(FileName)


def DicomRescaleSlope(DicomObject):
    for line in str(DicomObject).splitlines():
       if "rescale slope" in line.lower():
        temp=line
        RS=float(temp.split("'")[-2])
        return RS
        break
def DicomNumberTemporalPositions(DicomObject):   
    for line in str(DicomObject).splitlines():
        if "number of temporal positions" in line.lower():
            temp=line
            Ntime=int(temp.split("'")[-2])
            return Ntime
            break   

Darcy Mason

unread,
Sep 12, 2011, 9:04:09 AM9/12/11
to pydicom
On Sep 12, 8:48 am, Jason Steffener <steffe...@gmail.com> wrote:
> I have solved my problem in a very slow way, but it works! Any better ways
> would be appreciated!
> Jason.
>
> I have done the following:
> DicomObject = dicom.read_file(FileName)
>
> def DicomRescaleSlope(DicomObject):
>     for line in str(DicomObject).splitlines():
> ...

Okay, so this means that the objects are in there somewhere; it should
be a matter of finding the right path to them through nested objects.
Here's a suggestion:

If you read the file, then look at the top level:
>>> print DicomObject.top()

then you should be able to guess which Sequence the items are in. Then
follow one of those sequence items,
>>> sq0=DicomObject.Objects[0]
Replace 'Object' with name of sequence -- note the "s" on the end,
that's the way pydicom names sequence objects for now (will change
with move to standardized keywords now proposed by DICOM standard).
then
>>> print sq0.top()
and repeat.

Then you should be able to find the path down to your items of
interest.

Hope that helps,
Darcy

Jason Steffener

unread,
Sep 12, 2011, 9:32:50 AM9/12/11
to pyd...@googlegroups.com
Darcy,
Yes, that worked.
I did:
sq0=DicomObject.PerFrameFunctionalGroups[0]
Then I type:
sq0
and I see the fields I am looking for!
But how do I extract them?
I am interested in item:
(0028,1053)
Thank you,
Jason

Darcy Mason

unread,
Sep 12, 2011, 8:10:22 PM9/12/11
to pydicom
On Sep 12, 9:32 am, Jason Steffener <steffe...@gmail.com> wrote:
> I did:
> sq0=DicomObject.PerFrameFunctionalGroups[0]
> Then I type:
> sq0
> and I see the fields I am looking for!
> But how do I extract them?
> I am interested in item:
> (0028,1053)

If there is a name beside the item when you print it, then use
sq0.TheName, where 'TheName' is the name shown with no spaces and no
punctuation of any kind (and exact upper and lower case). That will
give you the value of the item as a python number, string, whatever it
should be (looks like numbers for the items you mentioned at the
beginning).

If there is no name, then use
sq0[0x00281053].value
to get the same as above.

-Darcy



Edoardo Pasca

unread,
Sep 13, 2011, 3:16:37 AM9/13/11
to pyd...@googlegroups.com
Hi Jason,

Just as I finished to write I realized that you use enhanced files and
I am not sure ours are such. Anyway my message is:

I use ReadFile instead of read_file or the other constructs.

In particular in our institute we have a 3T Philips Achieva and we
produce 5D series (4D magnitude/phase images). To be able to create
the two 4D images (we use our proprietary software to analyze images)
I get the important informations about the image from the first DICOM
header:

import dicom as pyDicom
# determine a few things about the 5D image
ds = pyDicom.ReadFile(File, force=True)
SizeX = int(ds.Rows)
SizeY = int(ds.Columns)

SizeT = ds[0x020,0x105].value

# because it is 5D it contains 2 4D images
SizeZ = len(files)/SizeT / 2
spacingX, spacingY = ds[0x28,0x30].value
sliceThickness = ds[0x18,0x88].value
spacingZ = ds[0x18,0x88].value

About the Rescale Slope in our scanner (I understand it depends on
some software settings) it is in (2005,140a)
RS = float(ds[0x2005140a].value)
If it is a 4D series it should be the same in every frame (BTW for our
B1 mapping sequence it isn't).

For my needs I then cycle on all the files putting each slice in the
proper location in the 4D image.

Edo

PS

> --
> You received this message because you are subscribed to the Google Groups
> "pydicom" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pydicom/-/tBNk5MNwAEYJ.
> To post to this group, send email to pyd...@googlegroups.com.
> To unsubscribe from this group, send email to
> pydicom+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pydicom?hl=en.
>

--
Edo
weblog  http://edo.imanetti.net/wordpress
podcast http://sieegiueeaccaso.blogspot.com
cooking http://edo.imanetti.net/cucina
:wq

Reply all
Reply to author
Forward
0 new messages