For some tests I'm trying to manipulate the PixelData
element of a CT image stored in dicom format and write it back in the file with Fellow Oak Dicom in C#. After some research I found out that the matrix I want to deal with is in the Buffer
of PixelData
stored in a byte
-array. So I wrote following code:
DicomFile ctFile = DicomFile.Open(image);
var pixDat = ctFile.Dataset.Get<byte[]>(DicomTag.PixelData);
for (int i = 0; i < pixData.Length; i++)
{
pixDat[i] = Convert.ToByte(200);
}
ctFile.Dataset.AddOrUpdate<byte[]>(DicomTag.PixelData, pixDat);
ctFile.Save("new file folder");
This was my first try and I got an Exception
at the AddOrUpdate
command because it was unable to convert a byte
-array to OB.
Reading e.g. Pianykh's book about DICOM, OB means Other Byte String. But up to now I'm unable to convert the manipulated byte
-array to OB. When I tried this code snippet:
DicomOtherByte dob = new DicomOtherByte(DicomTag.PixelData, pixDat);
ctFile.Dataset.AddOrUpdate<DicomOtherByte>(DicomTag.PixelData, dob);
the Exception
still is calling at AddOrUpdate
for being unable to convert the item to OB. Searching here at stackoverflow, fo-dicom documentation in git or with google I still didn't get a clue how to deal with it. So I'm wondering how to convert my manipulated matrix to OB, because I thought DicomOtherByte
is OB.
EDIT: The Exception
is "Unable to create DICOM element of type OB with values of type Dicom.DicomOtherByte" - System.InvalidOperationException
Thanks in advance.
foreach
loop to afor
loop. You were right. Looked a bit strange. – Booma