suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

Failure to write VR='US or SS or OW' properly #41

Open suever opened 9 years ago

suever commented 9 years ago

From brandon....@gmail.com on April 24, 2009 10:30:43

I ran into this problem while working with some new imagery.

With the attached imagery: dcm = dicom.ReadFile( 'img3.dcm' ) dicom.WriteFile( 'img3out.dcm', dcm )

You receive "NotImplementedError: WriteDataElement: unknown Value Representation 'US or SS or OW'".

This error raises when trying to write the tag (0028, 3006) LUTData. Clearly the writing for this VR is not implemented, but easy to fix since US, SS and OW are all some binary 16 bit values (ss and us have VM of 2, where OW can be a large buffer of values).

Note: The following solution works for my needs under limited testing.

First, since US and SS both use write_OWvalue in filewriter.py, add 'US or SS or OW':write_OWvalue to the writers dictionary.

Now pydicom will most likely raise an error in the write_OWvalue method because it sees a list instead of a buffer of shorts. This is because the DataElement constructor does not correctly capture the data for VR 'US or SS or OW'.. It treats the buffer as a free text type VR and splits on the text delimiter giving you a list of strings if the delimiter exists within your data.. To treat the data as binary, do the following:

in the DataElement Constructor: under _setvalue(self,val) if isString(val) and self.VR not in \ ['UT','ST','LT', 'FL','FD','AT','OB','OW','OF','SL','SQ','SS', 'UL','US', 'OW/OB', 'UN', ## ADD THIS ->## 'US or SS or OW']:

Now this should work: dcm = dicom.ReadFile( 'img3.dcm' ) dicom.WriteFile( 'img3out.dcm', dcm )

Attachment: img3.zip

Original issue: http://code.google.com/p/pydicom/issues/detail?id=41

suever commented 9 years ago

From darcymason@gmail.com on April 25, 2009 08:12:24

Thanks Brandon.

In a very unusual coincidence, I also discovered the 'US or ...' constructor backslash problem two days ago, and committed ( r104 ) a similar change to that suggested above. On the writing part, your suggestion looks good -- I'll implement something for that and add it.

Status: Started
Labels: Milestone-Release1.0

suever commented 9 years ago

From darcymason@gmail.com on April 25, 2009 09:21:04

Owner: darcymason

suever commented 9 years ago

From angela...@gmail.com on July 17, 2012 23:31:57

I had a similar problem, where the VR is 'US or OW'. I therefore made changes as suggested in dataelem.py, values.py, filewriter.py in version 0.9.7 of the code.