differences in filling pixel data tag between v1.36 to v3

27 views
Skip to first unread message

Yonatan sy

unread,
Sep 10, 2017, 4:04:32 AM9/10/17
to Fellow Oak DICOM

Hi,
 A short while ago we transferred our code from V1.36 to V3.
On V1.36 we used to fill pixel data using this:

Add(DicomTag.PixelData, pixels);

where pixels is ushort[].

Add(DicomTag.PixelData, pixels);
currently this couses to the following exception:
System.InvalidOperationException: Unable to create DICOM element of type OB with values of type System.Int32.

As it seems DoAdd has a problem identifying it:
            DicomVR vr = null;
           
if (values != null) vr = entry.ValueRepresentations.FirstOrDefault(x => x.ValueType == typeof(T));
           
if (vr == null) vr = entry.ValueRepresentations.First();
VR list contains both OB and OW, when checking typeof(T) UInt16 while OW value type is UInt16[] so the first line ends with vr=null then the second line puts in the default which is OB.
when tryin to do some thing of the form: 
Add(DicomTag.PixelData, new []{pixels});
The VR is identified as UInt16[], but later in the last DoAdd we have this piece of code:
            if (vr == DicomVR.OW)
           
{
               
if (values == null) return DoAdd(new DicomOtherWord(tag, EmptyBuffer.Value), allowUpdate);
               
if (typeof(T) == typeof(ushort)) return DoAdd(new DicomOtherWord(tag, values.Cast<ushort>().ToArray()), allowUpdate);

               
if (typeof(T) == typeof(IByteBuffer) && values.Count == 1)
               
{
                   
return DoAdd(new DicomOtherWord(tag, (IByteBuffer)values[0]), allowUpdate);
               
}
           
}

and then this typeof(T) == typeof(ushort)evaluates as false as T is recognized as UInt16[]

Can anyone help me with this issue?

Anders Gustafsson Cureos AB

unread,
Sep 10, 2017, 4:33:09 PM9/10/17
to Fellow Oak DICOM
Try Add<ushort>(DicomTag.PixelData, pixels) and see if that works.

Regards
Anders @ Cureos

Reply all
Reply to author
Forward
0 new messages