suyashdb / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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 )

Original issue reported on code.google.com by brandon....@gmail.com on 24 Apr 2009 at 2:30

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by darcymason@gmail.com on 25 Apr 2009 at 3:12

GoogleCodeExporter commented 8 years ago

Original comment by darcymason@gmail.com on 25 Apr 2009 at 4:21

GoogleCodeExporter commented 8 years ago
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. 

Original comment by angela...@gmail.com on 18 Jul 2012 at 6:31