Modifying DicomDataset

921 views
Skip to first unread message

Hesham Nabih

unread,
Oct 26, 2012, 10:36:42 PM10/26/12
to fo-d...@googlegroups.com
I tried to change Window Center  in Dataset ( It is a tag with VR=DS  and value type of ushort ).
But when we are using the following statement to change this property, the program throws an exception

 DicomImage _image = new DicomImage("C:\\IM1");
 
DicomDataset dset = _image.Dataset;
 dset
.Add<ushort>(DicomTag.WindowCenter, (ushort)40);

we also tried it with type <decimal> and <int> and still problem is the same.

That is the error message:
Unable to create DICOM element of type DS with values of type System.Int32

We had to hard-coded this way to make it work (in DicomDataset class):

 
 if (vr == DicomVR.DS)
           
{
               
if (values == null)
                   
return Add(new DicomDecimalString(tag, EmptyBuffer.Value));
               
if (typeof(T) == typeof(decimal))
                   
return Add(new DicomDecimalString(tag, values.Cast<decimal>().ToArray()));
               
if (typeof(T) == typeof(string))
                   
return Add(new DicomDecimalString(tag, values.Cast<string>().ToArray()));
               
if (typeof(T) == typeof(int))
               
{
                   
return Add(new DicomDecimalString(tag, new decimal[] { 40 }));
               
}
           
}


Is there any better way to change DicomTag values inside a DicomDataset?

Hesham Nabih

unread,
Oct 27, 2012, 1:54:43 AM10/27/12
to fo-d...@googlegroups.com
With the help see this post at stackoverflow http://chat.stackoverflow.com/rooms/18650/discussion-between-user373721-and-ark-kun
I used the following:
 
 DicomDataset dataset = DicomFile.Open(_filename).Dataset;
            dataset
.Add(DicomTag.WindowWidth, "100.0");
 dataset
.Add(new DicomCodeString(DicomTag.PhotometricInterpretation, "MONOCHROME1"));
           
DicomImage image = new DicomImage(dataset);
           
Image result = image.RenderImage(_slicenumber);
           
DisplayImage(result);

Now I am trying to figure out how to apply the changes to multiframe images and adjusting window level using trackbar.  Any ideas will be much appreciated

Mahesh Dubey

unread,
Oct 27, 2012, 2:29:18 AM10/27/12
to fo-d...@googlegroups.com


dset.Add(DicomTag.WindowCenter,40M);

Regards
Mahesh



--
You received this message because you are subscribed to the Google Groups "Fellow Oak DICOM for .NET" group.
To post to this group, send email to fo-d...@googlegroups.com.
To unsubscribe from this group, send email to fo-dicom+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/fo-dicom/-/UDZ2q2XRwOgJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks And Regards
Mahesh Dubey

Colby Dillion

unread,
Oct 27, 2012, 12:11:50 PM10/27/12
to fo-d...@googlegroups.com
I've taken the time to modify the DicomImage class so that you can set the window/level and it will apply to the rendered image. This setting will apply to all frames in a multiframe image.

var img = new DicomImage(fileName);
img
.WindowCenter = 2048.0;
img
.WindowWidth = 4096.0;
DisplayImage(img.RenderImage(frameNumber));


Hesham Nabih

unread,
Oct 27, 2012, 2:08:47 PM10/27/12
to fo-d...@googlegroups.com
Thank you so much Colby.
Reply all
Reply to author
Forward
0 new messages