compare the dicom files of a serie

636 views
Skip to first unread message

stomy

unread,
Feb 27, 2009, 5:43:48 PM2/27/09
to pydicom
Hi,

I have to compare the dicom files of a serie(a serie can contain a
lost of dicom files) ...For that i want to collect their similarities
and differences...I already can do this comparison between two dicom
files of a serie:

def compareDS(ds1,ds2):

"""Compare two dicom datasets."""
trueValues = []
falseValues = []
keys=ds1.keys()
keys.sort()

for key in keys:
if ds1[key].value==ds2[key].value:
s = '%s : %s --- %s' % (key, ds1[key].description(),ds1
[key].value
trueValues.append(s)

else:
s= '%s : %s --- %s : %s' % (key, ds1[key].description(),
ds1[key].value,':',ds2[key].value)
falseValues.append(s)

return trueValues, falseValues

dataset1=dicom.ReadFile(file1)
dataset2=dicom.ReadFile(file2)
TRUE,FALSE=compareDS(dataset1,dataset2)

for item in TRUE:
print item

for item in FALSE:
print item


Can someone help me?

Thanks in advance!!!

Darcy Mason

unread,
Feb 28, 2009, 9:43:01 AM2/28/09
to pydicom
pydicom's Datasets are just derived classes of python's dict, so this
discussion on Stack Overflow:
http://stackoverflow.com/questions/314583/comparing-multiple-dictionaries-in-python
should point you in the right direction. At a quick glance, it looks
to me like Claudiu's answer may be the best one.

The answer talks about the intersection (common elements of all
dicts), but python sets (http://docs.python.org/library/sets.html) can
do differences etc too so you should be able to compare each dataset
against the common intersection to find your differences as well.

And you should be able to wrap the result into a pydicom Dataset again
to be able to access the tags as usual.
dsIntersect = Dataset(result)
(untested -- but it looks like result comes back as a list of
key,value pairs so it should work)

Hope that helps,
Darcy

stomy

unread,
Mar 3, 2009, 12:15:15 PM3/3/09
to pydicom
Hi Darcy,

thanks for your suggestion...I used the Parand's method and i'm
satisfied!!!!

Stomy

Sandeep Kumar Aaryash

unread,
May 5, 2017, 11:52:43 AM5/5/17
to pydicom
hi 
   i want to compare a dictionary{Key: values] and a dicom file (tag,value) in python.
please help me out.

thanks
sandeep

Darcy Mason

unread,
May 9, 2017, 3:46:28 PM5/9/17
to pydicom
Can you explain in more detail what you are trying to compare? What kind of key is in the dictionary -- dicom keywords? Tags? What kind of values?

Sandeep Kumar Aaryash

unread,
May 10, 2017, 1:45:06 AM5/10/17
to pydicom
hi Darcy,
            now i am able to compare.
Regards,
sandeep

Su

unread,
Apr 20, 2018, 8:21:37 AM4/20/18
to pydicom
Hi,
    I want to compare the pixel contents of the dicom files to know how different are these dicom files from each other, and in which region (area/ part) are they different? I am not interested in the Tag comparison. Basically the pixel data tag displays that the two dicom files are not similar. But i want to know the difference in the pixels count / pixel placement in the image.

Thanks

Steve Gregory

unread,
Apr 21, 2018, 8:16:23 AM4/21/18
to pydicom
The pixel_array of each file can be subtracted from each other because they are numpy arrays. Hope this helps. Steve G

Sunaina Raghavendra Rao

unread,
Apr 23, 2018, 12:33:24 AM4/23/18
to pyd...@googlegroups.com
Yeah!! (A-B) and (B-A). Thanks much!!!

On Sat, Apr 21, 2018 at 5:46 PM, Steve Gregory <stephen....@gmail.com> wrote:
The pixel_array of each file can be subtracted from each other because they are numpy arrays. Hope this helps. Steve G

--
You received this message because you are subscribed to the Google Groups "pydicom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydicom+unsubscribe@googlegroups.com.
To post to this group, send email to pyd...@googlegroups.com.
Visit this group at https://groups.google.com/group/pydicom.
For more options, visit https://groups.google.com/d/optout.



--
Sunaina
Reply all
Reply to author
Forward
0 new messages