Reputation: 5841
I am trying to follow the tutorial here:
http://www.rexcardan.com/2014/10/evil-dicom-basics/
and process my DICOM file to show the image. In the tutorial, the DICOMObject.Open() method is called to process the file path. My issue is that intellisense does not pick this up for me. Would anyone be able to assist with this?
I downloaded this version:
https://github.com/rexcardan/Evil-DICOM
EDIT
Using the following:
var dcm = DICOMObject.Read(@"C:\file\path\filename.dcm");
While stepping through the code of DICOMObject
everything seems to be working fine up to this point:
public static IDICOMElement ReadElementImplicitLittleEndian(DICOMBinaryReader dr)
{
var tag = TagReader.ReadLittleEndian(dr);
var vr = TagDictionary.GetVRFromTag(tag);
int length = LengthReader.ReadLittleEndian(VR.Null, dr);
var data = DataReader.ReadLittleEndian(length, dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);
var el = ElementFactory.GenerateElement(tag, vr, data, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);
return el;
}
When the code gets to:
int length = LengthReader.ReadLittleEndian(VR.Null, dr);
length
returns an int
of 1919252000 bytes
which is ~2GB. Then the code steps to:
var data = DataReader.ReadLittleEndian(length, dr, TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN);
Which checks to see if there are any bytes to read (which there is) and goes to the read bytes here:
public byte[] ReadBytes(int count)
{
byte[] buffer = new byte[count];
_binaryReader.Read(buffer, 0, count);
return buffer;
}
byte[] buffer = new byte[count];
is where the actual exception occurs in the code. I have tested the amount of bytes that it can handle and it seems to be around .6 - .7 GB
which is not even half of what I need. Is there away to expand the buffer to accept all of what I need?
Upvotes: 0
Views: 936
Reputation: 295
Try this
var bdcm= File.ReadAllBytes(@"AbsolutePath");
var dcm = DICOMObject.Read(bdcm);
Upvotes: 0
Reputation: 438
Sorry for the late response.
My first thought is that the file is not actually encoded in Implicit VR Little Endian. This is the default transfer syntax that is presumed if the DICOM preamble and metadata are missing. Normally, in the metadata (Tags starting with 0002), the transfer syntax is revealed. On the actual file (in Windows explorer, not from ED), is the size really 600+MB? If so, what kind of file is that so I can play with one?
I added a new method to the DICOMObject class that let's you try another syntax on a read fail:
/// <summary>
/// Reads a DICOM file from a path
/// </summary>
/// <param name="filePath">the path to the file</param>
/// <param name="trySyntax">the transfer syntax to use in case there is no metadata explicitly included</param>
/// <returns></returns>
public static DICOMObject Read(string filePath,
TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
{
return DICOMFileReader.Read(filePath, trySyntax);
}
I've run across some badly formatted DICOM in my experiences that have caused me errors like the one you are mentioning. Of course, it could really be that you are running out of memory, which I would like to dive into further if you are sure the transfer syntax is correct. Try "Explicit VR Little Endian" and see if that fixes your problem.
Upvotes: 0
Reputation: 15981
I have not looked at the video, but as far as I know you should use:
var dicomObj = DICOMObject.Read(filePath);
to read a DICOM file using Evil DICOM.
Please see the source code here. I am not sure, but there may have been a recent API change that explains this confusion.
Upvotes: 1